Skip to content

Commit

Permalink
get_last_merged_commit func
Browse files Browse the repository at this point in the history
  • Loading branch information
Luís Freitas authored and Luís Freitas committed Jun 30, 2024
1 parent 94b1d1f commit c2f4b60
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions merge_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ def fetch_latest_commit(repo):
repo.remotes.origin.fetch()
return repo.head.commit.hexsha

def get_last_merged_commit(repo, tag_name):
try:
return repo.git.describe(tag_name, tags=True)
except git.exc.GitCommandError:
return None

def main():
# Replace with your actual GitHub username. Can be set as env variable
repo_url = "[email protected]:lsfreitas/target.git"
repo_path = "/tmp/target_repo"
target_repo_url = "[email protected]:lsfreitas/target.git"
target_repo_path = "/tmp/target_repo"
tag_name = "last-merged-commit"

repo = clone_repo(repo_url, repo_path)
print(f"Repository cloned to {repo_path}")
target_repo = clone_repo(target_repo_url, target_repo_path)
print(f"Repository cloned to {target_repo_path}")

latest_commit = fetch_latest_commit(repo)
latest_commit = fetch_latest_commit(target_repo)
print(f"Latest commit hash: {latest_commit}")

last_merged_commit = get_last_merged_commit(target_repo, tag_name)
if last_merged_commit:
print(f"Last merged commit hash: {last_merged_commit}")
else:
print(f"No tag '{tag_name}' found in the repository")

if __name__ == "__main__":
main()

0 comments on commit c2f4b60

Please sign in to comment.