8000 Merge pull request #929 from zpete/zpete/assume_unchanged · GiTechLab/libgit2sharp@27411bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 27411bf

Browse files
committed
Merge pull request libgit2#929 from zpete/zpete/assume_unchanged
Expose the assume-unchanged flag to IndexEntry
2 parents 2f1c52f + 6f16791 commit 27411bf

19 files changed

+65
-1
lines changed

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 14 add 8000 itions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,20 @@ public void CanMimicGitAddAll()
466466
}
467467
}
468468

469+
[Fact]
470+
public void RetrievingAssumedUnchangedMarkedIndexEntries()
471+
{
472+
var path = SandboxAssumeUnchangedTestRepo();
473+
using (var repo = new Repository(path))
474+
{
475+
var regularFile = repo.Index["hello.txt"];
476+
Assert.False(regularFile.AssumeUnchanged);
477+
478+
var assumeUnchangedFile = repo.Index["world.txt"];
479+
Assert.True(assumeUnchangedFile.AssumeUnchanged);
480+
}
481+
}
482+
469483
private static void AddSomeCornerCases(Repository repo)
470484
{
471485
// Turn 1.txt into a directory in the Index
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Initial commit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = false
5+
logallrefupdates = true
6+
symlinks = false
7+
ignorecase = true
8+
hideDotFiles = dotGitOnly
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 872129051d644790636b416d1ef1ec830c5f6b90 nulltoken <emeric.fermas@gmail.com> 1422023333 +0100 commit (initial): Initial commit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 872129051d644790636b416d1ef1ec830c5f6b90 nulltoken <emeric.fermas@gmail.com> 1422023333 +0100 commit (initial): Initial commit

LibGit2Sharp.Tests/Resources/assume_unchanged_wd/dot_git/objects/87/2129051d644790636b416d1ef1ec830c5f6b90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��I
2+
B1]��>��'��[����� ��o���U/�Z�n�i"���5�S�Q�hC��.��n��<I!UP�3w�WЎRfS�+U9l�Fu����\�����\�3rD��:����-��
3+
�:� �>=?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
872129051d644790636b416d1ef1ec830c5f6b90
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
World

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,5 +581,16 @@ public void CanRetrieveTheStatusOfAGlobSpec()
581581
Assert.Equal(2, status.Untracked.Count());
582582
}
583583
}
584+
585+
[Fact]
586+
public void RetrievingTheStatusHonorsAssumedUnchangedMarkedIndexEntries()
587+
{
588+
var path = SandboxAssumeUnchangedTestRepo();
589+
using (var repo = new Repository(path))
590+
{
591+
var status = repo.RetrieveStatus();
592+
Assert.Equal("hello.txt", status.Modified.Single().FilePath);
593+
}
594+
}
584595
}
585596
}

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static BaseFixture()
3939
public static string RevertTestRepoWorkingDirPath { get; private set; }
4040
public static string SubmoduleTestRepoWorkingDirPath { get; private set; }
4141
private static string SubmoduleTargetTestRepoWorkingDirPath { get; set; }
42+
private static string AssumeUnchangedRepoWorkingDirPath { get; set; }
4243
public static DirectoryInfo ResourcesDirectory { get; private set; }
4344

4445
public static bool IsFileSystemCaseSensitive { get; private set; }
@@ -67,6 +68,7 @@ private static void SetUpTestEnvironment()
6768
RevertTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "revert_testrepo_wd");
6869
SubmoduleTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_wd");
6970
SubmoduleTargetTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_target_wd");
71+
AssumeUnchangedRepoWorkingDirPath = Path.Combine(sourceRelativePath, "assume_unchanged_wd");
7072
}
7173

7274
private static bool IsFileSystemCaseSensitiveInternal()
@@ -147,6 +149,11 @@ public string SandboxSubmoduleTestRepo()
147149
return Sandbox(SubmoduleTestRepoWorkingDirPath, SubmoduleTargetTestRepoWorkingDirPath);
148150
}
149151

152+
public string SandboxAssumeUnchangedTestRepo()
153+
{
154+
return Sandbox(AssumeUnchangedRepoWorkingDirPath);
155+
}
156+
150157
protected string Sandbox(string sourceDirectoryPath, params string[] additionalSourcePaths)
151158
{
152159
var scd = BuildSelfCleaningDirectory();

LibGit2Sharp/Core/GitIndexEntry.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace LibGit2Sharp.Core
66
[StructLayout(LayoutKind.Sequential)]
77
internal class GitIndexEntry
88
{
9+
internal const ushort GIT_IDXENTRY_VALID = 0x8000;
10+
911
public GitIndexTime CTime;
1012
public GitIndexTime MTime;
1113
public uint Dev;

LibGit2Sharp/IndexEntry.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public class IndexEntry : IEquatable<IndexEntry>
3030
/// </summary>
3131
public virtual StageLevel StageLevel { get; private set; }
3232

33+
/// <summary>
34+
/// Whether the file is marked as assume-unchanged
35+
/// </summary>
36+
public virtual bool AssumeUnchanged { get; private set; }
37+
3338
/// <summary>
3439
/// Gets the id of the <see cref="Blob"/> pointed at by this index entry.
3540
/// </summary>
@@ -51,7 +56,8 @@ internal static IndexEntry BuildFromPtr(IndexEntrySafeHandle handle)
5156
Path = path.Native,
5257
Id = entry.Id,
5358
StageLevel = Proxy.git_index_entry_stage(handle),
54-
Mode = (Mode)entry.Mode
59+
Mode = (Mode)entry.Mode,
60+
AssumeUnchanged = (GitIndexEntry.GIT_IDXENTRY_VALID & entry.Flags) == GitIndexEntry.GIT_IDXENTRY_VALID
5561
};
5662
}
5763

0 commit comments

Comments
 (0)
0