4141
4242if TYPE_CHECKING :
4343 from git .db import GitCmdObjectDB
44- from git .objects import Commit , TagObject
44+ from git .objects import Commit
4545 from git .refs .reference import Reference
4646 from git .refs .log import RefLog , RefLogEntry
4747 from git .refs .tag import Tag
@@ -256,13 +256,30 @@ def _object_from_hexsha(repo: "Repo", hexsha: str) -> AnyGitObject:
256256
257257
258258def _current_reflog_ref (repo : "Repo" ) -> SymbolicReference :
259- return repo .head
259+ try :
260+ return repo .head .ref
261+ except TypeError :
262+ return repo .head
263+ # END handle detached head
264+
265+
266+ def _common_reflog_path (repo : "Repo" , ref : SymbolicReference ) -> Optional [str ]:
267+ if repo .common_dir == repo .git_dir :
268+ return None
269+ # END handle normal repository
270+ return SymbolicReference ._get_validated_path (osp .join (repo .common_dir , "logs" ), ref .path )
260271
261272
262273def _ref_log (repo : "Repo" , ref : SymbolicReference ) -> "RefLog" :
263274 try :
264275 return ref .log ()
265276 except FileNotFoundError :
277+ common_path = _common_reflog_path (repo , ref )
278+ if common_path and osp .isfile (common_path ):
279+ from git .refs .log import RefLog
280+
281+ return RefLog .from_file (common_path )
282+ # END handle linked-worktree branch logs
266283 try :
267284 if ref .path == repo .head .ref .path :
268285 return repo .head .log ()
@@ -278,6 +295,12 @@ def _ref_log_entry(repo: "Repo", ref: SymbolicReference, index: int) -> "RefLogE
278295 try :
279296 return ref .log_entry (index )
280297 except FileNotFoundError :
298+ common_path = _common_reflog_path (repo , ref )
299+ if common_path and osp .isfile (common_path ):
300+ from git .refs .log import RefLog
301+
302+ return RefLog .entry_at (common_path , index )
303+ # END handle linked-worktree branch logs
281304 try :
282305 if ref .path == repo .head .ref .path :
283306 return repo .head .log_entry (index )
@@ -464,7 +487,11 @@ def _find_commit_by_message(
464487 # END handle starting point
465488
466489 for commit in commits :
467- matches = regex .search (commit .message or "" ) is not None
490+ message = commit .message
491+ if isinstance (message , bytes ):
492+ message = message .decode (commit .encoding , "replace" )
493+ # END handle bytes message
494+ matches = regex .search (message or "" ) is not None
468495 if matches != negated :
469496 return commit
470497 # END found commit
@@ -505,15 +532,15 @@ def _peel(obj: AnyGitObject, output_type: str, repo: "Repo", rev: str) -> AnyGit
505532 if output_type .startswith ("/" ):
506533 return _find_commit_by_message (repo , obj , output_type [1 :], braced = True )
507534 if output_type == "" :
508- return deref_tag (cast ( "TagObject" , obj ) ) if obj .type == "tag" else obj
535+ return deref_tag (obj ) if obj .type == "tag" else obj
509536 if output_type == "object" :
510537 return obj
511538 if output_type == "commit" :
512539 return to_commit (cast (Object , obj ))
513540 if output_type == "tree" :
514541 return to_commit (cast (Object , obj )).tree if obj .type != "tree" else obj
515542 if output_type == "blob" :
516- obj = deref_tag (cast ( "TagObject" , obj ) ) if obj .type == "tag" else obj
543+ obj = deref_tag (obj ) if obj .type == "tag" else obj
517544 if obj .type == output_type :
518545 return obj
519546 # END handle matching type
@@ -615,14 +642,14 @@ def rev_parse(repo: "Repo", rev: str) -> AnyGitObject:
615642 # END handle reflog
616643
617644 if token == ":" :
618- return _tree_lookup (cast ( AnyGitObject , obj ) , rev [start + 1 :])
645+ return _tree_lookup (obj , rev [start + 1 :])
619646 # END handle path
620647
621648 start += 1
622649
623650 if token == "^" and start < lr and rev [start ] == "{" :
624651 end = _find_closing_brace (rev , start )
625- obj = _peel (cast ( AnyGitObject , obj ) , rev [start + 1 : end ], repo , rev )
652+ obj = _peel (obj , rev [start + 1 : end ], repo , rev )
626653 ref = None
627654 start = end + 1
628655 continue
@@ -645,7 +672,6 @@ def rev_parse(repo: "Repo", rev: str) -> AnyGitObject:
645672 # END set default num
646673
647674 try :
648- obj = cast (AnyGitObject , obj )
649675 if token == "~" :
650676 obj = to_commit (obj )
651677 for _ in range (num ):
0 commit comments