pull: introduce a pull.rebase option to enable --rebase

Currently we either need to set branch.<name>.rebase for existing branches if we'd like "git pull" to mean "git pull --rebase", or have the forethought of setting "branch.autosetuprebase" before we create the branch. Introduce a "pull.rebase" option to globally configure "git pull" to mean "git pull --rebase" for any branch. This option will be considered at a lower priority than branch.<name>.rebase, i.e. we could set pull.rebase=true and branch.<name>.rebase=false and the latter configuration option would win. Reviewed-by: Sverre Rabbelier <srabbelier@gmail.com> Reviewed-by: Fernando Vezzosi <buccia@repnz.net> Reviewed-by: Eric Herman <eric@freesa.org> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Liked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Nov 6, 2011 at 10:50 UTC 6b37dff17f176d7e87efa93b4cf521dd725de247
4 files changed +42 -7
Documentation/config.txt
+16 -4
@@ -668,10 +668,12 @@ branch.<name>.mergeoptions::
668 branch.<name>.rebase::
669 When true, rebase the branch <name> on top of the fetched branch,
670 instead of merging the default branch from the default remote when
671 - "git pull" is run.
672 - *NOTE*: this is a possibly dangerous operation; do *not* use
673 - it unless you understand the implications (see linkgit:git-rebase[1]
674 - for details).
671 + "git pull" is run. See "pull.rebase" for doing this in a non
672 + branch-specific manner.
673 ++
674 +*NOTE*: this is a possibly dangerous operation; do *not* use
675 +it unless you understand the implications (see linkgit:git-rebase[1]
676 +for details).
677
678 browser.<tool>.cmd::
679 Specify the command to invoke the specified browser. The
@@ -1548,6 +1550,16 @@ pretty.<name>::
1550 Note that an alias with the same name as a built-in format
1551 will be silently ignored.
1552
1553 +pull.rebase::
1554 + When true, rebase branches on top of the fetched branch, instead
1555 + of merging the default branch from the default remote when "git
1556 + pull" is run. See "branch.<name>.rebase" for setting this on a
1557 + per-branch basis.
1558 ++
1559 +*NOTE*: this is a possibly dangerous operation; do *not* use
1560 +it unless you understand the implications (see linkgit:git-rebase[1]
1561 +for details).
1562 +
1563 pull.octopus::
1564 The default merge strategy to use when pulling multiple branches
1565 at once.
Documentation/git-pull.txt
+1 -1
@@ -107,7 +107,7 @@ include::merge-options.txt[]
107 fetched, the rebase uses that information to avoid rebasing
108 non-local changes.
109 +
110 -See `branch.<name>.rebase` and `branch.autosetuprebase` in
110 +See `pull.rebase`, `branch.<name>.rebase` and `branch.autosetuprebase` in
111 linkgit:git-config[1] if you want to make `git pull` always use
112 `{litdd}rebase` instead of merging.
113 +
git-pull.sh
+4
@@ -43,6 +43,10 @@ merge_args=
43 curr_branch=$(git symbolic-ref -q HEAD)
44 curr_branch_short="${curr_branch#refs/heads/}"
45 rebase=$(git config --bool branch.$curr_branch_short.rebase)
46 +if test -z "$rebase"
47 +then
48 + rebase=$(git config --bool pull.rebase)
49 +fi
50 dry_run=
51 while :
52 do
t/t5520-pull.sh
+21 -2
@@ -94,16 +94,35 @@ test_expect_success '--rebase' '
94 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
95 test new = $(git show HEAD:file2)
96 '
97 +test_expect_success 'pull.rebase' '
98 + git reset --hard before-rebase &&
99 + git config --bool pull.rebase true &&
100 + test_when_finished "git config --unset pull.rebase" &&
101 + git pull . copy &&
102 + test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
103 + test new = $(git show HEAD:file2)
104 +'
105
106 test_expect_success 'branch.to-rebase.rebase' '
107 git reset --hard before-rebase &&
100 - git config branch.to-rebase.rebase 1 &&
108 + git config --bool branch.to-rebase.rebase true &&
109 + test_when_finished "git config --unset branch.to-rebase.rebase" &&
110 git pull . copy &&
102 - git config branch.to-rebase.rebase 0 &&
111 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
112 test new = $(git show HEAD:file2)
113 '
114
115 +test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
116 + git reset --hard before-rebase &&
117 + git config --bool pull.rebase true &&
118 + test_when_finished "git config --unset pull.rebase" &&
119 + git config --bool branch.to-rebase.rebase false &&
120 + test_when_finished "git config --unset branch.to-rebase.rebase" &&
121 + git pull . copy &&
122 + test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
123 + test new = $(git show HEAD:file2)
124 +'
125 +
126 test_expect_success '--rebase with rebased upstream' '
127
128 git remote add -f me . &&