Skip to content

Commit a784125

Browse files
committed
fix: Improve error handling and output of Git command errors
1 parent 75ced51 commit a784125

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

pkg/lib/commands/do-list.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ echo_package_info() {
120120
if git -C "$pkg_path" config remote.origin.url &>/dev/null; then
121121
if [ "$flag_fetch" = yes ]; then
122122
local git_output=
123-
if ! git_output="$(git -C "$pkg_path" fetch)"; then
124-
printf "%s\n" "$git_output"
123+
if ! git_output="$(git -C "$pkg_path" fetch 2>&1)"; then
124+
printf " --> %s\n" "Git output:"
125+
printf " --> %s\n" "${git_output%.}"
125126
fi
126127
fi
127128

pkg/lib/commands/do-plumbing-clone.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ do-plumbing-clone() {
3030
local git_output=
3131
if ! git_output="$(git clone "${git_args[@]}" 2>&1)"; then
3232
log.error "Could not clone repository"
33-
printf "%s\n" "$git_output"
33+
printf " --> %s\n" "Git output:"
34+
printf " --> %s\n" "${git_output%.}"
3435
exit 1
3536
fi
3637

pkg/lib/commands/do-prune.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ do-prune() {
88

99
for file in "$BPM_INSTALL_BIN"/* "$BPM_INSTALL_MAN"/*/* "$BPM_INSTALL_COMPLETIONS"/{bash,zsh/{compsys,compctl},fish}/*; do
1010
local real_file=
11-
real_file="$(readlink "$file")"
11+
if ! real_file="$(readlink "$file")"; then
12+
die "Readlink '$file' unexpectedly failed"
13+
fi
1214

1315
if [[ "${real_file:0:1}" == / && -e "$real_file" ]]; then
1416
# The only valid symlinks 'bpm' creates are absolute paths
@@ -17,6 +19,8 @@ do-prune() {
1719
fi
1820

1921
printf ' -> %s\n' "Unsymlinking broken symlink '$file'"
20-
unlink "$file"
22+
if ! unlink "$file"; then
23+
die "Unlink '$file' unexpectedly failed"
24+
fi
2125
done
2226
}

pkg/lib/commands/do-remove.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ do_actual_removal() {
101101

102102
if [ "${id%%/*}" = 'local' ]; then
103103
printf ' -> %s\n' "Unsymlinking directory"
104-
unlink "$BPM_PACKAGES_PATH/$id"
104+
if ! unlink "$BPM_PACKAGES_PATH/$id"; then
105+
die "Unlink '$BPM_PACKAGES_PATH/$id' unexpectedly failed"
106+
fi
105107
else
106108
printf ' -> %s\n' "Removing Git repository"
107109
rm -rf "${BPM_PACKAGES_PATH:?}/$id"

pkg/lib/commands/do-upgrade.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ do_actual_upgrade() {
111111
local git_output=
112112
if ! git_output="$(git -C "$BPM_PACKAGES_PATH/$id" pull 2>&1)"; then
113113
log.error "Could not update Git repository"
114-
printf "%s\n" "$git_output"
114+
printf " --> %s\n" "Git output:"
115+
printf " --> %s\n" "${git_output%.}"
115116
exit 1
116117
fi
117118

0 commit comments

Comments
 (0)