Skip to content

Commit b97bd7a

Browse files
giorio94borkmann
authored andcommitted
checkpatch: prevent unbound variable error
The blamed commit set the option to make the script fail if it tries to access any unbound variables, to catch possible errors. However, the script now fails when invoked directly, due to: > ./checkpatch.sh: line 218: GITHUB_REF: unbound variable While this is not a problem in practice, given that the Cilium's Makefile always sets the GITHUB_REF variable (possibly empty), let's guard the variable accesses, to be a bit more user-friendly. Fixes: 5d11067 ("checkpatch: make script exit if command exits with error") Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
1 parent 60ee83e commit b97bd7a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

images/checkpatch/checkpatch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fi
215215

216216
check_cmd git ifne jq
217217

218-
if [ -n "$GITHUB_REF" ]; then
218+
if [ -n "${GITHUB_REF-}" ]; then
219219
# Running as GitHub action
220220
# We'll run checkpatch on each commit from the PR
221221
check_cmd curl
@@ -256,11 +256,11 @@ ret=0
256256
for ((i=0; i<nb_commits; i++)); do
257257
sha=$(echo "$list_commits" | jq -r ".[$i].sha")
258258
subject=$(echo "$list_commits" | jq -r ".[$i].subject")
259-
check_commit "$((i+1))" "$nb_commits" "$sha" "$subject" "$GITHUB_REF"
259+
check_commit "$((i+1))" "$nb_commits" "$sha" "$subject" "${GITHUB_REF-}"
260260
done
261261

262262
# If not a GitHub action and repo is dirty, run on diff from HEAD
263-
if [ -z "$GITHUB_REF" ] && ! (git diff --exit-code && git diff --cached --exit-code) >/dev/null; then
263+
if [ -z "${GITHUB_REF-}" ] && ! (git diff --exit-code && git diff --cached --exit-code) >/dev/null; then
264264
echo "========================================================="
265265
echo -e "${HL_START}Running on changes from local HEAD$HL_END"
266266
echo "========================================================="

0 commit comments

Comments
 (0)