Skip to content

Commit ea1954a

Browse files
erwinvgitster
authored andcommitted
pull: should be noop when already-up-to-date
The already-up-to-date pull bug was fixed for --ff-only but it did not include the case where --ff or --ff-only are not specified. This updates the --ff-only fix to include the case where --ff or --ff-only are not specified in command line flags or config. Signed-off-by: Erwin Villejo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 361cb52 commit ea1954a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

builtin/pull.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
984984
struct object_id rebase_fork_point;
985985
int rebase_unspecified = 0;
986986
int can_ff;
987+
int divergent;
987988

988989
if (!getenv("GIT_REFLOG_ACTION"))
989990
set_reflog_message(argc, argv);
@@ -1098,15 +1099,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10981099
}
10991100

11001101
can_ff = get_can_ff(&orig_head, &merge_heads);
1102+
divergent = !can_ff && !already_up_to_date(&orig_head, &merge_heads);
11011103

11021104
/* ff-only takes precedence over rebase */
11031105
if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
1104-
if (!can_ff && !already_up_to_date(&orig_head, &merge_heads))
1106+
if (divergent)
11051107
die_ff_impossible();
11061108
opt_rebase = REBASE_FALSE;
11071109
}
11081110
/* If no action specified and we can't fast forward, then warn. */
1109-
if (!opt_ff && rebase_unspecified && !can_ff) {
1111+
if (!opt_ff && rebase_unspecified && divergent) {
11101112
show_advice_pull_non_ff();
11111113
die(_("Need to specify how to reconcile divergent branches."));
11121114
}

t/t7601-merge-pull-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
387387
test_must_fail git pull . c3
388388
'
389389

390+
test_expect_success 'already-up-to-date pull succeeds with unspecified pull.ff' '
391+
git reset --hard c1 &&
392+
git pull . c0 &&
393+
test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
394+
'
395+
390396
test_expect_success 'already-up-to-date pull succeeds with "only" in pull.ff' '
391397
git reset --hard c1 &&
392398
test_config pull.ff only &&

0 commit comments

Comments
 (0)