From 077f25b0cf99812d039f268d0f6c785a4faa0754 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 27 Nov 2013 10:58:40 +0100 Subject: [PATCH] update.sh: only stash/rebase/run if there are remote updates Signed-off-by: Alejandro Mery --- update.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/update.sh b/update.sh index c752455..14bd0b7 100755 --- a/update.sh +++ b/update.sh @@ -2,17 +2,31 @@ cd "$(dirname "$0")" +branch="$(git branch | sed -n 's/^* \(.*\)$/\1/p;')" +[ -n "$branch" ] || exit + +remote=$(git config --get "branch.$branch.remote") +rbranch=$(git config --get "branch.$branch.merge" | sed -e 's|^refs/heads/||') +rurl=$(git config --get "remote.$remote.url") +[ -n "$remote" -a -n "$rbranch" -a -n "$rurl" ] || exit + +echo "# $PWD ($branch <- $rurl:$rbranch)" + +hash0=$(git rev-parse "$remote/$rbranch") +git fetch "$remote" +hash1=$(git rev-parse "$remote/$rbranch") +[ "$hash0" != "$hash1" ] || exit + if [ "$(git ls-files -md)" ]; then - updated=true + stashed=true git stash -q else - updated=false + stashed=false fi -echo "== $PWD ==" -git pull -q --rebase +git rebase "$remote/$rbranch" -if $updated; then +if $stashed; then git stash pop -q fi