Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 575df91

Browse files
committed
Update to libgit2 a27f31d8
1 parent f8c944b commit 575df91

11 files changed

+168
-26
lines changed

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ public void ConflictingMergeReposBinary()
295295
}
296296
}
297297

298+
[Fact]
299+
public void CanFailOnFirstMergeConflict()
300+
{
301+
string path = SandboxMergeTestRepo();
302+
using (var repo = new Repository(path))
303+
{
304+
var master = repo.Lookup<Commit>("master");
305+
var branch = repo.Lookup<Commit>("conflicts");
306+
307+
Assert.Throws<ConflictInMergeException>(() =>
308+
{
309+
repo.Merge("conflicts", Constants.Signature, new MergeOptions() { FailOnConflict = true, });
310+
});
311+
}
312+
313+
}
314+
298315
[Theory]
299316
[InlineData(true, FastForwardStrategy.Default, fastForwardBranchInitialId, MergeStatus.FastForward)]
300317
[InlineData(true, FastForwardStrategy.FastForwardOnly, fastForwardBranchInitialId, MergeStatus.FastForward)]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using LibGit2Sharp.Core;
4+
5+
namespace LibGit2Sharp
6+
{
7+
/// <summary>
8+
/// The exception that is thrown when a merge cannot be performed due to
9+
/// a conflict and the caller requested to stop at the first conflict.
10+
/// </summary>
11+
[Serializable]
12+
public class ConflictInMergeException : LibGit2SharpException
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class.
16+
/// </summary>
17+
public ConflictInMergeException()
18+
{ }
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a specified error message.
22+
/// </summary>
23+
/// <param name="message">A message that describes the error.</param>
24+
public ConflictInMergeException(string message)
25+
: base(message)
26+
{ }
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a specified error message.
30+
/// </summary>
31+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
32+
/// <param name="args">An object array that contains zero or more objects to format.</param>
33+
public ConflictInMergeException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
37+
/// <summary>
38+
/// 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.
39+
/// </summary>
40+
/// <param name="message">The error message that explains the reason for the exception.</param>
41+
/// <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>
42+
public ConflictInMergeException(string message, Exception innerException)
43+
: base(message, innerException)
44+
{ }
45+
46+
/// <summary>
47+
/// Initializes a new instance of the <see cref="LibGit2Sharp.ConflictInMergeException"/> class with a serialized data.
48+
/// </summary>
49+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
50+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
51+
protected ConflictInMergeException(SerializationInfo info, StreamingContext context)
52+
: base(info, context)
53+
{ }
54+
55+
internal ConflictInMergeException(string message, GitErrorCode code, GitErrorCategory category)
56+
: base(message, code, category)
57+
{ }
58+
}
59+
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitE
125125
{ GitErrorCode.UnmergedEntries, (m, r, c) => new UnmergedIndexEntriesException(m, r, c) },
126126
{ GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) },
127127
{ GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) },
128+
{ GitErrorCode.MergeConflict, (m ,r, c) => new ConflictInMergeException(m, r, c) },
128129
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
129130
{ GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) },
130131
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },

LibGit2Sharp/Core/GitDiff.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ internal delegate int diff_notify_cb(
197197
IntPtr matched_pathspec,
198198
IntPtr payload);
199199

200+
internal delegate int diff_progress_cb(
201+
IntPtr diff_so_far,
202+
IntPtr old_path,
203+
IntPtr new_path,
204+
IntPtr payload);
205+
200206
[StructLayout(LayoutKind.Sequential)]
201207
internal class GitDiffOptions : IDisposable
202208
{
@@ -208,7 +214,8 @@ internal class GitDiffOptions : IDisposable
208214
public SubmoduleIgnore IgnoreSubmodules;
209215
public GitStrArrayManaged PathSpec;
210216
public diff_notify_cb NotifyCallback;
211-
public IntPtr NotifyPayload;
217+
public diff_progress_cb ProgressCallback;
218+
public IntPtr Payload;
212219

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

LibGit2Sharp/Core/GitMergeOpts.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal struct GitMergeOpts
88
{
99
public uint Version;
1010

11-
public GitMergeTreeFlags MergeTreeFlags;
11+
public GitMergeFlag MergeTreeFlags;
1212

1313
/// <summary>
1414
/// Similarity to consider a file renamed.
@@ -27,6 +27,14 @@ internal struct GitMergeOpts
2727
/// </summary>
2828
public IntPtr SimilarityMetric;
2929

30+
/// <summary>
31+
/// Maximum number of times to merge common ancestors to build a
32+
/// virtual merge base when faced with criss-cross merges. When this
33+
/// limit is reached, the next ancestor will simply be used instead of
34+
/// attempting to merge it. The default is unlimited.
35+
/// </summary>
36+
public uint RecursionLimit;
37+
3038
/// <summary>
3139
/// Flags for automerging content.
3240
/// </summary>
@@ -35,7 +43,7 @@ internal struct GitMergeOpts
3543
/// <summary>
3644
/// File merging flags.
3745
/// </summary>
38-
public GitMergeFileFlags FileFlags;
46+
public GitMergeFileFlag FileFlags;
3947
}
4048

4149
/// <summary>
@@ -98,30 +106,43 @@ internal enum GitMergePreference
98106
}
99107

