8000 Introduce IndexEntry.StageLevel · Saaman/libgit2sharp@703e4d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 703e4d5

Browse files
committed
Introduce IndexEntry.StageLevel
1 parent 2546c05 commit 703e4d5

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,19 @@ public void ANewRepoIsFullyMerged()
1414
Assert.Equal(true, repo.Index.IsFullyMerged);
1515
}
1616
}
17+
18+
[Fact]
19+
public void AFullyMergedRepoOnlyContainsStagedIndexEntries()
20+
{
21+
using (var repo = new Repository(StandardTestRepoWorkingDirPath))
22+
{
23+
Assert.Equal(true, repo.Index.IsFullyMerged);
24+
25+
foreach (var entry in repo.Index)
26+
{
27+
Assert.Equal(StageLevel.Staged, entry.StageLevel);
28+
}
29+
}
30+
}
1731
}
1832
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ internal static extern int git_index_add(
397397
[DllImport(libgit2)]
398398
internal static extern UIntPtr git_index_entrycount(IndexSafeHandle index);
399399

400+
[DllImport(libgit2)]
401+
internal static extern int git_index_entry_stage(IndexEntrySafeHandle indexentry);
402+
400403
[DllImport(libgit2)]
401404
internal static extern int git_index_find(
402405
IndexSafeHandle index,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ public static int git_index_entrycount(IndexSafeHandle index)
654654
return (int)count;
655655
}
656656

657+
public static StageLevel git_index_entry_stage(IndexEntrySafeHandle index)
658+
{
659+
return (StageLevel)NativeMethods.git_index_entry_stage(index);
660+
}
661+
657662
public static int? git_index_find(IndexSafeHandle index, FilePath path)
658663
{
659664
int res = NativeMethods.git_index_find(index, path);

LibGit2Sharp/IndexEntry.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public FileStatus State
3636
/// </summary>
3737
public Mode Mode { get; private set; }
3838

39+
/// <summary>
40+
/// Gets the stage number.
41+
/// </summary>
42+
public StageLevel StageLevel { get; private set; }
43+
3944
/// <summary>
4045
/// Gets the id of the <see cref = "Blob" /> pointed at by this index entry.
4146
/// </summary>
@@ -57,6 +62,7 @@ internal static IndexEntry BuildFromPtr(Repository repo, IndexEntrySafeHandle ha
5762
Path = path.Native,
5863
Id = new ObjectId(entry.oid),
5964
state = () => repo.Index.RetrieveStatus(path.Native),
65+
StageLevel = Proxy.git_index_entry_stage(handle),
6066
Mode = (Mode)entry.Mode
6167
};
6268
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="RemoteCallbacks.cs" />
9090
<Compile Include="RemoteCompletionType.cs" />
9191
<Compile Include="CurrentOperation.cs" />
92+
<Compile Include="StageLevel.cs" />
9293
<Compile Include="TagCollectionExtensions.cs" />
9394
<Compile Include="Core\Compat\Environment.cs" />
9495
<Compile Include="Core\FilePath.cs" />

LibGit2Sharp/StageLevel.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace LibGit2Sharp
2+
{
3+
/// <summary>
4+
/// Disambiguates the different versions of an index entry during a merge.
5+
/// </summary>
6+
public enum StageLevel
7+
{
8+
/// <summary>
9+
/// The standard fully merged state for an index entry.
10+
/// </summary>
11+
Staged = 0,
12+
13+
/// <summary>
14+
/// Version of the entry as it was in the common base merge commit.
15+
/// </summary>
16+
Ancestor = 1,
17+
18+
/// <summary>
19+
/// Version of the entry as it is in the commit of the Head.
20+
/// </summary>
21+
Ours = 2,
22+
23+
/// <summary>
24+
/// Version of the entry as it is in the commit being merged.
25+
/// </summary>
26+
Theirs = 3,
27+
}
28+
}

0 commit comments

Comments
 (0)
0