Skip to content

Commit 1c56d6f

Browse files
committed
Merge branch 'ah/force-pull-rebase-configuration'
"git pull" learned to warn when no pull.rebase configuration exists, and neither --[no-]rebase nor --ff-only is given (which would result a merge). * ah/force-pull-rebase-configuration: pull: warn if the user didn't say whether to rebase or to merge
2 parents 369ae75 + d18c950 commit 1c56d6f

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

builtin/pull.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,22 @@ static enum rebase_type config_get_rebase(void)
327327
if (!git_config_get_value("pull.rebase", &value))
328328
return parse_config_rebase("pull.rebase", value, 1);
329329

330+
if (opt_verbosity >= 0 &&
331+
(!opt_ff || strcmp(opt_ff, "--ff-only"))) {
332+
warning(_("Pulling without specifying how to reconcile divergent branches is\n"
333+
"discouraged. You can squelch this message by running one of the following\n"
334+
"commands sometime before your next pull:\n"
335+
"\n"
336+
" git config pull.rebase false # merge (the default strategy)\n"
337+
" git config pull.rebase true # rebase\n"
338+
" git config pull.ff only # fast-forward only\n"
339+
"\n"
340+
"You can replace \"git config\" with \"git config --global\" to set a default\n"
341+
"preference for all repositories. You can also pass --rebase, --no-rebase,\n"
342+
"or --ff-only on the command line to override the configured default per\n"
343+
"invocation.\n"));
344+
}
345+
330346
return REBASE_FALSE;
331347
}
332348

t/t5521-pull-options.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ test_expect_success 'setup' '
1111
git commit -m one)
1212
'
1313

14-
test_expect_success 'git pull -q' '
14+
test_expect_success 'git pull -q --no-rebase' '
1515
mkdir clonedq &&
1616
(cd clonedq && git init &&
17-
git pull -q "../parent" >out 2>err &&
17+
git pull -q --no-rebase "../parent" >out 2>err &&
1818
test_must_be_empty err &&
1919
test_must_be_empty out)
2020
'
@@ -30,10 +30,10 @@ test_expect_success 'git pull -q --rebase' '
3030
test_must_be_empty out)
3131
'
3232

33-
test_expect_success 'git pull' '
33+
test_expect_success 'git pull --no-rebase' '
3434
mkdir cloned &&
3535
(cd cloned && git init &&
36-
git pull "../parent" >out 2>err &&
36+
git pull --no-rebase "../parent" >out 2>err &&
3737
test -s err &&
3838
test_must_be_empty out)
3939
'
@@ -46,10 +46,10 @@ test_expect_success 'git pull --rebase' '
4646
test_must_be_empty out)
4747
'
4848

49-
test_expect_success 'git pull -v' '
49+
test_expect_success 'git pull -v --no-rebase' '
5050
mkdir clonedv &&
5151
(cd clonedv && git init &&
52-
git pull -v "../parent" >out 2>err &&
52+
git pull -v --no-rebase "../parent" >out 2>err &&
5353
test -s err &&
5454
test_must_be_empty out)
5555
'
@@ -62,25 +62,25 @@ test_expect_success 'git pull -v --rebase' '
6262
test_must_be_empty out)
6363
'
6464

65-
test_expect_success 'git pull -v -q' '
65+
test_expect_success 'git pull -v -q --no-rebase' '
6666
mkdir clonedvq &&
6767
(cd clonedvq && git init &&
68-
git pull -v -q "../parent" >out 2>err &&
68+
git pull -v -q --no-rebase "../parent" >out 2>err &&
6969
test_must_be_empty out &&
7070
test_must_be_empty err)
7171
'
7272

73-
test_expect_success 'git pull -q -v' '
73+
test_expect_success 'git pull -q -v --no-rebase' '
7474
mkdir clonedqv &&
7575
(cd clonedqv && git init &&
76-
git pull -q -v "../parent" >out 2>err &&
76+
git pull -q -v --no-rebase "../parent" >out 2>err &&
7777
test_must_be_empty out &&
7878
test -s err)
7979
'
8080
test_expect_success 'git pull --cleanup errors early on invalid argument' '
8181
mkdir clonedcleanup &&
8282
(cd clonedcleanup && git init &&
83-
test_must_fail git pull --cleanup invalid "../parent" >out 2>err &&
83+
test_must_fail git pull --no-rebase --cleanup invalid "../parent" >out 2>err &&
8484
test_must_be_empty out &&
8585
test -s err)
8686
'

t/t7601-merge-pull-config.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,44 @@ test_expect_success 'setup' '
2727
git tag c3
2828
'
2929

30+
test_expect_success 'pull.rebase not set' '
31+
git reset --hard c0 &&
32+
git pull . c1 2>err &&
33+
test_i18ngrep "Pulling without specifying how to reconcile" err
34+
'
35+
36+
test_expect_success 'pull.rebase not set and pull.ff=false' '
37+
git reset --hard c0 &&
38+
test_config pull.ff false &&
39+
git pull . c1 2>err &&
40+
test_i18ngrep "Pulling without specifying how to reconcile" err
41+
'
42+
43+
test_expect_success 'pull.rebase not set and pull.ff=only' '
44+
git reset --hard c0 &&
45+
test_config pull.ff only &&
46+
git pull . c1 2>err &&
47+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
48+
'
49+
50+
test_expect_success 'pull.rebase not set and --rebase given' '
51+
git reset --hard c0 &&
52+
git pull --rebase . c1 2>err &&
53+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
54+
'
55+
56+
test_expect_success 'pull.rebase not set and --no-rebase given' '
57+
git reset --hard c0 &&
58+
git pull --no-rebase . c1 2>err &&
59+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
60+
'
61+
62+
test_expect_success 'pull.rebase not set and --ff-only given' '
63+
git reset --hard c0 &&
64+
git pull --ff-only . c1 2>err &&
65+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
66+
'
67+
3068
test_expect_success 'merge c1 with c2' '
3169
git reset --hard c1 &&
3270
test -f c0.c &&

0 commit comments

Comments
 (0)