8000 Make Stage(), Unstage(), Move() and Remove() explicitly throw a NotIm… · Folcon/libgit2sharp@524f56f · GitHub
[go: up one dir, main page]

Skip to content

Commit 524f56f

Browse files
committed
Make Stage(), Unstage(), Move() and Remove() explicitly throw a NotImplementedException when being passed a path that leads to a directory
1 parent c2f6ab2 commit 524f56f

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

LibGit2Sharp/Index.cs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ public void Stage(IEnumerable<string> paths)
133133
{
134134
Ensure.ArgumentNotNull(paths, "paths");
135135

136+
//TODO: Stage() should support following use cases:
137+
// - Recursively staging the content of a directory
138+
136139
IDictionary<string, FileStatus> batch = PrepareBatch(paths);
137140

138141
if (batch.Count == 0)
@@ -142,6 +145,11 @@ public void Stage(IEnumerable<string> paths)
142145

143146
foreach (KeyValuePair<string, FileStatus> kvp in batch)
144147
{
148+
if (Directory.Exists(kvp.Key))
149+
{
150+
throw new NotImplementedException();
151+
}
152+
145153
if (!kvp.Value.Has(FileStatus.Nonexistent))
146154
{
147155
continue;
@@ -192,6 +200,14 @@ public void Unstage(IEnumerable<string> paths)
192200
throw new ArgumentNullException("paths");
193201
}
194202

203+
foreach (KeyValuePair<string, FileStatus> kvp in batch)
204+
{
205+
if (Directory.Exists(kvp.Key))
206+
{
207+
throw new NotImplementedException();
208+
}
209+
}
210+
195211
foreach (KeyValuePair<string, FileStatus> kvp in batch)
196212
{
197213
bool doesExistInIndex =
@@ -232,6 +248,13 @@ public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinatio
232248
Ensure.ArgumentNotNull(sourcePaths, "sourcePaths");
233249
Ensure.ArgumentNotNull(destinationPaths, "destinationPaths");
234250

251+
//TODO: Move() should support following use cases:
252+
// - Moving a file under a directory ('file' and 'dir' -> 'dir/file')
253+
// - Moving a directory (and its content) under another directory ('dir1' and 'dir2' -> 'dir2/dir1/*')
254+
255+
//TODO: Move() should throw when:
256+
// - Moving a directory under a file
257+
235258
IDictionary<Tuple<string, FileStatus>, Tuple<string, FileStatus>> batch = PrepareBatch(sourcePaths, destinationPaths);
236259

237260
if (batch.Count == 0)
@@ -241,17 +264,27 @@ public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinatio
241264

242265
foreach (KeyValuePair<Tuple<string, FileStatus>, Tuple<string, FileStatus>> keyValuePair in batch)
243266
{
244-
if (keyValuePair.Key.Item2.HasAny(new[] { FileStatus.Nonexistent, FileStatus.Removed, FileStatus.Untracked, FileStatus.Missing }))
267+
string sourcePath = keyValuePair.Key.Item1;
268+
string destPath = keyValuePair.Value.Item1;
269+
270+
if (Directory.Exists(sourcePath) || Directory.Exists(destPath))
271+
{
272+
throw new NotImplementedException();
273+
}
274+
275+
FileStatus sourceStatus = keyValuePair.Key.Item2;
276+
if (sourceStatus.HasAny(new[] { FileStatus.Nonexistent, FileStatus.Removed, FileStatus.Untracked, FileStatus.Missing }))
245277
{
246-
throw new LibGit2Exception(string.Format("Unable to move file '{0}'. Its current status is '{1}'.", keyValuePair.Key.Item1, Enum.GetName(typeof(FileStatus), keyValuePair.Key.Item2)));
278+
throw new LibGit2Exception(string.Format("Unable to move file '{0}'. Its current status is '{1}'.", sourcePath, Enum.GetName(typeof(FileStatus), sourceStatus)));
247279
}
248280

249-
if (keyValuePair.Value.Item2.Has(FileStatus.Nonexistent))
281+
FileStatus desStatus = keyValuePair.Value.Item2;
282+
if (desStatus.Has(FileStatus.Nonexistent))
250283
{
251284
continue;
252285
}
253286

254-
throw new LibGit2Exception(string.Format("Unable to overwrite file '{0}'. Its current status is '{1}'.", keyValuePair.Value.Item1, Enum.GetName(typeof(FileStatus), keyValuePair.Value.Item2)));
287+
throw new LibGit2Exception(string.Format("Unable to overwrite file '{0}'. Its current status is '{1}'.", destPath, Enum.GetName(typeof(FileStatus), desStatus)));
255288
}
256289

257290
string wd = repo.Info.WorkingDirectory;
@@ -285,6 +318,9 @@ public void Remove(IEnumerable<string> paths)
285318
{
286319
Ensure.ArgumentNotNull(paths, "paths");
287320

321+
//TODO: Remove() should support following use cases:
322+
// - Removing a directory and its content
323+
288324
IDictionary<string, FileStatus> batch = PrepareBatch(paths);
289325

290326
if (batch.Count == 0)
@@ -294,6 +330,11 @@ public void Remove(IEnumerable<string> paths)
294330

295331
foreach (KeyValuePair<string, FileStatus> keyValuePair in batch)
296332
{
333+
if (Directory.Exists(keyValuePair.Key))
334+
{
335+
throw new NotImplementedException();
336+
}
337+
297338
if (!keyValuePair.Value.HasAny(new[] { FileStatus.Missing, FileStatus.Nonexistent, FileStatus.Removed, FileStatus.Untracked }))
298339
{
299340
continue;

0 commit comments

Comments
 (0)
0