diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-01-17 15:11:04 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-01-17 15:11:05 -0800 |
commit | e4ec4089883c9076744561863f9913bdefec06cf (patch) | |
tree | 0da60edb46ca721baef5a128e3450cb6466d5f53 | |
parent | 07ec05d9e6f54874c6a439fea35ec70ffa05c1a0 (diff) | |
parent | 33b842a1e9bf28bcffe953ad9dcdbb0561336314 (diff) | |
download | git-e4ec4089883c9076744561863f9913bdefec06cf.tar.gz |
Merge branch 'jc/pull-rebase-ff' into maint
"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"
-rw-r--r-- | builtin/pull.c | 22 | ||||
-rwxr-xr-x | t/t5520-pull.sh | 17 |
2 files changed, 35 insertions, 4 deletions
diff --git a/builtin/pull.c b/builtin/pull.c index d6e46ee6d0..3ecb881b0b 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -857,10 +857,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(); + } } diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 551844584f..17f4d0fe4e 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -255,6 +255,23 @@ test_expect_success '--rebase' ' test new = "$(git show HEAD:file2)" ' +test_expect_success '--rebase fast forward' ' + git reset --hard before-rebase && + git checkout -b ff && + echo another modification >file && + git commit -m third file && + + git checkout to-rebase && + git pull --rebase . ff && + test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" && + + # The above only validates the result. Did we actually bypass rebase? + git reflog -1 >reflog.actual && + sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && + echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && + test_cmp reflog.expected reflog.fuzzy +' + test_expect_success '--rebase with conflicts shows advice' ' test_when_finished "git rebase --abort; git checkout -f to-rebase" && git checkout -b seq && |