Skip to content

Commit f7c3b00

Browse files
committed
improve error handling
1 parent 4747aad commit f7c3b00

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

usr/bin/check-ref-commits-for-unicode

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ source /usr/libexec/helper-scripts/log_run_die.sh
1414
log_level=info
1515

1616
check_ref_commits_for_unicode() {
17-
local target_ref commit_list commit commit_diff unicode_report \
18-
unicode_show_exit_code found_malicious_unicode
17+
local target_ref git_log_cmd git_log_output commit_list commit commit_diff \
18+
unicode_report unicode_show_exit_code found_malicious_unicode
1919

2020
target_ref="${1:-}"
2121
if [ -z "${target_ref}" ]; then
@@ -30,11 +30,22 @@ check_ref_commits_for_unicode() {
3030
die 1 'Target ref does not exist!'
3131
fi
3232

33-
readarray -t commit_list < <(git log --format=%H "HEAD..${target_ref}")
34-
if [ -z "${commit_list[0]:-}" ]; then
33+
git_log_cmd=( git log --format=%H "HEAD..${target_ref}" )
34+
35+
if ! git_log_output="$( "${git_log_cmd[@]}" )"; then
36+
die 1 "git_log_cmd failed! git_log_cmd: ${git_log_cmd[*]}"
37+
fi
38+
39+
if [ "$git_log_output" = "" ]; then
3540
die 1 'No new commits in target ref!'
3641
fi
3742

43+
readarray -t commit_list <<< "$git_log_output"
44+
45+
if [ -z "${commit_list[0]:-}" ]; then
46+
die 1 'commit_list array size is 0!'
47+
fi
48+
3849
found_malicious_unicode='false'
3950
for commit in "${commit_list[@]}"; do
4051
## --no-ext-diff prevents use of external diff drivers.

0 commit comments

Comments
 (0)