Set u+x on scripts.
[git-central.git] / scripts / pull
old mode 100644 (file)
new mode 100755 (executable)
index c2313ba..c8bcbdd
@@ -1,11 +1,22 @@
 #!/bin/sh
+#
+# Makes pull "just work" by correctly rebasing of local commits on top of new
+# incoming commits.
+#
+# This avoids the "same-branch" merges that the default "git pull" creates of
+# your local branch foo being merged into the remote branch origin/foo.
+#
+# Also, even though "git pull" has a branch.<name>.rebase flag, it will replay
+# commits if you have local merges of other branches that are being rebased--the
+# "-p" parameter to git rebase prevents this reply but is not available from the
+# "git pull" command line or config options--hence this script.
+#
 
 branch_name=$(git symbolic-ref --quiet HEAD)
 if [[ $? -ne 0 ]] ; then
-       echo "not on a branch"
+       echo "Not on a branch"
        exit 1
 fi
-
 branch_name=${branch_name/refs\/heads\//}
 
 git fetch
@@ -13,5 +24,10 @@ if [[ $? -ne 0 ]] ; then
        exit $?
 fi
 
-GIT_EDITOR=: git rebase -p -i "origin/$branch_name"
+# rebase-p-i stops if nothing to do, even a ff, so do a non-i-p if needed
+if test "$(git rev-parse HEAD)" = "$(git merge-base HEAD origin/$branch_name)" ; then
+       git rebase "origin/$branch_name"
+else
+       GIT_EDITOR=: git rebase -p -i "origin/$branch_name"
+fi