Skip to content

Commit

Permalink
repo_resolver.py: repo_details() to use first remote if origin does…
Browse files Browse the repository at this point in the history
… not exist (#490)

In some scenarios, the origin branch does not exist; due to this hardcoding the URL to be the origin URL can fail. In this scenario, we default to the first existing remote's URL.
  • Loading branch information
Javagedes authored Apr 14, 2023
1 parent cb6bcb5 commit 87f0c44
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion edk2toolext/environment/repo_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,18 @@ def repo_details(abs_file_system_path):
details["Bare"] = repo.bare
details["Dirty"] = repo.is_dirty(untracked_files=True)
details["Initialized"] = True
details["Url"] = repo.remotes.origin.url

# 1. Use the remote associated with the branch if on a branch and it exists
if not repo.head.is_detached and repo.branches[repo.head.ref.name].tracking_branch():
remote_name = repo.branches[repo.head.ref.name].tracking_branch().remote_name
details["Url"] = repo.remotes[remote_name].url
# 2. Use the origin url if it exists
elif "origin" in repo.remotes:
details["Url"] = repo.remotes.origin.url
# 3. Use whatever the first remote is
elif len(repo.remotes) > 0:
details["Url"] = repo.remotes[0].url

except (InvalidGitRepositoryError, NoSuchPathError):
pass
return details
Expand Down

0 comments on commit 87f0c44

Please sign in to comment.