-
Notifications
You must be signed in to change notification settings - Fork 899
Fix for FastForward detach issue + test. #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq; | ||
using LibGit2Sharp.Tests.TestHelpers; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace LibGit2Sharp.Tests | ||
{ | ||
|
@@ -81,9 +81,11 @@ public void CanRetrieveTheBranchBeingMerged() | |
Assert.Null(mergedHeads[1].Tip); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void CanMergeRepoNonFastForward() | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void CanMergeRepoNonFastForward(bool shouldMergeOccurInDetachedHeadState) | ||
{ | ||
const string firstBranchFileName = "first branch file.txt"; | ||
const string secondBranchFileName = "second branch file.txt"; | ||
|
@@ -104,7 +106,13 @@ public void CanMergeRepoNonFastForward() | |
// Commit with ONE new file to first branch (FirstBranch moves forward as it is checked out, SecondBranch stays back one). | ||
AddFileCommitToRepo(repo, firstBranchFileName); | ||
|
||
secondBranch.Checkout(); | ||
if (shouldMergeOccurInDetachedHeadState) | ||
{ | ||
// Detaches HEAD | ||
repo.Checkout(secondBranch.Tip); | ||
} | ||
else | ||
secondBranch.Checkout(); | ||
|
||
// Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit). | ||
AddFileCommitToRepo(repo, secondBranchFileName); | ||
|
@@ -116,6 +124,13 @@ public void CanMergeRepoNonFastForward() | |
Assert.Equal(repo.Head.Tip, mergeResult.Commit); | ||
Assert.Equal(originalTreeCount + 3, mergeResult.Commit.Tree.Count); // Expecting original tree count plussed by the 3 added files. | ||
Assert.Equal(2, mergeResult.Commit.Parents.Count()); // Merge commit should have 2 parents | ||
Assert.Equal(shouldMergeOccurInDetachedHeadState, repo.Info.IsHeadDetached); | ||
|
||
if (!shouldMergeOccurInDetachedHeadState) | ||
{ | ||
// Ensure HEAD is still attached and points to SecondBranch | ||
Assert.Equal(repo.Refs.Head.TargetIdentifier, secondBranch.CanonicalName); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -143,8 +158,10 @@ public void IsUpToDateMerge() | |
} | ||
} | ||
|
||
[Fact] | ||
public void CanFastForwardRepos() | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void CanFastForwardRepos(bool shouldMergeOccurInDetachedHeadState) | ||
{ | ||
const string firstBranchFileName = "first branch file.txt"; | ||
const string sharedBranchFileName = "first+second branch file.txt"; | ||
|
@@ -169,14 +186,29 @@ public void CanFastForwardRepos() | |
// Commit with ONE new file to first branch (FirstBranch moves forward as it is checked out, SecondBranch stays back one). | ||
AddFileCommitToRepo(repo, firstBranchFileName); | ||
|
||
secondBranch.Checkout(); | ||
if (shouldMergeOccurInDetachedHeadState) | ||
{ | ||
// Detaches HEAD | ||
repo.Checkout(secondBranch.Tip); | ||
} | ||
else | ||
secondBranch.Checkout(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Assert.Equal(shouldMergeOccurInDetachedHeadState, repo.Info.IsHeadDetached); | ||
|
||
MergeResult mergeResult = repo.Merge(repo.Branches["FirstBranch"].Tip, Constants.Signature); | ||
|
||
Assert.Equal(MergeStatus.FastForward, mergeResult.Status); | ||
Assert.Equal(repo.Branches["FirstBranch"].Tip, mergeResult.Commit); | ||
Assert.Equal(repo.Branches["FirstBranch"].Tip, repo.Head.Tip); | ||
Assert.Equal(repo.Head.Tip, mergeResult.Commit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it still makes sense to verify that the current HEAD commit ID matches the expected FastForward Commit ID. We expect the current Head commit ID to now be equal to the tip commit on "FirstBranch". I don't think the original test conditions here were wrong, they were just not sufficient to verify that the HEAD was detached. |
||
|
||
Assert.Equal(0, repo.Index.RetrieveStatus().Count()); | ||
Assert.Equal(shouldMergeOccurInDetachedHeadState, repo.Info.IsHeadDetached); | ||
|
||
if (!shouldMergeOccurInDetachedHeadState) | ||
{ | ||
// Ensure HEAD is still attached and points to SecondBranch | ||
Assert.Equal(repo.Refs.Head.TargetIdentifier, secondBranch.CanonicalName); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ }
around the else statement?