Skip to content

Commit c9a5d01

Browse files
angusbjonesjamill
authored andcommitted
MergeFixture: Added in recommended asserts
MergeResult: Fixed up bad reference + added FastForwardOid prop Repository: Wrapped MergeHead and MergeResult handles in usings.
1 parent 1803553 commit c9a5d01

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,25 @@ public void CanMergeRepos()
8989
{
9090
var firstBranch = repo.CreateBranch("FirstBranch");
9191
firstBranch.Checkout();
92-
AddFileCommitToRepo(repo, "first+second branch file");
92+
var originalTreeCount = firstBranch.Tip.Tree.Count;
9393

94+
//Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
95+
AddFileCommitToRepo(repo, "first+second branch file");
96+
9497
var secondBranch = repo.CreateBranch("SecondBranch");
95-
AddFileCommitToRepo(repo, "first branch file");
98+
//Commit with ONE new file to first branch (FirstBranch moves forward as it is checked out, SecondBranch stays back one).
99+
var firstBranchCommit = AddFileCommitToRepo(repo, "first branch file");
100+
96101
secondBranch.Checkout();
97-
AddFileCommitToRepo(repo, "second branch file");
102+
//Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit).
103+
var secondBranchCommit = AddFileCommitToRepo(repo, "second branch file");
104+
105+
MergeResult mergeResult = repo.Merge(repo.Branches["FirstBranch"].Tip);
98106

99-
repo.Merge(repo.Branches["FirstBranch"].Tip);
107+
var mergeCommit = repo.Commit("Merge First+Second");
100108

101-
repo.Commit("Merge First+Second");
109+
Assert.Equal(mergeCommit.Tree.Count, originalTreeCount + 3); //Expecting original tree count plussed by the 3 added files.
110+
Assert.Equal(mergeCommit.Parents.Count(), 2); //Merge commit should have 2 parents
102111
}
103112
}
104113

LibGit2Sharp/MergeResult.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ public MergeResult(){}
1010
internal MergeResult(GitMergeResultHandle handle)
1111
{
1212
_isUpToDate = Proxy.git_merge_result_is_uptodate(handle);
13-
_isUpToDate = Proxy.git_merge_result_is_fastforward(handle);
13+
_isFastForward = Proxy.git_merge_result_is_fastforward(handle);
14+
15+
if (_isFastForward)
16+
_oid = Proxy.git_merge_result_fastforward_oid(handle);
1417
}
1518

1619
private bool _isUpToDate;
@@ -24,5 +27,11 @@ public virtual bool IsFastForward
2427
{
2528
get { return _isFastForward; }
2629
}
30+
31+
private readonly GitOid _oid;
32+
internal GitOid FastForwardOid
33+
{
34+
get { return _oid; }
35+
}
2736
}
2837
}

LibGit2Sharp/Repository.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,15 +1037,19 @@ public IEnumerable<MergeHead> MergeHeads
10371037
/// </summary>
10381038
public MergeResult Merge(Commit commit)
10391039
{
1040-
var mergeHeadHandle = Proxy.git_merge_head_from_oid(Handle, commit.Id.Oid);
1041-
1042-
GitMergeOpts opts = new GitMergeOpts()
1040+
using (GitMergeHeadHandle mergeHeadHandle = Proxy.git_merge_head_from_oid(Handle, commit.Id.Oid))
10431041
{
1044-
Version = 1,
1045-
MergeTreeOpts = { Version = 1 },
1046-
CheckoutOpts = { version = 1 }
1047-
};
1048-
return new MergeResult(Proxy.git_merge(Handle, new GitMergeHeadHandle[] { mergeHeadHandle }, opts));
1042+
GitMergeOpts opts = new GitMergeOpts()
1043+
{
1044+
Version = 1,
1045+
MergeTreeOpts = { Version = 1 },
1046+
CheckoutOpts = { version = 1 }
1047+
};
1048+
using (GitMergeResultHandle mergeResultHandle = Proxy.git_merge(Handle, new GitMergeHeadHandle[] { mergeHeadHandle }, opts))
1049+
{
1050+
return new MergeResult(mergeResultHandle);
1051+
}
1052+
}
10491053
}
10501054

10511055
internal StringComparer PathComparer

0 commit comments

Comments
 (0)