Skip to content

Commit 3626785

Browse files
committed
pull: fast-forward "pull --rebase=true"
Signed-off-by: Junio C Hamano <[email protected]>
1 parent e465796 commit 3626785

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
@@ -878,10 +878,24 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
878878
if (merge_heads.nr > 1)
879879
die(_("Cannot merge multiple branches into empty head."));
880880
return pull_into_void(*merge_heads.sha1, curr_head);
881-
} else if (opt_rebase) {
882-
if (merge_heads.nr > 1)
883-
die(_("Cannot rebase onto multiple branches."));
881+
}
882+
if (opt_rebase && merge_heads.nr > 1)
883+
die(_("Cannot rebase onto multiple branches."));
884+
885+
if (opt_rebase) {
886+
struct commit_list *list = NULL;
887+
struct commit *merge_head, *head;
888+
889+
head = lookup_commit_reference(orig_head);
890+
commit_list_insert(head, &list);
891+
merge_head = lookup_commit_reference(merge_heads.sha1[0]);
892+
if (is_descendant_of(merge_head, list)) {
893+
/* we can fast-forward this without invoking rebase */
894+
opt_ff = "--ff-only";
895+
return run_merge();
896+
}
884897
return run_rebase(curr_head, *merge_heads.sha1, rebase_fork_point);
885-
} else
898+
} else {
886899
return run_merge();
900+
}
887901
}

0 commit comments

Comments
 (0)