diff --git a/LibGit2Sharp.Tests/StatusFixture.cs b/LibGit2Sharp.Tests/StatusFixture.cs index 698639aa4..ce4877abc 100644 --- a/LibGit2Sharp.Tests/StatusFixture.cs +++ b/LibGit2Sharp.Tests/StatusFixture.cs @@ -660,5 +660,19 @@ public void UnalteredFilesDontMarkIndexAsDirty() Assert.Equal(9, status.Count()); } } + + [Fact] + public void TestUpdateIndexDoesNotFail() + { + var path = SandboxStandardTestRepo(); + + using (var repo = new Repository(path)) + { + // This option improves the performance of subsequent calls, + // but there isn't really an observable difference to assert + // Therefor enable the option and to ensure it doesn't trigger and exception is the only thing possible + repo.RetrieveStatus(new StatusOptions() { UpdateIndex = true }); + } + } } } diff --git a/LibGit2Sharp/RepositoryStatus.cs b/LibGit2Sharp/RepositoryStatus.cs index cc1c6e7e0..3ad58bf72 100644 --- a/LibGit2Sharp/RepositoryStatus.cs +++ b/LibGit2Sharp/RepositoryStatus.cs @@ -139,6 +139,12 @@ private static GitStatusOptions CreateStatusOptions(StatusOptions options) GitStatusOptionFlags.IncludeUnmodified; } + if (options.UpdateIndex) + { + coreOptions.Flags |= + GitStatusOptionFlags.UpdateIndex; + } + return coreOptions; } diff --git a/LibGit2Sharp/StatusOptions.cs b/LibGit2Sharp/StatusOptions.cs index 47dba9197..4e835cc80 100644 --- a/LibGit2Sharp/StatusOptions.cs +++ b/LibGit2Sharp/StatusOptions.cs @@ -105,5 +105,13 @@ public StatusOptions() /// Include untracked files when scanning for status /// public bool IncludeUntracked { get; set; } + + /// + /// Refresh out of date index and save it in index + /// + /// + /// Will result in less work being done in subsequent calls + /// + public bool UpdateIndex { get; set; } } }