diff options
author | Carlos Martín Nieto <carlosmn@github.com> | 2016-05-04 19:05:38 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlosmn@github.com> | 2016-05-04 19:05:38 +0200 |
commit | 2e43a37bcb14d324ab09de4801cb37cf2f31b9bb (patch) | |
tree | 5fe12d7726b03713bcb649f4254d90af972e36f4 /src | |
parent | 4d384d6bbe3efc72fb212a2c5c71c8064a2cee54 (diff) | |
parent | 9a363d1b266d24f3641dc1cc2aa14be54dcfa3cf (diff) | |
download | libgit2-2e43a37bcb14d324ab09de4801cb37cf2f31b9bb.tar.gz |
Merge pull request #3769 from libgit2/ethomson/rebase_inmemory_no_base
Rebase: rebase a branch with no merge base for in-memory
Diffstat (limited to 'src')
-rw-r--r-- | src/rebase.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/rebase.c b/src/rebase.c index 93a91545d..9f3b6ec6e 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -852,6 +852,7 @@ static int rebase_next_inmemory( git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL; git_rebase_operation *operation; git_index *index = NULL; + unsigned int parent_count; int error; *out = NULL; @@ -859,10 +860,20 @@ static int rebase_next_inmemory( operation = git_array_get(rebase->operations, rebase->current); if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 || - (error = git_commit_tree(¤t_tree, current_commit)) < 0 || - (error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 || - (error = git_commit_tree(&parent_tree, parent_commit)) < 0 || - (error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 || + (error = git_commit_tree(¤t_tree, current_commit)) < 0) + goto done; + + if ((parent_count = git_commit_parentcount(current_commit)) > 1) { + giterr_set(GITERR_REBASE, "Cannot rebase a merge commit"); + error = -1; + goto done; + } else if (parent_count) { + if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 || + (error = git_commit_tree(&parent_tree, parent_commit)) < 0) + goto done; + } + + if ((error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 || (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0) goto done; |