Skip to content

Commit c41bf72

Browse files
author
Edward Thomson
committed
Introduce StatusOptions.ExcludeSubmodules
1 parent d1e06fe commit c41bf72

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,5 +501,40 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectivesThroug
501501
Assert.True(newStatus.Untracked.Select(s => s.FilePath).Contains("bin" + dirSep + "what-about-me.txt"));
502502
}
503503
}
504+
505+
[Fact]
506+
public void CanRetrieveStatusOfFilesInSubmodule()
507+
{
508+
var path = CloneSubmoduleTestRepo();
509+
using (var repo = new Repository(path))
510+
{
511+
string[] expected = new string[] {
512+
".gitmodules",
513+
"sm_changed_file",
514+
"sm_changed_head",
515+
"sm_changed_index",
516+
"sm_changed_untracked_file",
517+
"sm_missing_commits"
518+
};
519+
520+
RepositoryStatus status = repo.Index.RetrieveStatus();
521+
Assert.Equal(expected, status.Modified.Select(x => x.FilePath).ToArray());
522+
}
523+
}
524+
525+
[Fact]
526+
public void CanExcludeStatusOfFilesInSubmodule()
527+
{
528+
var path = CloneSubmoduleTestRepo();
529+
using (var repo = new Repository(path))
530+
{
531+
string[] expected = new string[] {
532+
".gitmodules",
533+
};
534+
535+
RepositoryStatus status = repo.Index.RetrieveStatus(new StatusOptions() { ExcludeSubmodules = true });
536+
Assert.Equal(expected, status.Modified.Select(x => x.FilePath).ToArray());
537+
}
538+
}
504539
}
505540
}

LibGit2Sharp/RepositoryStatus.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ internal RepositoryStatus(Repository repo, StatusOptions options)
8282
GitStatusOptionFlags.RenamesFromRewrites;
8383
}
8484

85+
if (options != null && options.ExcludeSubmodules)
86+
{
87+
gitOptions.Flags |=
88+
GitStatusOptionFlags.ExcludeSubmodules;
89+
}
90+
8591
try
8692
{
8793
StatusListSafeHandle list = Proxy.git_status_list_new(repo.Handle, gitOptions);

LibGit2Sharp/StatusOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@ public StatusOptions()
5353
/// Examine unstaged changes in the working directory for renames.
5454
/// </summary>
5555
public virtual bool DetectRenamesInWorkDir { get; set; }
56+
57+
/// <summary>
58+
/// Exclude submodules from being scanned for status
59+
/// </summary>
60+
public virtual bool ExcludeSubmodules { get; set; }
5661
}
5762
}

0 commit comments

Comments
 (0)