Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions tagbot/action/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,17 @@ def _commit_sha_of_tree_from_branch(
) -> Optional[str]:
"""Look up the commit SHA of a tree with the given SHA on one branch."""
for commit in self._repo.get_commits(sha=branch, since=since):
if commit.commit.tree.sha == tree:
return cast(str, commit.sha)
if self.__subdir:
arg = f"{commit.sha}:{self.__subdir}"
try:
subdir_tree_hash = self._git.command("rev-parse", arg)
if subdir_tree_hash == tree:
return cast(str, commit.sha)
except Exception:
continue
else:
if commit.commit.tree.sha == tree:
return cast(str, commit.sha)
return None

def _commit_sha_of_tree(self, tree: str) -> Optional[str]:
Expand All @@ -351,7 +360,20 @@ def _commit_sha_of_tree(self, tree: str) -> Optional[str]:
# For a valid tree SHA, the only time that we reach here is when a release
# has been made long after the commit was made, which is reasonably rare.
# Fall back to cloning the repo in that case.
return self._git.commit_sha_of_tree(tree)
if self.__subdir:
# For subdirectories, we need to check the subdirectory tree hash
for line in self._git.command("log", "--all", "--format=%H").splitlines():
arg = f"{line}:{self.__subdir}"
try:
subdir_tree_hash = self._git.command("rev-parse", arg)
if subdir_tree_hash == tree:
return line
except Exception:
# If rev-parse fails, skip this commit
continue
return None
else:
return self._git.commit_sha_of_tree(tree)

def _commit_sha_of_tag(self, version_tag: str) -> Optional[str]:
"""Look up the commit SHA of a given tag."""
Expand Down