Improve updating output for errors or other conditions
This commit is contained in:
parent
40a24178fb
commit
bc758f6e22
49
dup
49
dup
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue