Skip to content

Commit cfd4ad3

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 da04d23 + f918d20 commit cfd4ad3

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
@@ -922,10 +922,24 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
922922
if (merge_heads.nr > 1)
923923
die(_("Cannot merge multiple branches into empty head."));
924924
return pull_into_void(*merge_heads.sha1, curr_head);
925-
} else if (opt_rebase) {
926-
if (merge_heads.nr > 1)
927-
die(_("Cannot rebase onto multiple branches."));
925+
}
926+
if (opt_rebase && merge_heads.nr > 1)
927+
die(_("Cannot rebase onto multiple branches."));
928+
929+
if (opt_rebase) {
930+
struct commit_list *list = NULL;
931+
struct commit *merge_head, *head;
932+
933+
head = lookup_commit_reference(orig_head);
934+
commit_list_insert(head, &list);
935+
merge_head = lookup_commit_reference(merge_heads.sha1[0]);
936+
if (is_descendant_of(merge_head, list)) {
937+
/* we can fast-forward this without invoking rebase */
938+
opt_ff = "--ff-only";
939+
return run_merge();
940+
}
928941
return run_rebase(curr_head, *merge_heads.sha1, rebase_fork_point);
929-
} else
942+
} else {
930943
return run_merge();
944+
}
931945
}

0 commit comments

Comments
 (0)