diff options
author | Edward Thomson <ethomson@microsoft.com> | 2013-01-09 21:29:37 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-01-29 02:08:39 +0400 |
commit | 258fa7e3412f63e1c620850943f8705128c491ae (patch) | |
tree | 0070d908c4b22f7123a36ddc6823f99d7e1a5f3f | |
parent | 742f5b831469932a2c3af645d3d8d8c0f506950e (diff) |
Teach Repository.Commit() to add merged branches as parents
-rw-r--r-- | LibGit2Sharp.Tests/CommitFixture.cs | 23 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 9 |
2 files changed, 30 insertions, 2 deletions
diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs index ef101176..1a20ab04 100644 --- a/LibGit2Sharp.Tests/CommitFixture.cs +++ b/LibGit2Sharp.Tests/CommitFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -528,6 +528,27 @@ namespace LibGit2Sharp.Tests } [Fact] + public void CommitParentsAreMergeHeads() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath); + using (var repo = new Repository(path.RepositoryPath)) + { + repo.Reset(ResetOptions.Hard, "c47800"); + + CreateAndStageANewFile(repo); + + string mergeHeadPath = Path.Combine(repo.Info.Path, "MERGE_HEAD"); + File.WriteAllText(mergeHeadPath, "9fd738e8f7967c078dceed8190330fc8648ee56a\n"); + + Commit newMergedCommit = repo.Commit("Merge commit", DummySignature, DummySignature, false); + + Assert.Equal(2, newMergedCommit.Parents.Count()); + Assert.Equal(newMergedCommit.Parents.First().Sha, "c47800c7266a2be04c571c04d5a6614691ea99bd"); + Assert.Equal(newMergedCommit.Parents.Skip(1).First().Sha, "9fd738e8f7967c078dceed8190330fc8648ee56a"); + } + } + + [Fact] public void CommitCleansUpMergeMetadata() { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 65196e78..1f4885a5 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -648,7 +648,14 @@ namespace LibGit2Sharp return Enumerable.Empty<Commit>(); } - return new[] { Head.Tip }; + var parents = new List<Commit> { Head.Tip }; + + if (Info.CurrentOperation == CurrentOperation.Merge) + { + parents.AddRange(MergeHeads.Select(mh => mh.Tip)); + } + + return parents; } /// <summary> |