Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions LibGit2Sharp.Tests/MergeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,32 @@ public void CanMergeCommittish(string committish, FastForwardStrategy strategy,
}
}

[Theory]
[InlineData(true, FastForwardStrategy.FastForwardOnly)]
[InlineData(false, FastForwardStrategy.FastForwardOnly)]
[InlineData(true, FastForwardStrategy.NoFastFoward)]
[InlineData(false, FastForwardStrategy.NoFastFoward)]
public void MergeWithWorkDirConflictsThrows(bool shouldStage, FastForwardStrategy strategy)
{
// Merging the fast_forward branch results in a change to file
// b.txt. In this test we modify the file in the working directory
// and then attempt to perform a merge. We expect the merge to fail
// due to merge conflicts.
string committishToMerge = "fast_forward";

using (var repo = new Repository(CloneMergeTestRepo()))
{
Touch(repo.Info.WorkingDirectory, "b.txt", "this is an alternate change");

if (shouldStage)
{
repo.Index.Stage("b.txt");
}

Assert.Throws<MergeConflictException>(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy }));
}
}

[Theory]
[InlineData(CheckoutFileConflictStrategy.Ours)]
[InlineData(CheckoutFileConflictStrategy.Theirs)]
Expand Down
1 change: 0 additions & 1 deletion LibGit2Sharp/CherryPickOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
get
{
return CheckoutStrategy.GIT_CHECKOUT_SAFE |
CheckoutStrategy.GIT_CHECKOUT_ALLOW_CONFLICTS |
GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy);
}
}
Expand Down
46 changes: 46 additions & 0 deletions LibGit2Sharp/Core/GitCheckoutOpts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,50 @@ internal interface IConvertableToGitCheckoutOpts

CheckoutNotifyFlags CheckoutNotifyFlags { get; }
}

/// <summary>
/// This wraps an IConvertableToGitCheckoutOpts object and can tweak the
/// properties so that they are appropriate for a checkout performed as
/// part of a FastForward merge. Most properties are passthrough to the
/// wrapped object.
/// </summary>
internal class FastForwardCheckoutOptionsAdapter : IConvertableToGitCheckoutOpts
{
private IConvertableToGitCheckoutOpts internalOptions;

internal FastForwardCheckoutOptionsAdapter(IConvertableToGitCheckoutOpts internalOptions)
{
this.internalOptions = internalOptions;
}

/// <summary>
/// Passthrough to the wrapped object.
/// </summary>
/// <returns></returns>
public CheckoutCallbacks GenerateCallbacks()
{
return internalOptions.GenerateCallbacks();
}

/// <summary>
/// There should be no resolvable conflicts in a FastForward merge.
/// Just perform checkout with the safe checkout strategy.
/// </summary>
public CheckoutStrategy CheckoutStrategy
{
get
{
return CheckoutStrategy.GIT_CHECKOUT_SAFE;
}
}

/// <summary>
/// Passthrough to the wrapped object.
/// </summary>
/// <returns></returns>
public CheckoutNotifyFlags CheckoutNotifyFlags
{
get { return internalOptions.CheckoutNotifyFlags; }
}
}
}
3 changes: 1 addition & 2 deletions LibGit2Sharp/MergeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
{
get
{
return CheckoutStrategy.GIT_CHECKOUT_SAFE|
CheckoutStrategy.GIT_CHECKOUT_ALLOW_CONFLICTS |
return CheckoutStrategy.GIT_CHECKOUT_SAFE |
GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy);
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ private MergeResult FastForwardMerge(GitMergeHeadHandle mergeHead, Signature mer
Commit fastForwardCommit = (Commit) Lookup(id, ObjectType.Commit);
Ensure.GitObjectIsNotNull(fastForwardCommit, id.Sha);

CheckoutTree(fastForwardCommit.Tree, null, options);
CheckoutTree(fastForwardCommit.Tree, null, new FastForwardCheckoutOptionsAdapter(options));

var reference = Refs.Head.ResolveToDirectReference();

Expand Down
1 change: 0 additions & 1 deletion LibGit2Sharp/RevertOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
get
{
return CheckoutStrategy.GIT_CHECKOUT_SAFE |
CheckoutStrategy.GIT_CHECKOUT_ALLOW_CONFLICTS |
GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy);
}
}
Expand Down