Skip to content

Commit

Permalink
Merge pull request #270 from DataRecce/bug/drc-366-getting-current-br…
Browse files Browse the repository at this point in the history
…anch-raises-exception

[Bug] Handle getting branch information when HEAD is detached
  • Loading branch information
wcchang1115 authored Apr 10, 2024
2 parents 53e0255 + 3160545 commit 2791d62
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions recce/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
def current_branch():
try:
repo = Repo(search_parent_directories=True)
except Exception:
if not repo.active_branch:
return None
return repo.active_branch.name
except TypeError:
# happened when HEAD is a detached symbolic reference
return None

if not repo.active_branch:
except Exception:
return None

return repo.active_branch.name

0 comments on commit 2791d62

Please sign in to comment.