Skip to content

Commit dd02c3b

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9f17bef commit dd02c3b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

ci/lib.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,32 @@ skip_branch_tip_with_tag () {
6969
fi
7070
}
7171

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+
7289
# Save some info about the current commit's tree, so we can skip the build
7390
# job if we encounter the same tree again and can provide a useful info
7491
# message.
7592
save_good_tree () {
93+
if ! is_usable_git_repository .
94+
then
95+
return
96+
fi
97+
7698
echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
7799
# limit the file size
78100
tail -1000 "$good_trees_file" >"$good_trees_file".tmp
@@ -88,6 +110,11 @@ skip_good_tree () {
88110
return
89111
fi
90112

113+
if ! is_usable_git_repository .
114+
then
115+
return
116+
fi
117+
91118
if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")"
92119
then
93120
# Haven't seen this tree yet, or no cached good trees file yet.
@@ -119,6 +146,11 @@ skip_good_tree () {
119146
}
120147

121148
check_unignored_build_artifacts () {
149+
if ! is_usable_git_repository .
150+
then
151+
return
152+
fi
153+
122154
! git ls-files --other --exclude-standard --error-unmatch \
123155
-- ':/*' 2>/dev/null ||
124156
{

0 commit comments

Comments
 (0)