summaryrefslogtreecommitdiff
path: root/builtin/pull.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-06-29 17:22:31 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-11-29 22:40:16 (GMT)
commit33b842a1e9bf28bcffe953ad9dcdbb0561336314 (patch)
treea0cac789037bd45e18d7a875918f7692af88b211 /builtin/pull.c
parente46579643d56162299b1756b70d418005351b256 (diff)
downloadgit-33b842a1e9bf28bcffe953ad9dcdbb0561336314.zip
git-33b842a1e9bf28bcffe953ad9dcdbb0561336314.tar.gz
git-33b842a1e9bf28bcffe953ad9dcdbb0561336314.tar.bz2
pull: fast-forward "pull --rebase=true"
"git pull --rebase" always runs "git rebase" after fetching the commit to serve as the new base, even when the new base is a descendant of the current HEAD, i.e. we haven't done any work. In such a case, we can instead fast-forward to the new base without invoking the rebase process. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/pull.c')
-rw-r--r--builtin/pull.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/builtin/pull.c b/builtin/pull.c
index bf3fd3f..2a41d41 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -878,10 +878,24 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (merge_heads.nr > 1)
die(_("Cannot merge multiple branches into empty head."));
return pull_into_void(*merge_heads.sha1, curr_head);
- } else if (opt_rebase) {
- if (merge_heads.nr > 1)
- die(_("Cannot rebase onto multiple branches."));
+ }
+ if (opt_rebase && merge_heads.nr > 1)
+ die(_("Cannot rebase onto multiple branches."));
+
+ if (opt_rebase) {
+ struct commit_list *list = NULL;
+ struct commit *merge_head, *head;
+
+ head = lookup_commit_reference(orig_head);
+ commit_list_insert(head, &list);
+ merge_head = lookup_commit_reference(merge_heads.sha1[0]);
+ if (is_descendant_of(merge_head, list)) {
+ /* we can fast-forward this without invoking rebase */
+ opt_ff = "--ff-only";
+ return run_merge();
+ }
return run_rebase(curr_head, *merge_heads.sha1, rebase_fork_point);
- } else
+ } else {
return run_merge();
+ }
}