100108
[Flags]
101-
internal enum GitMergeTreeFlags
109+
internal enum GitMergeFlag
102110
{
103111
/// <summary>
104112
/// No options.
105113
/// </summary>
106-
GIT_MERGE_TREE_NORMAL = 0,
114+
GIT_MERGE_NORMAL = 0,
107115

108116
/// <summary>
109117
/// Detect renames that occur between the common ancestor and the "ours"
110118
/// side or the common ancestor and the "theirs" side. This will enable
111119
/// the ability to merge between a modified and renamed file.
112120
/// </summary>
113-
GIT_MERGE_TREE_FIND_RENAMES = (1 << 0),
121+
GIT_MERGE_FIND_RENAMES = (1 << 0),
114122

115123
/// <summary>
116124
/// If a conflict occurs, exit immediately instead of attempting to
117125
/// continue resolving conflicts. The merge operation will fail with
118126
/// GIT_EMERGECONFLICT and no index will be returned.
119127
///</summary>
120-
GIT_MERGE_TREE_FAIL_ON_CONFLICT = (1 << 1),
128+
GIT_MERGE_FAIL_ON_CONFLICT = (1 << 1),
129+
130+
/// <summary>
131+
/// Do not write the REUC extension on the generated index
132+
/// </summary>
133+
GIT_MERGE_SKIP_REUC = (1 << 2),
134+
135+
/// <summary>
136+
/// If the commits being merged have multiple merge bases, do not build
137+
/// a recursive merge base (by merging the multiple merge bases),
138+
/// instead simply use the first base. This flag provides a similar
139+
/// merge base to `git-merge-resolve`.
140+
/// </summary>
141+
GIT_MERGE_NO_RECURSIVE = (1 << 3),
121142
}
122143

123144
[Flags]
124-
internal enum GitMergeFileFlags
145+
internal enum GitMergeFileFlag
125146
{
126147
/// <summary>
127148
/// Defaults

LibGit2Sharp/CurrentOperation.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,49 @@ public enum CurrentOperation
2121
/// </summary>
2222
Revert = 2,
2323

24+
/// <summary>
25+
/// A sequencer revert is in progress.
26+
/// </summary>
27+
RevertSequence = 3,
28+
2429
/// <summary>
2530
/// A cherry-pick is in progress.
2631
/// </summary>
27-
CherryPick = 3,
32+
CherryPick = 4,
33+
34+
/// <summary>
35+
/// A sequencer cherry-pick is in progress.
36+
/// </summary>
37+
CherryPickSequence = 5,
2838

2939
/// <summary>
3040
/// A bisect is in progress.
3141
/// </summary>
32-
Bisect = 4,
42+
Bisect = 6,
3343

3444
/// <summary>
3545
/// A rebase is in progress.
3646
/// </summary>
37-
Rebase = 5,
47+
Rebase = 7,
3848

3949
/// <summary>
4050
/// A rebase --interactive is in progress.
4151
/// </summary>
42-
RebaseInteractive = 6,
52+
RebaseInteractive = 8,
4353

4454
/// <summary>
4555
/// A rebase --merge is in progress.
4656
/// </summary>
47-
RebaseMerge = 7,
57+
RebaseMerge = 9,
4858

4959
/// <summary>
5060
/// A mailbox application (am) is in progress.
5161
/// </summary>
52-
ApplyMailbox = 8,
62+
ApplyMailbox = 10,
5363

5464
/// <summary>
5565
/// A mailbox application (am) or rebase is in progress.
5666
/// </summary>
57-
ApplyMailboxOrRebase = 9,
67+
ApplyMailboxOrRebase = 11,
5868
}
5969
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props')" />
3+
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.114\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.114\build\LibGit2Sharp.NativeBinaries.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -69,6 +69,7 @@
6969
<Compile Include="CommitOptions.cs" />
7070
<Compile Include="CommitSortStrategies.cs" />
7171
<Compile Include="CompareOptions.cs" />
72+
<Compile Include="ConflictInMergeException.cs" />
7273
<Compile Include="Core\FileHistory.cs" />
7374
<Compile Include="Core\GitFetchOptions.cs" />
7475
<Compile Include="Core\GitPushUpdate.cs" />
@@ -405,7 +406,7 @@
405406
<PropertyGroup>
406407
<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>
407408
</PropertyGroup>
408-
<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'))" />
409+
<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'))" />
409410
</Target>
410411
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
411412
Other similar extension points exist, see Microsoft.Common.targets.

