@@ -127,17 +127,20 @@ def _wrap(func, q):
127127 else :
128128 raise out # type: ignore
129129
130- def git_commit (bot_directory : str ) -> typing .Optional [str ]:
130+ def git_commit (bot_directory : str
131+ ) -> typing .Tuple [typing .Optional [str ], typing .Optional [str ]]:
131132 git_dir = os .path .join (bot_directory , ".git" )
132133 head_filepath = os .path .join (git_dir , "HEAD" )
133134 if os .path .isfile (head_filepath ):
134- ref = None
135135 with open (head_filepath , "r" ) as head_file :
136- ref = head_file .readline ().split (" " , 1 )[1 ].strip ()
137- branch = ref .rsplit ("/" , 1 )[1 ]
138-
139- ref_filepath = os .path .join (git_dir , ref )
140- if os .path .isfile (ref_filepath ):
141- with open (ref_filepath , "r" ) as ref_file :
142- return ref_file .readline ().strip ()[:8 ]
143- return None
136+ ref_line = head_file .readline ().strip ()
137+ if not ref_line .startswith ("ref: " ):
138+ return None , ref_line
139+ else :
140+ ref = ref_line .split (" " , 1 )[1 ]
141+ branch = ref .rsplit ("/" , 1 )[1 ]
142+
143+ ref_filepath = os .path .join (git_dir , ref )
144+ with open (ref_filepath , "r" ) as ref_file :
145+ return branch , ref_file .readline ().strip ()[:8 ]
146+ return None , None
0 commit comments