From 707015891fc65dcf5b0b2601aa78f1fb33a01f39 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 24 Nov 2022 15:59:51 +0000 Subject: [PATCH] commit_in_branch.py: add support for checking staging branches Or any branch that contains a `/` slash. Cc: mesa-stable Signed-off-by: Eric Engestrom Part-of: --- bin/commit_in_branch.py | 6 +++--- bin/commit_in_branch_test.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/commit_in_branch.py b/bin/commit_in_branch.py index e4e2edb50ab..36ee7a9795e 100755 --- a/bin/commit_in_branch.py +++ b/bin/commit_in_branch.py @@ -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) diff --git a/bin/commit_in_branch_test.py b/bin/commit_in_branch_test.py index 0e4be6ff95f..aeb09a65000 100644 --- a/bin/commit_in_branch_test.py +++ b/bin/commit_in_branch_test.py @@ -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', 'abac4859618e02aea00f705b841a7c5c5007ad1a'),