commit_in_branch.py: add support for checking staging branches
authorEric Engestrom <eric@engestrom.ch>
Thu, 24 Nov 2022 15:59:51 +0000 (15:59 +0000)
committerEric Engestrom <eric@engestrom.ch>
Wed, 30 Nov 2022 21:12:44 +0000 (21:12 +0000)
Or any branch that contains a `/` slash.

Cc: mesa-stable
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19988>
(cherry picked from commit 707015891fc65dcf5b0b2601aa78f1fb33a01f39)

.pick_status.json
bin/commit_in_branch.py
bin/commit_in_branch_test.py

index d2e8d6a..53006df 100644 (file)
@@ -58,7 +58,7 @@
         "description": "commit_in_branch.py: add support for checking staging branches",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
index e4e2edb..36ee7a9 100755 (executable)
@@ -62,7 +62,7 @@ def branch_has_backport_of_commit(upstream: str, branch: str, commit: str) -> st
     or an empty string if is hasn't
     """
     out = subprocess.check_output(['git', 'log', '--format=%H',
-                                   branch + '-branchpoint..' + upstream + '/' + branch,
+                                   upstream + '..' + upstream + '/' + branch,
                                    '--grep', 'cherry picked from commit ' + commit],
                                   stderr=subprocess.DEVNULL)
     return out.decode().strip()
@@ -89,7 +89,7 @@ def validate_branch(branch: str) -> str:
     out = subprocess.check_output(['git', 'remote', '--verbose'],
                                   stderr=subprocess.DEVNULL)
     remotes = out.decode().splitlines()
-    (upstream, _) = branch.split('/')
+    upstream, _ = branch.split('/', 1)
     valid_remote = False
     for line in remotes:
         if line.startswith(upstream + '\t'):
@@ -125,7 +125,7 @@ if __name__ == "__main__":
                         help='colorize output (default: true if stdout is a terminal)')
     args = parser.parse_args()
 
-    (upstream, branch) = args.branch.split('/')
+    upstream, branch = args.branch.split('/', 1)
 
     if branch_has_commit(upstream, branch, args.commit):
         print_(args, True, 'Commit ' + args.commit + ' is in branch ' + branch)
index d6033ec..52be960 100644 (file)
@@ -46,6 +46,7 @@ def test_canonicalize_commit(commit: str, expected: bool) -> None:
     'commit, expected',
     [
         (get_upstream() + '/20.1', True),
+        (get_upstream() + '/staging/20.1', True),
         (get_upstream() + '/main', True),
         ('20.1', False),
         ('main', False),
@@ -73,6 +74,7 @@ def test_validate_branch(commit: str, expected: bool) -> None:
         ('20.1-branchpoint', True),
         ('20.1', False),
         (get_upstream() + '/20.1', True),
+        (get_upstream() + '/staging/20.1', True),
         ('e58a10af640ba58b6001f5c5ad750b782547da76', True),
         ('d043d24654c851f0be57dbbf48274b5373dea42b', True),
         ('dd2bd68fa69124c86cd008b256d06f44fab8e6cd', True),
@@ -91,6 +93,7 @@ def test_is_commit_valid(commit: str, expected: bool) -> None:
         ('20.1', 'main', False),
         ('20.1', 'e58a10af640ba58b6001f5c5ad750b782547da76', True),
         ('20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', True),
+        ('staging/20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', True),
         ('20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', False),
         ('main', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', True),
         ('20.0', 'd043d24654c851f0be57dbbf48274b5373dea42b', False),
@@ -104,6 +107,7 @@ def test_branch_has_commit(branch: str, commit: str, expected: bool) -> None:
     'branch, commit, expected',
     [
         ('20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', 'd043d24654c851f0be57dbbf48274b5373dea42b'),
+        ('staging/20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', 'd043d24654c851f0be57dbbf48274b5373dea42b'),
         ('20.1', '20.1-branchpoint', ''),
         ('20.1', '20.0', ''),
         ('20.1', '20.2', ''),