You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
740 B

  1. #!/bin/sh
  2. cd "$(dirname "$0")"
  3. branch="$(git branch | sed -n 's/^* \(.*\)$/\1/p;')"
  4. [ -n "$branch" ] || exit
  5. remote=$(git config --get "branch.$branch.remote")
  6. rbranch=$(git config --get "branch.$branch.merge" | sed -e 's|^refs/heads/||')
  7. rurl=$(git config --get "remote.$remote.url")
  8. [ -n "$remote" -a -n "$rbranch" -a -n "$rurl" ] || exit
  9. echo "# $PWD ($branch <- $rurl:$rbranch)"
  10. hash0=$(git rev-parse "$remote/$rbranch")
  11. git fetch "$remote"
  12. hash1=$(git rev-parse "$remote/$rbranch")
  13. [ -n "$hash0" -a -n "$hash1" -a "$hash0" != "$hash1" ] || exit
  14. if [ "$(git ls-files -md)" ]; then
  15. stashed=true
  16. git stash -q
  17. else
  18. stashed=false
  19. fi
  20. git rebase "$remote/$rbranch"
  21. if $stashed; then
  22. git stash pop -q
  23. fi
  24. [ $# -eq 0 ] || exec "$@"