diff options
author | Edward Thomson <ethomson@microsoft.com> | 2014-03-18 16:04:51 -0700 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2014-03-20 09:25:11 -0700 |
commit | ac584fcfd3e15b0a0200ee609bf964414936c710 (patch) | |
tree | 5248a253050c1b65f1de2cd9851e00ca8a0dd1ca /src/merge.c | |
parent | 97f3462ae699fae370cfa410ed58eb869ae6b276 (diff) | |
download | libgit2-ac584fcfd3e15b0a0200ee609bf964414936c710.tar.gz |
Introduce GIT_MERGE_ANALYSIS_UNBORN
Diffstat (limited to 'src/merge.c')
-rw-r--r-- | src/merge.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/merge.c b/src/merge.c index 6b416a3ef..852043cd7 100644 --- a/src/merge.c +++ b/src/merge.c @@ -2524,26 +2524,41 @@ int git_merge_analysis( size_t their_heads_len) { git_merge_head *ancestor_head = NULL, *our_head = NULL; - int error; + int error = 0; assert(out && repo && their_heads); - *out = GIT_MERGE_ANALYSIS_NORMAL; + *out = GIT_MERGE_ANALYSIS_NONE; + + if (git_repository_head_unborn(repo)) { + *out = GIT_MERGE_ANALYSIS_UNBORN; + goto done; + } + + if (their_heads_len != 1) { + giterr_set(GITERR_MERGE, "Can only merge a single branch"); + error = -1; + goto done; + } if ((error = merge_heads(&ancestor_head, &our_head, repo, their_heads, their_heads_len)) < 0) goto done; - if (their_heads_len == 1 && ancestor_head != NULL) { - /* We're up-to-date if we're trying to merge our own common ancestor. */ - if (git_oid_equal(&ancestor_head->oid, &their_heads[0]->oid)) - *out = GIT_MERGE_ANALYSIS_UP_TO_DATE; + /* We're up-to-date if we're trying to merge our own common ancestor. */ + if (ancestor_head && git_oid_equal(&ancestor_head->oid, &their_heads[0]->oid)) + *out = GIT_MERGE_ANALYSIS_UP_TO_DATE; - /* We're fastforwardable if we're our own common ancestor. */ - else if (git_oid_equal(&ancestor_head->oid, &our_head->oid)) - *out = GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL; - } + /* We're fastforwardable if we're our own common ancestor. */ + else if (ancestor_head && git_oid_equal(&ancestor_head->oid, &our_head->oid)) + *out = GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL; + + /* Otherwise, just a normal merge is possible. */ + else + *out = GIT_MERGE_ANALYSIS_NORMAL; done: + git_merge_head_free(ancestor_head); + git_merge_head_free(our_head); return error; } |