Skip to content

Commit c525de3

Browse files
felipecgitster
authored andcommitted
pull: display default warning only when non-ff
There's no need to display the annoying warning on every pull... only the ones that are not fast-forward. The current warning tests still pass, but not because of the arguments or the configuration, but because they are all fast-forward. We need to test non-fast-forward situations now. Suggestions-by: Junio C Hamano <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7539fdc commit c525de3

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

builtin/pull.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
949949
struct object_id rebase_fork_point;
950950
int autostash;
951951
int rebase_unspecified = 0;
952+
int can_ff;
952953

953954
if (!getenv("GIT_REFLOG_ACTION"))
954955
set_reflog_message(argc, argv);
@@ -1044,7 +1045,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10441045
if (opt_rebase && merge_heads.nr > 1)
10451046
die(_("Cannot rebase onto multiple branches."));
10461047

1047-
if (rebase_unspecified && !opt_ff) {
1048+
can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
1049+
1050+
if (rebase_unspecified && !opt_ff && !can_ff) {
10481051
if (opt_verbosity >= 0)
10491052
show_advice_pull_non_ff();
10501053
}
@@ -1063,7 +1066,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10631066
submodule_touches_in_range(the_repository, &upstream, &curr_head))
10641067
die(_("cannot rebase with locally recorded submodule modifications"));
10651068
if (!autostash) {
1066-
if (get_can_ff(&orig_head, &merge_heads.oid[0])) {
1069+
if (can_ff) {
10671070
/* we can fast-forward this without invoking rebase */
10681071
opt_ff = "--ff-only";
10691072
ran_ff = 1;

t/t7601-merge-pull-config.sh

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ test_expect_success 'setup' '
2929

3030
test_expect_success 'pull.rebase not set' '
3131
git reset --hard c0 &&
32-
git -c color.advice=always pull . c1 2>err &&
33-
test_decode_color <err >decoded &&
34-
test_i18ngrep "<YELLOW>hint: " decoded &&
35-
test_i18ngrep "Pulling without specifying how to reconcile" decoded
36-
32+
git pull . c1 2>err &&
33+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
3734
'
3835

3936
test_expect_success 'pull.rebase not set and pull.ff=true' '
@@ -87,6 +84,65 @@ test_expect_success 'pull.rebase not set and --ff-only given' '
8784
test_i18ngrep ! "Pulling without specifying how to reconcile" err
8885
'
8986

87+
test_expect_success 'pull.rebase not set (not-fast-forward)' '
88+
git reset --hard c2 &&
89+
git -c color.advice=always pull . c1 2>err &&
90+
test_decode_color <err >decoded &&
91+
test_i18ngrep "<YELLOW>hint: " decoded &&
92+
test_i18ngrep "Pulling without specifying how to reconcile" decoded
93+
'
94+
95+
test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' '
96+
git reset --hard c2 &&
97+
test_config pull.ff true &&
98+
git pull . c1 2>err &&
99+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
100+
'
101+
102+
test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' '
103+
git reset --hard c2 &&
104+
test_config pull.ff false &&
105+
git pull . c1 2>err &&
106+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
107+
'
108+
109+
test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' '
110+
git reset --hard c2 &&
111+
test_config pull.ff only &&
112+
test_must_fail git pull . c1 2>err &&
113+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
114+
'
115+
116+
test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' '
117+
git reset --hard c2 &&
118+
git pull --rebase . c1 2>err &&
119+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
120+
'
121+
122+
test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' '
123+
git reset --hard c2 &&
124+
git pull --no-rebase . c1 2>err &&
125+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
126+
'
127+
128+
test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' '
129+
git reset --hard c2 &&
130+
git pull --ff . c1 2>err &&
131+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
132+
'
133+
134+
test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' '
135+
git reset --hard c2 &&
136+
git pull --no-ff . c1 2>err &&
137+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
138+
'
139+
140+
test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' '
141+
git reset --hard c2 &&
142+
test_must_fail git pull --ff-only . c1 2>err &&
143+
test_i18ngrep ! "Pulling without specifying how to reconcile" err
144+
'
145+
90146
test_expect_success 'merge c1 with c2' '
91147
git reset --hard c1 &&
92148
test -f c0.c &&

0 commit comments

Comments
 (0)