Improve updating output for errors or other conditions

This commit is contained in:
Adam Goldsmith 2023-04-17 00:12:00 -04:00
parent 40a24178fb
commit bc758f6e22
1 changed files with 34 additions and 15 deletions

49
dup
View File

@ -31,32 +31,51 @@ function do_get() {
function do_pull() { function do_pull() {
dir="$1" dir="$1"
function git_in_dir() {
stdbuf -oL git -C "$dir" $@
}
if [ "$stashAndSync" = true ] if [ "$stashAndSync" = true ]
then then
local do_stash git_in_dir pull --rebase --autostash
do_stash=$(git diff) git_in_dir push
[ -n "$do_stash" ] && git -C "$dir" stash
git pull -C "$dir" --rebase
git push -C "$dir"
[ -n "$do_stash" ] && git -C "$dir" stash pop || true
else else
git -C "$dir" pull git_in_dir pull
fi fi
} }
function do_pull_maybe_quiet() { function do_pull_maybe_quiet() {
function pull_header_line() {
echo "$(tput $1)}$(tput sgr0) $(tput $2)$3$(tput sgr0): $4"
}
name="$1" name="$1"
dir="${2:-$name}" dir="${2:-$name}"
git_out="$(do_pull $dir)" git_out="$(do_pull $dir 2>&1)"
git_status=$?
first_line="${git_out%%$'\n'*}" first_line="${git_out%%$'\n'*}"
if [[ "$quiet" != true || "$first_line" != "Already up to date." ]] if [ $git_status -ne 0 ]
then then
echo "$(tput setaf 4)}$(tput sgr0) $(tput bold)$name$(tput sgr0): $first_line" pull_header_line "setaf 1 bold" "setaf 1 bold" "$name" "$git_out"
fi else
if [[ $first_line == Updating* ]] case "$first_line" in
then "Already up to date.")
git -C "${dir}" log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ${first_line##Updating } \ [[ "$quiet" == "true" ]] || \
| sed 's/^/ /' pull_header_line "setaf 4" bold "$name" "$first_line"
;;
Updating*)
if [[ "$quiet" != "true" ]]
then
pull_header_line "setaf 4" bold "$name" "$first_line"
git -C "${dir}" log --graph --color \
--format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' \
${first_line##Updating } \
| sed 's/^/ /'
fi
;;
*)
pull_header_line "setaf 5 bold" "setaf 5 bold" "$name" "$git_out"
esac
fi fi
} }