Skip to content

Commit 8dd4543

Browse files
committed
Merge branch 'jc/pull-rebase-ff' into pu
"git pull --rebase", when there is no new commits on our side since we forked from the upstream, should be able to fast-forward without invoking "git rebase", but it didn't. * jc/pull-rebase-ff: pull: fast-forward "pull --rebase=true"
2 parents 386a8bf + 3626785 commit 8dd4543

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

builtin/pull.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,10 +857,24 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
857857
if (merge_heads.nr > 1)
858858
die(_("Cannot merge multiple branches into empty head."));
859859
return pull_into_void(*merge_heads.sha1, curr_head);
860-
} else if (opt_rebase) {
861-
if (merge_heads.nr > 1)
862-
die(_("Cannot rebase onto multiple branches."));
860+
}
861+
if (opt_rebase && merge_heads.nr > 1)
862+
die(_("Cannot rebase onto multiple branches."));
863+
864+
if (opt_rebase) {
865+
struct commit_list *list = NULL;
866+
struct commit *merge_head, *head;
867+
868+
head = lookup_commit_reference(orig_head);
869+
commit_list_insert(head, &list);
870+
merge_head = lookup_commit_reference(merge_heads.sha1[0]);
871+
if (is_descendant_of(merge_head, list)) {
872+
/* we can fast-forward this without invoking rebase */
873+
opt_ff = "--ff-only";
874+
return run_merge();
875+
}
863876
return run_rebase(curr_head, *merge_heads.sha1, rebase_fork_point);
864-
} else
877+
} else {
865878
return run_merge();
879+
}
866880
}

0 commit comments

Comments
 (0)