Skip to content
Permalink
Browse files
Handle cases where origin/HEAD doesn't exist in git-webkit
https://bugs.webkit.org/show_bug.cgi?id=240693

Reviewed by Jonathan Bedard.

* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.default_branch):

This makes several changes to default_branch:

 * We attempt origin/HEAD, origin/main, and origin/master before
   trying to guess based on all branches.

 * When guessing based on all branches, prefer main over master.

Additionally, this changes the searching to use `--symbolic-full-ref`,
as we only ever want refs to be returned, and this takes away the
guesswork parsing.

Canonical link: https://commits.webkit.org/250770@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294513 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
gsnedders committed May 19, 2022
1 parent 4c354a6 commit f0527ad4230c903a9a8a53aee3f3cc53bf1b9c33
Showing 1 changed file with 14 additions and 9 deletions.
@@ -421,15 +421,20 @@ def root_path(self):
@property
@decorators.Memoize()
def default_branch(self):
result = run([self.executable(), 'rev-parse', '--abbrev-ref', 'origin/HEAD'], cwd=self.path, capture_output=True, encoding='utf-8')
if result.returncode:
candidates = self.branches
if 'master' in candidates:
return 'master'
if 'main' in candidates:
return 'main'
return None
return '/'.join(result.stdout.rstrip().split('/')[1:])
for name in ['HEAD', 'main', 'master']:
result = run([self.executable(), 'rev-parse', '--symbolic-full-name', 'refs/remotes/origin/{}'.format(name)],
cwd=self.path, capture_output=True, encoding='utf-8')
s = result.stdout.strip()
if result.returncode == 0 and s:
assert s.startswith('refs/remotes/origin/')
return s[len('refs/remotes/origin/'):]

candidates = self.branches
if 'main' in candidates:
return 'main'
if 'master' in candidates:
return 'master'
return None

@property
def branch(self):

0 comments on commit f0527ad

Please sign in to comment.