Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Default branch can't always be determined #3

Closed
jhauberg opened this issue Feb 27, 2019 · 3 comments
Closed

Default branch can't always be determined #3

jhauberg opened this issue Feb 27, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@jhauberg
Copy link
Owner

jhauberg commented Feb 27, 2019

The function default_branch rely on the existence of a HEAD ref in refs/remotes/origin to determine default branch name. However, this ref does not always, nor does it have to, exist (see this answer).

gitdoctor/doctor/repo.py

Lines 44 to 51 in ecb0e4c

def default_branch() -> str:
""" Return the symbolic reference to the default branch. """
result = subprocess.run([
'git', 'symbolic-ref', '--short', 'refs/remotes/origin/HEAD'],
check=True, # print stacktrace on non-zero exit status
stdout=subprocess.PIPE, # capture stdout
stderr=subprocess.DEVNULL) # ignore stderr

In a repository where the refs/remotes/origin/HEAD does not exist, this error will trigger:

$ git symbolic-ref --short refs/remotes/origin/HEAD
fatal: ref refs/remotes/origin/HEAD is not a symbolic ref
@jhauberg jhauberg added the bug Something isn't working label Feb 27, 2019
@jhauberg
Copy link
Owner Author

So the real problem here, is that there is no such thing as a "default branch". It is a thing on GitHub, sure, but in a plain git context, there is no default branch. There is master to begin with, but that could just be deleted or named differently.

@jhauberg
Copy link
Owner Author

This might be a way to go:

$ git remote
origin
$ git remote show origin
* remote origin
  Fetch URL: https://github.com/jhauberg/gitdoctor.git
  Push  URL: https://github.com/jhauberg/gitdoctor.git
  HEAD branch: master
  Remote branches:
    develop tracked
    master  tracked
  Local branches configured for 'git pull':
    develop merges with remote develop
    master  merges with remote master
  Local refs configured for 'git push':
    develop pushes to develop (up to date)
    master  pushes to master  (up to date)

In particular, the HEAD branch: master part.

jhauberg added a commit that referenced this issue Feb 27, 2019
@jhauberg
Copy link
Owner Author

Seems to work. Closing for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant