GitPython: Error in `repo.active_branch` if branch is in DETACHED HEAD state
Error in repo.active_branch if branch is in DETACHED HEAD state:
{TypeError}HEAD is a detached symbolic reference as it points to '0fa1f2a7d9dd9fb63fa775d2d97ad72f56f1d819'
The branch is None in def _get_ref_info(cls, repo, ref_path): because of
# its a commit
if repo.re_hexsha_only.match(tokens[0]):
return (tokens[0], None)
def active_branch(self) could return HEAD-{commit-hash} instead like:
try:
active_branch = repo.active_branch
except:
active_branch = 'DETACHED_' + repo.head.object.hexsha
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 24
- Comments: 16 (8 by maintainers)
Commits related to this issue
- Use hexsha instead of active_branch to work around detached head When concourse checks out a repo it leaves it in a detached head state. This was causing errors as python git has slightly undefined b... — committed to alphagov/gds-pre-commit by akinnane 7 years ago
- Use hexsha instead of active_branch to work around detached head When concourse checks out a repo it leaves it in a detached head state. This was causing errors as python git has slightly undefined b... — committed to alphagov/gds-pre-commit by akinnane 7 years ago
- [seq2seq] It looks like gitpython is broken when one tries to use it from `git checkout hash`, see: https://github.com/gitpython-developers/GitPython/issues/633 While debugging/bisecting we need t... — committed to stas00/transformers by stas00 6 years ago
- fix: handle detached head Workaround for https://github.com/gitpython-developers/GitPython/issues/633 — committed to alyf-de/frappe by barredterra 5 years ago
- fix: handle detached head Workaround for https://github.com/gitpython-developers/GitPython/issues/633 (cherry picked from commit 04094110f5ddb5b2d4c514be43328d9f0e893654) # Conflicts: # frappe/comm... — committed to frappe/frappe by barredterra 5 years ago
3.5 years later and this is still a problem 😦
3 years later and this is still a problem 😦
This comment might help.
I read the last comment, but it was 4 years ago, any new update on this?
Thank you for this follow up, @Byron
My suggestion for the best solution would be this: In order to keep backward compatibility (exception that is) adding a new argument that allows for what OP suggested:
and then:
I haven’t looked at the code, so this is totally a pseudocode based on what I saw in this issue.
Of course, if that suggestion resonates, you’d know better what to call it,
active_branch_flexibleis just a quick idea 😉Thank you.