ci: squelch warnings when testing with unusable Git repo
Our CI jobs that run on Docker also use mostly the same architecture to build and test Git via the "ci/run-build-and-tests.sh" script. These scripts also provide some functionality to massage the Git repository we're supposedly operating in. In our Docker-based infrastructure we may not even have a Git repository available though, which leads to warnings when those functions execute. Make the helpers exit gracefully in case either there is no Git in our PATH, or when not running in a Git repository. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Nov 9, 2023 at 09:05 UTC
dd02c3b68c67f8e9a5daca3b52a562318738fa47
1 file changed
+32
ci/lib.sh
+32
@@ -69,10 +69,32 @@ skip_branch_tip_with_tag () {
69
fi
70
}
71
72
+# Check whether we can use the path passed via the first argument as Git
73
+# repository.
74
+is_usable_git_repository () {
75
+ # We require Git in our PATH, otherwise we cannot access repositories
76
+ # at all.
77
+ if ! command -v git >/dev/null
78
+ then
79
+ return 1
80
+ fi
81
+
82
+ # And the target directory needs to be a proper Git repository.
83
+ if ! git -C "$1" rev-parse 2>/dev/null
84
+ then
85
+ return 1
86
+ fi
87
+}
88
+
89
# Save some info about the current commit's tree, so we can skip the build
90
# job if we encounter the same tree again and can provide a useful info
91
# message.
92
save_good_tree () {
93
+ if ! is_usable_git_repository .
94
+ then
95
+ return
96
+ fi
97
+
98
echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
99
# limit the file size
100
tail -1000 "$good_trees_file" >"$good_trees_file".tmp
@@ -88,6 +110,11 @@ skip_good_tree () {
110
return
111
fi
112
113
+ if ! is_usable_git_repository .
114
+ then
115
+ return
116
+ fi
117
+
118
if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")"
119
then
120
# Haven't seen this tree yet, or no cached good trees file yet.
@@ -119,6 +146,11 @@ skip_good_tree () {
146
}
147
148
check_unignored_build_artifacts () {
149
+ if ! is_usable_git_repository .
150
+ then
151
+ return
152
+ fi
153
+
154
! git ls-files --other --exclude-standard --error-unmatch \
155
-- ':/*' 2>/dev/null ||
156
{