Get tests passing again.
[git-central.git] / scripts / pull
1 #!/bin/bash
2 #
3 # Makes pull "just work" by correctly rebasing of local commits on top of new
4 # incoming commits.
5 #
6 # This avoids the "same-branch" merges that the default "git pull" creates of
7 # your local branch foo being merged into the remote branch origin/foo.
8 #
9 # Also, even though "git pull" has a branch.<name>.rebase flag, it will replay
10 # commits if you have local merges of other branches that are being rebased--the
11 # "-p" parameter to git rebase prevents this reply but is not available from the
12 # "git pull" command line or config options--hence this script.
13 #
14
15 branch_name=$(git symbolic-ref --quiet HEAD)
16 if [[ $? -ne 0 ]] ; then
17         echo "Not on a branch"
18         exit 1
19 fi
20 branch_name=${branch_name/refs\/heads\//}
21
22 git fetch
23 if [[ $? -ne 0 ]] ; then
24         exit $?
25 fi
26
27 # rebase-p-i stops if nothing to do, even a ff, so do a non-i-p if needed
28 if test "$(git rev-parse HEAD)" = "$(git merge-base HEAD origin/$branch_name)" ; then
29         git rebase "origin/$branch_name"
30 else
31         GIT_EDITOR=: git rebase -p -i "origin/$branch_name"
32 fi
33