From 3acb00290dfc2ea895254275e0244c0a9c1250eb Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Mon, 12 Feb 2024 14:43:27 +0000 Subject: [PATCH] ci_run_n_monitor: allow detached heads as well When running on a detached head (eg. checkout of a tag or a specific commit), there is no active branch, so we can't perform this check; just skip it and assume the user knows what they're doing. Part-of: --- bin/ci/ci_run_n_monitor.py | 43 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/bin/ci/ci_run_n_monitor.py b/bin/ci/ci_run_n_monitor.py index 454dc084969..b8ced54139f 100755 --- a/bin/ci/ci_run_n_monitor.py +++ b/bin/ci/ci_run_n_monitor.py @@ -20,7 +20,7 @@ from collections import defaultdict from concurrent.futures import ThreadPoolExecutor from functools import partial from itertools import chain -from subprocess import check_output +from subprocess import check_output, CalledProcessError from typing import TYPE_CHECKING, Iterable, Literal, Optional import gitlab @@ -426,27 +426,32 @@ if __name__ == "__main__": REV = check_output(['git', 'rev-parse', REV]).decode('ascii').strip() if args.rev == 'HEAD': - branch_name = check_output([ - 'git', 'symbolic-ref', '-q', 'HEAD', - ]).decode('ascii').strip() + try: + branch_name = check_output([ + 'git', 'symbolic-ref', '-q', 'HEAD', + ]).decode('ascii').strip() + except CalledProcessError: + branch_name = "" - tracked_remote = check_output([ - 'git', 'for-each-ref', '--format=%(upstream)', - branch_name, - ]).decode('ascii').strip() - - # Ignore local branches that do not track any remote - if tracked_remote: - remote_rev = check_output([ - 'git', 'rev-parse', tracked_remote, + # Ignore detached heads + if branch_name: + tracked_remote = check_output([ + 'git', 'for-each-ref', '--format=%(upstream)', + branch_name, ]).decode('ascii').strip() - if REV != remote_rev: - print( - f"Local HEAD commit {REV[:10]} is different than " - f"tracked remote HEAD commit {remote_rev[:10]}" - ) - print("Did you forget to `git push` ?") + # Ignore local branches that do not track any remote + if tracked_remote: + remote_rev = check_output([ + 'git', 'rev-parse', tracked_remote, + ]).decode('ascii').strip() + + if REV != remote_rev: + print( + f"Local HEAD commit {REV[:10]} is different than " + f"tracked remote HEAD commit {remote_rev[:10]}" + ) + print("Did you forget to `git push` ?") projects.append(get_gitlab_project(gl, args.project)) (pipe, cur_project) = wait_for_pipeline(projects, REV)