Skip to content

Include Ignored Options #1328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions LibGit2Sharp.Tests/StatusFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,29 @@ public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives()
}
}

[Fact]
public void RetrievingTheStatusWithoutIncludeIgnoredIgnoresButDoesntInclude()
{
string repoPath = InitNewRepository();

using (var repo = new Repository(repoPath))
{
const string relativePath = "look-ma.txt";
Touch(repo.Info.WorkingDirectory, relativePath, "I'm going to be ignored!");
var opt = new StatusOptions { IncludeIgnored = false };
Assert.False(opt.IncludeIgnored);
RepositoryStatus status = repo.RetrieveStatus(opt);
Assert.Equal(new[] { relativePath }, status.Untracked.Select(s => s.FilePath));

Touch(repo.Info.WorkingDirectory, ".gitignore", "*.txt" + Environment.NewLine);

RepositoryStatus newStatus = repo.RetrieveStatus(opt);
Assert.Equal(".gitignore", newStatus.Untracked.Select(s => s.FilePath).Single());

Assert.False(newStatus.Ignored.Any());
}
}

[Fact]
public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
{
Expand Down
6 changes: 5 additions & 1 deletion LibGit2Sharp/RepositoryStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ private static GitStatusOptions CreateStatusOptions(StatusOptions options)
Version = 1,
Show = (GitStatusShow)options.Show,
Flags =
GitStatusOptionFlags.IncludeIgnored |
GitStatusOptionFlags.IncludeUntracked |
GitStatusOptionFlags.RecurseUntrackedDirs,
};

if (options.IncludeIgnored)
{
coreOptions.Flags |= GitStatusOptionFlags.IncludeIgnored;
}

if (options.DetectRenamesInIndex)
{
coreOptions.Flags |=
Expand Down
10 changes: 10 additions & 0 deletions LibGit2Sharp/StatusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public sealed class StatusOptions
public StatusOptions()
{
DetectRenamesInIndex = true;
IncludeIgnored = true;
}

/// <summary>
Expand Down Expand Up @@ -84,5 +85,14 @@ public StatusOptions()
/// Unaltered meaning the file is identical in the working directory, the index and HEAD.
/// </remarks>
public bool IncludeUnaltered { get; set; }

/// <summary>
/// Include ignored files when scanning for status
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public bool IncludeIgnored { get; set; }

}
}