8000 make including ignored files optional (still default to true) so user… · libgit2/libgit2sharp@461ddeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 461ddeb

Browse files
committed
make including ignored files optional (still default to true) so users can opt out for perf reasons. Add unittests for that status option.
1 parent 0b00a5b commit 461ddeb

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,29 @@ public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives()
318318
}
319319
}
320320

321+
[Fact]
322+
public void RetrievingTheStatusWithoutIncludeIgnoredIgnoresButDoesntInclude()
323+
{
324+
string repoPath = InitNewRepository();
325+
326+
using (var repo = new Repository(repoPath))
327+
{
328+
const string relativePath = "look-ma.txt";
329+
Touch(repo.Info.WorkingDirectory, relativePath, "I'm going to be ignored!");
330+
var opt = new StatusOptions { IncludeIgnored = false };
331+
Assert.False(opt.IncludeIgnored);
332+
RepositoryStatus status = repo.RetrieveStatus(opt);
333+
Assert.Equal(new[] { relativePath }, status.Untracked.Select(s => s.FilePath));
334+
335+
Touch(repo.Info.WorkingDirectory, ".gitignore", "*.txt" + Environment.NewLine);
336+
337+
RepositoryStatus newStatus = repo.RetrieveStatus(opt);
338+
Assert.Equal(".gitignore", newStatus.Untracked.Select(s => s.FilePath).Single());
339+
340+
Assert.False(newStatus.Ignored.Any());
341+
}
342+
}
343+
321344
[Fact]
322345
public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
323346
{

LibGit2Sharp/RepositoryStatus.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ private static GitStatusOptions CreateStatusOptions(StatusOptions options)
7979
Version = 1,
8080
Show = (GitStatusShow)options.Show,
8181
Flags =
82-
GitStatusOptionFlags.IncludeIgnored |
8382
GitStatusOptionFlags.IncludeUntracked |
8483
GitStatusOptionFlags.RecurseUntrackedDirs,
8584
};
8685

86+
if (options.IncludeIgnored)
87+
{
88+
coreOptions.Flags |= GitStatusOptionFlags.IncludeIgnored;
89+
}
90+
8791
if (options.DetectRenamesInIndex)
8892
{
8993
coreOptions.Flags |=

LibGit2Sharp/StatusOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public sealed class StatusOptions
3535
public StatusOptions()
3636
{
3737
DetectRenamesInIndex = true;
38+
IncludeIgnored = true;
3839
}
3940

4041
/// <summary>
@@ -84,5 +85,14 @@ public StatusOptions()
8485
/// Unaltered meaning the file is identical in the working directory, the index and HEAD.
8586
/// </remarks>
8687
public bool IncludeUnaltered { get; set; }
88+
89+
/// <summary>
90+
/// Include ignored files when scanning for status
91+
/// </summary>
92+
/// <remarks>
93+
/// ignored meaning present in .gitignore. Defaults to true for back compat but may improve perf to not include if you have thousands of ignored files.
94+
/// </remarks>
95+
public bool IncludeIgnored { get; set; }
96+
8797
}
8898
}

0 commit comments

Comments
 (0)
0