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