8000 Introduce PathSpec for StatusOptions. · raiden2012/libgit2sharp@a783913 · GitHub
[go: up one dir, main page]

Skip to content

Commit a783913

Browse files
committed
Introduce PathSpec for StatusOptions.
1 parent 6a92ac9 commit a783913

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,5 +536,63 @@ public void CanExcludeStatusOfFilesInSubmodule()
536536
Assert.Equal(expected, status.Modified.Select(x => x.FilePath).ToArray());
537537
}
538538
}
539+
540+
[Fact]
541+
public void CanRetrieveTheStatusOfARelativeWorkingDirectory()
542+
{
543+
string path = CloneStandardTestRepo();
544+
using (var repo = new Repository(path))
545+
{
546+
const string file = "just_a_dir/other.txt";
547+
const string otherFile = "just_a_dir/another_dir/other.txt";
548+
549+
Touch(repo.Info.WorkingDirectory, file);
550+
Touch(repo.Info.WorkingDirectory, otherFile);
551+
552+
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { PathSpec = new[] { "just_a_dir" } });
553+
Assert.Equal(2, status.Count());
554+
Assert.Equal(2, status.Untracked.Count());
555+
556+
status = repo.RetrieveStatus(new StatusOptions() { PathSpec = new[] { "just_a_dir/another_dir" } });
557+
Assert.Equal(1, status.Count());
558+
Assert.Equal(1, status.Untracked.Count());
559+
}
560+
}
561+
562+
[Fact]
563+
public void CanRetrieveTheStatusOfMultiplePathSpec()
564+
{
565+
string path = CloneStandardTestRepo();
566+
using (var repo = new Repository(path))
567+
{
568+
const string file = "just_a_dir/other.txt";
569+
const string otherFile = "just_a_file.txt";
570+
571+
Touch(repo.Info.WorkingDirectory, file);
572+
Touch(repo.Info.WorkingDirectory, otherFile);
573+
574+
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { PathSpec = new[] { "just_a_file.txt", "just_a_dir" } });
575+
Assert.Equal(2, status.Count());
576+
Assert.Equal(2, status.Untracked.Count());
577+
}
578+
}
579+
580+
[Fact]
581+
public void CanRetrieveTheStatusOfAGlobSpec()
582+
{
583+
string path = CloneStandardTestRepo();
584+
using (var repo = new Repository(path))
585+
{
586+
const string file = "just_a_dir/other.txt";
587+
const string otherFile = "just_a_file.txt";
588+
589+
Touch(repo.Info.WorkingDirectory, file);
590+
Touch(repo.Info.WorkingDirectory, otherFile);
591+
592+
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { PathSpec = new[] { "just_a_*" } });
593+
Assert.Equal(2, status.Count());
594+
Assert.Equal(2, status.Untracked.Count());
595+
}
596+
}
539597
}
540598
}

LibGit2Sharp/Core/GitStatusOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class GitStatusOptions : IDisposable
1414
public GitStatusShow Show;
1515
public GitStatusOptionFlags Flags;
1616

17-
GitStrArrayManaged PathSpec;
17+
public GitStrArrayManaged PathSpec;
1818

1919
public void Dispose()
2020
{

LibGit2Sharp/RepositoryStatus.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ private static GitStatusOptions CreateStatusOptions(StatusOptions options)
123123
GitStatusOptionFlags.RecurseIgnoredDirs;
124124
}
125125

126+
if (options.PathSpec != null)
127+
{
128+
coreOptions.PathSpec = GitStrArrayManaged.BuildFrom(options.PathSpec);
129+
}
130+
126131
return coreOptions;
127132
}
128133

LibGit2Sharp/StatusOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,10 @@ public StatusOptions()
6666
/// Recurse into ignored directories
6767
/// </summary>
6868
public bool RecurseIgnoredDirs { get; set; }
69+
70+
/// <summary>
71+
/// Limit the scope of paths to consider to the provided pathspecs
72+
/// </summary>
73+
public string[] PathSpec { get; set; }
6974
}
7075
}

0 commit comments

Comments
 (0)
0