8000 Expose low level Index.Remove() · GiTechLab/libgit2sharp@a8973a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8973a4

Browse files
committed
Expose low level Index.Remove()
1 parent cf0a893 commit a8973a4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,5 +373,24 @@ public void CanClearTheIndex()
373373
Assert.Equal(FileStatus.Removed | FileStatus.Untracked, repo.RetrieveStatus(testFile));
374374
}
375375
}
376+
377+
[Theory]
378+
[InlineData("new_tracked_file.txt", FileStatus.Added, FileStatus.Untracked)]
379+
[InlineData("modified_staged_file.txt", FileStatus.Staged, FileStatus.Removed | FileStatus.Untracked)]
380+
[InlineData("i_dont_exist.txt", FileStatus.Nonexistent, FileStatus.Nonexistent)]
381+
public void CanRemoveAnEntryFromTheIndex(string pathInTheIndex, FileStatus expectedBeforeStatus, FileStatus expectedAfterStatus)
382+
{
383+
var path = SandboxStandardTestRepoGitDir();
384+
using (var repo = new Repository(path))
385+
{
386+
var before = repo.RetrieveStatus(pathInTheIndex);
387+
Assert.Equal(expectedBeforeStatus, before);
388+
389+
repo.Index.Remove(pathInTheIndex);
390+
391+
var after = repo.RetrieveStatus(pathInTheIndex);
392+
Assert.Equal(expectedAfterStatus, after);
393+
}
394+
}
376395
}
377396
}

LibGit2Sharp/Index.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ private void RemoveFromIndex(string relativePath)
162162
Proxy.git_index_remove_bypath(handle, relativePath);
163163
}
164164

165+
/// <summary>
166+
/// Removes a specified entry from the index.
167+
/// </summary>
168+
/// <param name="indexEntryPath">The path of the <see cref="Index"/> entry to be removed.</param>
169+
public virtual void Remove(string indexEntryPath)
170+
{
171+
if (indexEntryPath == null)
172+
{
173+
throw new ArgumentNullException("indexEntryPath");
174+
}
175+
176+
RemoveFromIndex(indexEntryPath);
177+
178+
UpdatePhysicalIndex();
179+
}
180+
165181
private void UpdatePhysicalIndex()
166182
{
167183
Proxy.git_index_write(handle);

0 commit comments

Comments
 (0)
0