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)