Skip to content

Commit e0ce428

Browse files
author
Edward Thomson
committed
Introduce StatusShowOption (for git_status_show_t)
1 parent 64d1929 commit e0ce428

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,42 @@ public void CanRetrieveTheStatusOfAFile()
2020
}
2121
}
2222

23+
[Theory]
24+
[InlineData(StatusShowOption.IndexAndWorkdir, FileStatus.Untracked)]
25+
[InlineData(StatusShowOption.WorkdirOnly, FileStatus.Untracked)]
26+
[InlineData(StatusShowOption.IndexOnly, FileStatus.Nonexistent)]
27+
public void CanLimitStatusToWorkdirOnly(StatusShowOption show, FileStatus expected)
28+
{
29+
var clone = CloneStandardTestRepo();
30+
31+
using (var repo = new Repository(clone))
32+
{
33+
Touch(repo.Info.WorkingDirectory, "file.txt", "content");
34+
35+
RepositoryStatus status = repo.Index.RetrieveStatus(new StatusOptions() { Show = show });
36+
Assert.Equal(expected, status["file.txt"].State);
37+
}
38+
}
39+
40+
[Theory]
41+
[InlineData(StatusShowOption.IndexAndWorkdir, FileStatus.Added)]
42+
[InlineData(StatusShowOption.WorkdirOnly, FileStatus.Nonexistent)]
43+
[InlineData(StatusShowOption.IndexOnly, FileStatus.Added)]
44+
public void CanLimitStatusToIndexOnly(StatusShowOption show, FileStatus expected)
45+
{
46+
var clone = CloneStandardTestRepo();
47+
48+
using (var repo = new Repository(clone))
49+
{
50+
Touch(repo.Info.WorkingDirectory, "file.txt", "content");
51+
repo.Index.Stage("file.txt");
52+
53+
RepositoryStatus status = repo.Index.RetrieveStatus(new StatusOptions() { Show = show });
54+
Assert.Equal(expected, status["file.txt"].State);
55+
}
56+
}
57+
58+
2359
[Theory]
2460
[InlineData("file")]
2561
[InlineData("file.txt")]

LibGit2Sharp/RepositoryStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal RepositoryStatus(Repository repo, StatusOptions options)
6161
var gitOptions = new GitStatusOptions
6262
{
6363
Version = 1,
64-
Show = GitStatusShow.IndexAndWorkdir,
64+
Show = (GitStatusShow)options.Show,
6565
Flags =
6666
GitStatusOptionFlags.IncludeIgnored |
6767
GitStatusOptionFlags.IncludeUntracked |

LibGit2Sharp/StatusOptions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,47 @@
55

66
namespace LibGit2Sharp
77
{
8+
/// <summary>
9+
/// Flags controlling what files are reported by status.
10+
/// </summary>
11+
public enum StatusShowOption
12+
{
13+
/// <summary>
14+
/// Both the index and working directory are examined for changes
15+
/// </summary>
16+
IndexAndWorkdir = 0,
17+
18+
/// <summary>
19+
/// Only the index is examined for changes
20+
/// </summary>
21+
IndexOnly = 1,
22+
23+
/// <summary>
24+
/// Only the working directory is examined for changes
25+
/// </summary>
26+
WorkdirOnly = 2
27+
}
28+
829
/// <summary>
930
/// Options controlling the status behavior.
1031
/// </summary>
1132
public class StatusOptions
1233
{
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="StatusOptions"/> class.
36+
/// </summary>
1337
public StatusOptions()
1438
{
39+
Show = StatusShowOption.IndexAndWorkdir;
40+
1541
DetectRenamesInIndex = true;
1642
}
1743

44+
/// <summary>
45+
/// Which files should be scanned and returned
46+
/// </summary>
47+
public virtual StatusShowOption Show { get; set; }
48+
1849
/// <summary>
1950
/// Examine the staged changes for renames.
2051
/// </summary>

0 commit comments

Comments
 (0)