Skip to content

Commit 6b37dff

Browse files
avargitster
authored andcommitted
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 <[email protected]> Reviewed-by: Fernando Vezzosi <[email protected]> Reviewed-by: Eric Herman <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Liked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f696543 commit 6b37dff

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

Documentation/config.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,12 @@ branch.<name>.mergeoptions::
668668
branch.<name>.rebase::
669669
When true, rebase the branch <name> on top of the fetched branch,
670670
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).
675677

676678
browser.<tool>.cmd::
677679
Specify the command to invoke the specified browser. The
@@ -1548,6 +1550,16 @@ pretty.<name>::
15481550
Note that an alias with the same name as a built-in format
15491551
will be silently ignored.
15501552

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+
15511563
pull.octopus::
15521564
The default merge strategy to use when pulling multiple branches
15531565
at once.

Documentation/git-pull.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ include::merge-options.txt[]
107107
fetched, the rebase uses that information to avoid rebasing
108108
non-local changes.
109109
+
110-
See `branch.<name>.rebase` and `branch.autosetuprebase` in
110+
See `pull.rebase`, `branch.<name>.rebase` and `branch.autosetuprebase` in
111111
linkgit:git-config[1] if you want to make `git pull` always use
112112
`{litdd}rebase` instead of merging.
113113
+

git-pull.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ merge_args=
4343
curr_branch=$(git symbolic-ref -q HEAD)
4444
curr_branch_short="${curr_branch#refs/heads/}"
4545
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
4650
dry_run=
4751
while :
4852
do

t/t5520-pull.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,35 @@ test_expect_success '--rebase' '
9494
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
9595
test new = $(git show HEAD:file2)
9696
'
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+
'
97105

98106
test_expect_success 'branch.to-rebase.rebase' '
99107
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" &&
101110
git pull . copy &&
102-
git config branch.to-rebase.rebase 0 &&
103111
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
104112
test new = $(git show HEAD:file2)
105113
'
106114

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+
107126
test_expect_success '--rebase with rebased upstream' '
108127
109128
git remote add -f me . &&

0 commit comments

Comments
 (0)