Skip to content

Commit ad03180

Browse files
committed
Merge branch 'ev/pull-already-up-to-date-is-noop' into maint
"git pull" with any strategy when the other side is behind us should succeed as it is a no-op, but doesn't. * ev/pull-already-up-to-date-is-noop: pull: should be noop when already-up-to-date
2 parents a650ff5 + ea1954a commit ad03180

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
@@ -988,6 +988,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
988988
struct object_id rebase_fork_point;
989989
int rebase_unspecified = 0;
990990
int can_ff;
991+
int divergent;
991992

992993
if (!getenv("GIT_REFLOG_ACTION"))
993994
set_reflog_message(argc, argv);
@@ -1102,15 +1103,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
11021103
}
11031104

11041105
can_ff = get_can_ff(&orig_head, &merge_heads);
1106+
divergent = !can_ff && !already_up_to_date(&orig_head, &merge_heads);
11051107

11061108
/* ff-only takes precedence over rebase */
11071109
if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
1108-
if (!can_ff && !already_up_to_date(&orig_head, &merge_heads))
1110+
if (divergent)
11091111
die_ff_impossible();
11101112
opt_rebase = REBASE_FALSE;
11111113
}
11121114
/* If no action specified and we can't fast forward, then warn. */
1113-
if (!opt_ff && rebase_unspecified && !can_ff) {
1115+
if (!opt_ff && rebase_unspecified && divergent) {
11141116
show_advice_pull_non_ff();
11151117
die(_("Need to specify how to reconcile divergent branches."));
11161118
}

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)