3636from streamlit .logger import get_logger
3737from streamlit .proto .ForwardMsg_pb2 import ForwardMsg
3838from streamlit .proto .ClientState_pb2 import ClientState
39+ from streamlit .proto .GitInfo_pb2 import GitInfo
3940from streamlit .server .server_util import serialize_forward_msg
4041from streamlit .storage .file_storage import FileStorage
4142from streamlit .watcher .local_sources_watcher import LocalSourcesWatcher
@@ -59,6 +60,7 @@ class ReportSession(object):
5960 and widget state.
6061
6162 A ReportSession is attached to each thread involved in running its Report.
63+
6264 """
6365
6466 def __init__ (self , ioloop , script_path , command_line , uploaded_file_manager ):
@@ -345,34 +347,14 @@ def _enqueue_file_change_message(self):
345347 msg .session_event .report_changed_on_disk = True
346348 self .enqueue (msg )
347349
348- def get_deploy_params (self ):
349- try :
350- from streamlit .git_util import GitRepo
351-
352- self ._repo = GitRepo (self ._report .script_path )
353- return self ._repo .get_repo_info ()
354- except :
355- # Issues can arise based on the git structure
356- # (e.g. if branch is in DETACHED HEAD state,
357- # git is not installed, etc)
358- # In this case, catch any errors
359- return None
360-
361350 def _enqueue_new_report_message (self ):
362351 self ._report .generate_new_id ()
352+
363353 msg = ForwardMsg ()
364354 msg .new_report .report_id = self ._report .report_id
365355 msg .new_report .name = self ._report .name
366356 msg .new_report .script_path = self ._report .script_path
367357
368- # git deploy params
369- deploy_params = self .get_deploy_params ()
370- if deploy_params is not None :
371- repo , branch , module = deploy_params
372- msg .new_report .deploy_params .repository = repo
373- msg .new_report .deploy_params .branch = branch
374- msg .new_report .deploy_params .module = module
375-
376358 # Immutable session data. We send this every time a new report is
377359 # started, to avoid having to track whether the client has already
378360 # received it. It does not change from run to run; it's up to the
@@ -423,6 +405,34 @@ def _enqueue_report_finished_message(self, status):
423405 msg .report_finished = status
424406 self .enqueue (msg )
425407
408+ def handle_git_information_request (self ):
409+ msg = ForwardMsg ()
410+
411+ try :
412+ from streamlit .git_util import GitRepo
413+
414+ self ._repo = GitRepo (self ._report .script_path )
415+
416+ repo , branch , module = self ._repo .get_repo_info ()
417+
418+ msg .git_info_changed .repository = repo
419+ msg .git_info_changed .branch = branch
420+ msg .git_info_changed .module = module
421+
422+ msg .git_info_changed .untracked_files [:] = self ._repo .untracked_files
423+ msg .git_info_changed .uncommitted_files [:] = self ._repo .uncommitted_files
424+
425+ if self ._repo .is_head_detached :
426+ msg .git_info_changed .state = GitInfo .GitStates .HEAD_DETACHED
427+ elif len (self ._repo .ahead_commits ) > 0 :
428+ msg .git_info_changed .state = GitInfo .GitStates .AHEAD_OF_REMOTE
429+ else :
430+ msg .git_info_changed .state = GitInfo .GitStates .DEFAULT
431+ except :
432+ pass
433+
434+ self .enqueue (msg )
435+
426436 def handle_rerun_script_request (self , client_state = None , is_preheat = False ):
427437 """Tell the ScriptRunner to re-run its report.
428438
@@ -431,6 +441,7 @@ def handle_rerun_script_request(self, client_state=None, is_preheat=False):
431441 client_state : streamlit.proto.ClientState_pb2.ClientState | None
432442 The ClientState protobuf to run the script with, or None
433443 to use previous client state.
444+
434445 is_preheat: boolean
435446 True if this ReportSession should run the script immediately, and
436447 then ignore the next rerun request if it matches the already-ran
0 commit comments