Skip to content

Commit 23622fe

Browse files
committed
Index.Unstage should accept absolute file paths
1 parent 9ded665 commit 23622fe

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public void CanUnstageTheRemovalOfAFile()
341341
}
342342

343343
[Fact]
344-
public void CanUnstageUntrackedFileInAnEmptyRepository()
344+
public void CanUnstageUntrackedFileAgainstAnOrphanedHead()
345345
{
346346
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
347347

@@ -360,6 +360,41 @@ public void CanUnstageUntrackedFileInAnEmptyRepository()
360360
}
361361
}
362362

363+
[Fact]
364+
public void UnstagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows()
365+
{
366+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
367+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
368+
using (var repo = new Repository(path.RepositoryPath))
369+
{
370+
DirectoryInfo di = Directory.CreateDirectory(scd.DirectoryPath);
371+
372+
const string filename = "unit_test.txt";
373+
string fullPath = Path.Combine(di.FullName, filename);
374+
File.WriteAllText(fullPath, "some contents");
375+
376+
Assert.Throws<ArgumentException>(() => repo.Index.Unstage(fullPath));
377+
}
378+
}
379+
380+
[Fact]
381+
public void UnstagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirAgainstAnOrphanedHeadThrows()
382+
{
383+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
384+
SelfCleaningDirectory scd2 = BuildSelfCleaningDirectory();
385+
386+
using (var repo = Repository.Init(scd2.DirectoryPath))
387+
{
388+
DirectoryInfo di = Directory.CreateDirectory(scd.DirectoryPath);
389+
390+
const string filename = "unit_test.txt";
391+
string fullPath = Path.Combine(di.FullName, filename);
392+
File.WriteAllText(fullPath, "some contents");
393+
394+
Assert.Throws<ArgumentException>(() => repo.Index.Unstage(fullPath));
395+
}
396+
}
397+
363398
[Fact]
364399
public void UnstagingFileWithBadParamsThrows()
365400
{

LibGit2Sharp/Index.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,19 @@ public virtual void Unstage(string path)
211211
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
212212
public virtual void Unstage(IEnumerable<string> paths)
213213
{
214-
Commit commit = repo.Lookup("HEAD",
214+
Ensure.ArgumentNotNull(paths, "paths");
215+
216+
IEnumerable<KeyValuePair<string, FileStatus>> batch = PrepareBatch(paths);
217+
218+
foreach (KeyValuePair<string, FileStatus> kvp in batch)
219+
{
220+
if (Directory.Exists(kvp.Key))
221+
{
222+
throw new NotImplementedException();
223+
}
224+
}
225+
226+
var commit = repo.Lookup("HEAD",
215227
GitObjectType.Any,
216228
LookUpOptions.DereferenceResultToCommit) as Commit;
217229

0 commit comments

Comments
 (0)