Title: [294513] trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py
Revision
294513
Author
[email protected]
Date
2022-05-19 16:46:27 -0700 (Thu, 19 May 2022)

Log Message

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

Modified Paths

Diff

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (294512 => 294513)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2022-05-19 23:42:23 UTC (rev 294512)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2022-05-19 23:46:27 UTC (rev 294513)
@@ -421,16 +421,21 @@
     @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):
         if self._branch:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to