Improve updating output for errors or other conditions
This commit is contained in:
parent
40a24178fb
commit
bc758f6e22
45
dup
45
dup
|
@ -31,33 +31,52 @@ 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
|
||||||
|
"Already up to date.")
|
||||||
|
[[ "$quiet" == "true" ]] || \
|
||||||
|
pull_header_line "setaf 4" bold "$name" "$first_line"
|
||||||
|
;;
|
||||||
|
Updating*)
|
||||||
|
if [[ "$quiet" != "true" ]]
|
||||||
then
|
then
|
||||||
git -C "${dir}" log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ${first_line##Updating } \
|
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/^/ /'
|
| sed 's/^/ /'
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
pull_header_line "setaf 5 bold" "setaf 5 bold" "$name" "$git_out"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_script() {
|
function run_script() {
|
||||||
|
|
Loading…
Reference in New Issue