Skip to content

Commit

Permalink
Update to libgit2 a27f31d8
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmn committed Dec 10, 2015
1 parent f8c944b commit 575df91
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 26 deletions.
17 changes: 17 additions & 0 deletions LibGit2Sharp.Tests/MergeFixture.cs
Expand Up @@ -295,6 +295,23 @@ public void ConflictingMergeReposBinary()
}
}

[Fact]
public void CanFailOnFirstMergeConflict()
{
string path = SandboxMergeTestRepo();
using (var repo = new Repository(path))
{
var master = repo.Lookup<Commit>("master");
var branch = repo.Lookup<Commit>("conflicts");

Assert.Throws<ConflictInMergeException>(() =>
{
repo.Merge("conflicts", Constants.Signature, new MergeOptions() { FailOnConflict = true, });
});
}

}

[Theory]
[InlineData(true, FastForwardStrategy.Default, fastForwardBranchInitialId, MergeStatus.FastForward)]
[InlineData(true, FastForwardStrategy.FastForwardOnly, fastForwardBranchInitialId, MergeStatus.FastForward)]
Expand Down
59 changes: 59 additions & 0 deletions LibGit2Sharp/ConflictInMergeException.cs
@@ -0,0 +1,59 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown when a merge cannot be performed due to
/// a conflict and the caller requested to stop at the first conflict.
/// </summary>
[Serializable]
public class ConflictInMergeException : LibGit2SharpException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class.
/// </summary>
public ConflictInMergeException()
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a specified error message.
/// </summary>
/// <param name="message">A message that describes the error.</param>
public ConflictInMergeException(string message)
: base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a specified error message.
/// </summary>
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public ConflictInMergeException(string format, params object[] args)
: base(format, args)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.</param>
public ConflictInMergeException(string message, Exception innerException)
: base(message, innerException)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a serialized data.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected ConflictInMergeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }

internal ConflictInMergeException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
{ }
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/Core/Ensure.cs
Expand Up @@ -125,6 +125,7 @@ public static void ArgumentIsExpectedIntPtr(IntPtr argumentValue, IntPtr expecte
{ GitErrorCode.UnmergedEntries, (m, r, c) => new UnmergedIndexEntriesException(m, r, c) },
{ GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) },
{ GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) },
{ GitErrorCode.MergeConflict, (m ,r, c) => new ConflictInMergeException(m, r, c) },
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
{ GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) },
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },
Expand Down
9 changes: 8 additions & 1 deletion LibGit2Sharp/Core/GitDiff.cs
Expand Up @@ -197,6 +197,12 @@ internal enum GitDiffOptionFlags
IntPtr matched_pathspec,
IntPtr payload);

internal delegate int diff_progress_cb(
IntPtr diff_so_far,
IntPtr old_path,
IntPtr new_path,
IntPtr payload);

[StructLayout(LayoutKind.Sequential)]
internal class GitDiffOptions : IDisposable
{
Expand All @@ -208,7 +214,8 @@ internal class GitDiffOptions : IDisposable
public SubmoduleIgnore IgnoreSubmodules;
public GitStrArrayManaged PathSpec;
public diff_notify_cb NotifyCallback;
public IntPtr NotifyPayload;
public diff_progress_cb ProgressCallback;
public IntPtr Payload;

/* options controlling how to diff text is generated */

Expand Down
35 changes: 28 additions & 7 deletions LibGit2Sharp/Core/GitMergeOpts.cs
Expand Up @@ -8,7 +8,7 @@ internal struct GitMergeOpts
{
public uint Version;

public GitMergeTreeFlags MergeTreeFlags;
public GitMergeFlag MergeTreeFlags;

/// <summary>
/// Similarity to consider a file renamed.
Expand All @@ -27,6 +27,14 @@ internal struct GitMergeOpts
/// </summary>
public IntPtr SimilarityMetric;

/// <summary>
/// Maximum number of times to merge common ancestors to build a
/// virtual merge base when faced with criss-cross merges. When this
/// limit is reached, the next ancestor will simply be used instead of
/// attempting to merge it. The default is unlimited.
/// </summary>
public uint RecursionLimit;

/// <summary>
/// Flags for automerging content.
/// </summary>
Expand All @@ -35,7 +43,7 @@ internal struct GitMergeOpts
/// <summary>
/// File merging flags.
/// </summary>
public GitMergeFileFlags FileFlags;
public GitMergeFileFlag FileFlags;
}

/// <summary>
Expand Down Expand Up @@ -98,30 +106,43 @@ internal enum GitMergePreference
}

