Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upError in `repo.active_branch` if branch is in DETACHED HEAD state #633
Comments
|
Looks similar to #629 |
|
I am not sure it would be right to return a commit instead. The function is called |
|
Hm good point, I don´t have a pefect answer.. To return no branch seems to be ok. |
|
I think returning no branch would break existing code which expects an exception. On the other hand, the exception is not documented, so in a way it's running under the radar anyway. Maybe it could be adjusted to return None if there is no active branch instead, which would make the calling code a little less cumbersome and safer, as it could start to expect that. Would you like to contribute a respective PR? |
|
I stumbled on this too. With submodules. |
When concourse checks out a repo it leaves it in a detached head
state. This was causing errors as python git has slightly undefined
behaviour in this case.
```
File "detect_checker.py", line 125, in _load_repo
self.parent_branch = self.repo.active_branch
File "/home/a/venv/local/lib/python3.7/site-packages/git/repo/base.py", line 703, in active_branch
return self.head.reference
File "/home/a/venv/local/lib/python3.7/site-packages/git/refs/symbolic.py", line 272, in _get_reference
raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
TypeError: HEAD is a detached symbolic reference as it points to '6e589de2864ee310a46a343ae9d656405e6b8c84'
```
gitpython-developers/GitPython#633
This PR changes it use the hexsha instead which works correctly with
detached heads and normal branches.
Co-authored-by: detnon <sam.detnon@digital.cabinet-office.gov.uk>
Co-authored-by: Alex Kinnane <17098249+akinnane@users.noreply.github.com>
When concourse checks out a repo it leaves it in a detached head
state. This was causing errors as python git has slightly undefined
behaviour in this case.
```
File "detect_checker.py", line 125, in _load_repo
self.parent_branch = self.repo.active_branch
File "/home/a/venv/local/lib/python3.7/site-packages/git/repo/base.py", line 703, in active_branch
return self.head.reference
File "/home/a/venv/local/lib/python3.7/site-packages/git/refs/symbolic.py", line 272, in _get_reference
raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
TypeError: HEAD is a detached symbolic reference as it points to '6e589de2864ee310a46a343ae9d656405e6b8c84'
```
gitpython-developers/GitPython#633
This PR changes it use the hexsha instead which works correctly with
detached heads and normal branches.
Co-authored-by: detnon <sam.detnon@digital.cabinet-office.gov.uk>
Co-authored-by: Alex Kinnane <17098249+akinnane@users.noreply.github.com>
Error in
repo.active_branchif branch is inDETACHED HEADstate:The branch is
Noneindef _get_ref_info(cls, repo, ref_path):because ofdef active_branch(self)could returnHEAD-{commit-hash}instead like: