Browse Source

update.sh: only stash/rebase/run if there are remote updates

Signed-off-by: Alejandro Mery <amery@geeks.cl>
master
Alejandro Mery 11 years ago
parent
commit
077f25b0cf
1 changed files with 19 additions and 5 deletions
  1. +19
    -5
      update.sh

+ 19
- 5
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

Loading…
Cancel
Save