[Flags]
internal enum GitMergeTreeFlags
internal enum GitMergeFlag
{
/// <summary>
/// No options.
/// </summary>
GIT_MERGE_TREE_NORMAL = 0,
GIT_MERGE_NORMAL = 0,

/// <summary>
/// Detect renames that occur between the common ancestor and the "ours"
/// side or the common ancestor and the "theirs" side. This will enable
/// the ability to merge between a modified and renamed file.
/// </summary>
GIT_MERGE_TREE_FIND_RENAMES = (1 << 0),
GIT_MERGE_FIND_RENAMES = (1 << 0),

/// <summary>
/// If a conflict occurs, exit immediately instead of attempting to
/// continue resolving conflicts. The merge operation will fail with
/// GIT_EMERGECONFLICT and no index will be returned.
///</summary>
GIT_MERGE_TREE_FAIL_ON_CONFLICT = (1 << 1),
GIT_MERGE_FAIL_ON_CONFLICT = (1 << 1),

/// <summary>
/// Do not write the REUC extension on the generated index
/// </summary>
GIT_MERGE_SKIP_REUC = (1 << 2),

/// <summary>
/// If the commits being merged have multiple merge bases, do not build
/// a recursive merge base (by merging the multiple merge bases),
/// instead simply use the first base. This flag provides a similar
/// merge base to `git-merge-resolve`.
/// </summary>
GIT_MERGE_NO_RECURSIVE = (1 << 3),
}

[Flags]
internal enum GitMergeFileFlags
internal enum GitMergeFileFlag
{
/// <summary>
/// Defaults
Expand Down
24 changes: 17 additions & 7 deletions LibGit2Sharp/CurrentOperation.cs
Expand Up @@ -21,39 +21,49 @@ public enum CurrentOperation
/// </summary>
Revert = 2,

/// <summary>
/// A sequencer revert is in progress.
/// </summary>
RevertSequence = 3,

/// <summary>
/// A cherry-pick is in progress.
/// </summary>
CherryPick = 3,
CherryPick = 4,

/// <summary>
/// A sequencer cherry-pick is in progress.
/// </summary>
CherryPickSequence = 5,

/// <summary>
/// A bisect is in progress.
/// </summary>
Bisect = 4,
Bisect = 6,

/// <summary>
/// A rebase is in progress.
/// </summary>
Rebase = 5,
Rebase = 7,

/// <summary>
/// A rebase --interactive is in progress.
/// </summary>
RebaseInteractive = 6,
RebaseInteractive = 8,

/// <summary>
/// A rebase --merge is in progress.
/// </summary>
RebaseMerge = 7,
RebaseMerge = 9,

/// <summary>
/// A mailbox application (am) is in progress.
/// </summary>
ApplyMailbox = 8,
ApplyMailbox = 10,

/// <summary>
/// A mailbox application (am) or rebase is in progress.
/// </summary>
ApplyMailboxOrRebase = 9,
ApplyMailboxOrRebase = 11,
}
}
5 changes: 3 additions & 2 deletions LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props')" />
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.114\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.114\build\LibGit2Sharp.NativeBinaries.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -69,6 +69,7 @@
<Compile Include="CommitOptions.cs" />
<Compile Include="CommitSortStrategies.cs" />
<Compile Include="CompareOptions.cs" />
<Compile Include="ConflictInMergeException.cs" />
<Compile Include="Core\FileHistory.cs" />
<Compile Include="Core\GitFetchOptions.cs" />
<Compile Include="Core\GitPushUpdate.cs" />
Expand Down Expand Up @@ -405,7 +406,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props'))" />
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.114\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.114\build\LibGit2Sharp.NativeBinaries.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
14 changes: 14 additions & 0 deletions LibGit2Sharp/MergeOptionsBase.cs
Expand Up @@ -22,6 +22,20 @@ protected MergeOptionsBase()
/// </summary>
public bool FindRenames { get; set; }

/// <summary>
/// If set, do not create conflict entries but fail the operation. No
/// merged index will be created and a <see cref="LibGit2Sharp.ConflictInMergeException"/>
/// exception will be thrown.
/// </summary>
public bool FailOnConflict { get; set; }

/// <summary>
/// Do not write the Resolve Undo Cache extension on the generated index. This can
/// be useful when no merge resolution will be presented to the user (e.g. a server-side
/// merge attempt).
/// </summary>
public bool SkipReuc { get; set; }

/// <summary>
/// Similarity to consider a file renamed.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/ObjectDatabase.cs
Expand Up @@ -607,8 +607,8 @@ public virtual MergeTreeResult MergeCommits(Commit ours, Commit theirs, MergeTre
{
Version = 1,
MergeFileFavorFlags = options.MergeFileFavor,
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES
: GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
MergeTreeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES
: GitMergeFlag.GIT_MERGE_NORMAL,
RenameThreshold = (uint)options.RenameThreshold,
TargetLimit = (uint)options.TargetLimit,
};
Expand Down
24 changes: 18 additions & 6 deletions LibGit2Sharp/Repository.cs
Expand Up @@ -1329,8 +1329,8 @@ public RevertResult Revert(Commit commit, Signature reverter, RevertOptions opti
{
Version = 1,
MergeFileFavorFlags = options.MergeFileFavor,
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES :
GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
MergeTreeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES :
GitMergeFlag.GIT_MERGE_NORMAL,
RenameThreshold = (uint)options.RenameThreshold,
TargetLimit = (uint)options.TargetLimit,
};
Expand Down Expand Up @@ -1413,8 +1413,8 @@ public CherryPickResult CherryPick(Commit commit, Signature committer, CherryPic
{
Version = 1,
MergeFileFavorFlags = options.MergeFileFavor,
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES :
GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
MergeTreeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES :
GitMergeFlag.GIT_MERGE_NORMAL,
RenameThreshold = (uint)options.RenameThreshold,
TargetLimit = (uint)options.TargetLimit,
};
Expand Down Expand Up @@ -1553,12 +1553,24 @@ private MergeResult Merge(GitAnnotatedCommitHandle[] annotatedCommits, Signature
private MergeResult NormalMerge(GitAnnotatedCommitHandle[] annotatedCommits, Signature merger, MergeOptions options)
{
MergeResult mergeResult;
GitMergeFlag treeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES
: GitMergeFlag.GIT_MERGE_NORMAL;

if (options.FailOnConflict)
{
treeFlags |= GitMergeFlag.GIT_MERGE_FAIL_ON_CONFLICT;
}

if (options.SkipReuc)
{
treeFlags |= GitMergeFlag.GIT_MERGE_SKIP_REUC;
}

var mergeOptions = new GitMergeOpts
{
Version = 1,
MergeFileFavorFlags = options.MergeFileFavor,
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES
: GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
MergeTreeFlags = treeFlags,
RenameThreshold = (uint)options.RenameThreshold,
TargetLimit = (uint)options.TargetLimit,
};
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LibGit2Sharp.NativeBinaries" version="1.0.106" targetFramework="net4" allowedVersions="[1.0.106]" />
<package id="LibGit2Sharp.NativeBinaries" version="1.0.114" targetFramework="net4" allowedVersions="[1.0.114]" />
</packages>

0 comments on commit 575df91

Please sign in to comment.