LibGit2Sharp/MergeOptionsBase.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ protected MergeOptionsBase()
2222
/// </summary>
2323
public bool FindRenames { get; set; }
2424

25+
/// <summary>
26+
/// If set, do not create conflict entries but fail the operation. No
27+
/// merged index will be created and a <see cref="LibGit2Sharp.ConflictInMergeException"/>
28+
/// exception will be thrown.
29+
/// </summary>
30+
public bool FailOnConflict { get; set; }
31+
32+
/// <summary>
33+
/// Do not write the Resolve Undo Cache extension on the generated index. This can
34+
/// be useful when no merge resolution will be presented to the user (e.g. a server-side
35+
/// merge attempt).
36+
/// </summary>
37+
public bool SkipReuc { get; set; }
38+
2539
/// <summary>
2640
/// Similarity to consider a file renamed.
2741
/// </summary>

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ public virtual MergeTreeResult MergeCommits(Commit ours, Commit theirs, MergeTre
607607
{
608608
Version = 1,
609609
MergeFileFavorFlags = options.MergeFileFavor,
610-
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES
611-
: GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
610+
MergeTreeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES
611+
: GitMergeFlag.GIT_MERGE_NORMAL,
612612
RenameThreshold = (uint)options.RenameThreshold,
613613
TargetLimit = (uint)options.TargetLimit,
614614
};

LibGit2Sharp/Repository.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,8 +1329,8 @@ public RevertResult Revert(Commit commit, Signature reverter, RevertOptions opti
13291329
{
13301330
Version = 1,
13311331
MergeFileFavorFlags = options.MergeFileFavor,
1332-
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES :
1333-
GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
1332+
MergeTreeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES :
1333+
GitMergeFlag.GIT_MERGE_NORMAL,
13341334
RenameThreshold = (uint)options.RenameThreshold,
13351335
TargetLimit = (uint)options.TargetLimit,
13361336
};
@@ -1413,8 +1413,8 @@ public CherryPickResult CherryPick(Commit commit, Signature committer, CherryPic
14131413
{
14141414
Version = 1,
14151415
MergeFileFavorFlags = options.MergeFileFavor,
1416-
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES :
1417-
GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
1416+
MergeTreeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES :
1417+
GitMergeFlag.GIT_MERGE_NORMAL,
14181418
RenameThreshold = (uint)options.RenameThreshold,
14191419
TargetLimit = (uint)options.TargetLimit,
14201420
};
@@ -1553,12 +1553,24 @@ private MergeResult Merge(GitAnnotatedCommitHandle[] annotatedCommits, Signature
15531553
private MergeResult NormalMerge(GitAnnotatedCommitHandle[] annotatedCommits, Signature merger, MergeOptions options)
15541554
{
15551555
MergeResult mergeResult;
1556+
GitMergeFlag treeFlags = options.FindRenames ? GitMergeFlag.GIT_MERGE_FIND_RENAMES
1557+
: GitMergeFlag.GIT_MERGE_NORMAL;
1558+
1559+
if (options.FailOnConflict)
1560+
{
1561+
treeFlags |= GitMergeFlag.GIT_MERGE_FAIL_ON_CONFLICT;
1562+
}
1563+
1564+
if (options.SkipReuc)
1565+
{
1566+
treeFlags |= GitMergeFlag.GIT_MERGE_SKIP_REUC;
1567+
}
1568+
15561569
var mergeOptions = new GitMergeOpts
15571570
{
15581571
Version = 1,
15591572
MergeFileFavorFlags = options.MergeFileFavor,
1560-
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES
1561-
: GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
1573+
MergeTreeFlags = treeFlags,
15621574
RenameThreshold = (uint)options.RenameThreshold,
15631575
TargetLimit = (uint)options.TargetLimit,
15641576
};

LibGit2Sharp/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="LibGit2Sharp.NativeBinaries" version="1.0.106" targetFramework="net4" allowedVersions="[1.0.106]" />
3+
<package id="LibGit2Sharp.NativeBinaries" version="1.0.114" targetFramework="net4" allowedVersions="[1.0.114]" />
44
</packages>

0 commit comments

Comments
 (0)