Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change the type of Exception which is returned when staging/unstaging…

…/removing an empty collection of paths
  • Loading branch information...
commit e32f933298a8086f4cdbb5c2d70a0c199bf67ff1 1 parent e6ba4c9
@nulltoken nulltoken authored
Showing with 34 additions and 25 deletions.
  1. +16 −4 LibGit2Sharp.Tests/IndexFixture.cs
  2. +18 −21 LibGit2Sharp/Index.cs
View
20 LibGit2Sharp.Tests/IndexFixture.cs
@@ -288,8 +288,8 @@ public void StageFileWithBadParamsThrows()
{
Assert.Throws<ArgumentException>(() => repo.Index.Stage(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Index.Stage((string)null));
- Assert.Throws<ArgumentNullException>(() => repo.Index.Stage(new string[] { }));
- Assert.Throws<ArgumentNullException>(() => repo.Index.Stage(new string[] { null }));
+ Assert.Throws<ArgumentException>(() => repo.Index.Stage(new string[] { }));
+ Assert.Throws<ArgumentException>(() => repo.Index.Stage(new string[] { null }));
}
}
@@ -346,8 +346,8 @@ public void UnstagingFileWithBadParamsThrows()
{
Assert.Throws<ArgumentException>(() => repo.Index.Unstage(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Index.Unstage((string)null));
- Assert.Throws<ArgumentNullException>(() => repo.Index.Unstage(new string[] { }));
- Assert.Throws<ArgumentNullException>(() => repo.Index.Unstage(new string[] { null }));
+ Assert.Throws<ArgumentException>(() => repo.Index.Unstage(new string[] { }));
+ Assert.Throws<ArgumentException>(() => repo.Index.Unstage(new string[] { null }));
}
}
@@ -498,6 +498,18 @@ public void RemovingAInvalidFileThrows(string filepath)
}
[Fact]
+ public void RemovingFileWithBadParamsThrows()
+ {
+ using (var repo = new Repository(StandardTestRepoPath))
+ {
+ Assert.Throws<ArgumentException>(() => repo.Index.Remove(string.Empty));
+ Assert.Throws<ArgumentNullException>(() => repo.Index.Remove((string)null));
+ Assert.Throws<ArgumentException>(() => repo.Index.Remove(new string[] { }));
+ Assert.Throws<ArgumentException>(() => repo.Index.Remove(new string[] { null }));
+ }
+ }
+
+ [Fact]
public void PathsOfIndexEntriesAreExpressedInNativeFormat()
{
// Initialize a new repository
View
39 LibGit2Sharp/Index.cs
@@ -105,6 +105,8 @@ IEnumerator IEnumerable.GetEnumerator()
/// <param name = "path">The path of the file within the working directory.</param>
public void Stage(string path)
{
+ Ensure.ArgumentNotNull(path, "path");
+
Stage(new[] { path });
}
@@ -114,18 +116,11 @@ public void Stage(string path)
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
public void Stage(IEnumerable<string> paths)
{
- Ensure.ArgumentNotNull(paths, "paths");
-
//TODO: Stage() should support following use cases:
// - Recursively staging the content of a directory
IDictionary<string, FileStatus> batch = PrepareBatch(paths);
- if (batch.Count == 0)
- {
- throw new ArgumentNullException("paths");
- }
-
foreach (KeyValuePair<string, FileStatus> kvp in batch)
{
if (Directory.Exists(kvp.Key))
@@ -165,6 +160,8 @@ public void Stage(IEnumerable<string> paths)
/// <param name = "path">The path of the file within the working directory.</param>
public void Unstage(string path)
{
+ Ensure.ArgumentNotNull(path, "path");
+
Unstage(new[] { path });
}
@@ -174,15 +171,8 @@ public void Unstage(string path)
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
public void Unstage(IEnumerable<string> paths)
{
- Ensure.ArgumentNotNull(paths, "paths");
-
IDictionary<string, FileStatus> batch = PrepareBatch(paths);
- if (batch.Count == 0)
- {
- throw new ArgumentNullException("paths");
- }
-
foreach (KeyValuePair<string, FileStatus> kvp in batch)
{
if (Directory.Exists(kvp.Key))
@@ -291,6 +281,8 @@ public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinatio
/// <param name = "path">The path of the file within the working directory.</param>
public void Remove(string path)
{
+ Ensure.ArgumentNotNull(path, "path");
+
Remove(new[] { path });
}
@@ -304,18 +296,11 @@ public void Remove(string path)
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
public void Remove(IEnumerable<string> paths)
{
- Ensure.ArgumentNotNull(paths, "paths");
-
//TODO: Remove() should support following use cases:
// - Removing a directory and its content
IDictionary<string, FileStatus> batch = PrepareBatch(paths);
- if (batch.Count == 0)
- {
- throw new ArgumentNullException("paths");
- }
-
foreach (KeyValuePair<string, FileStatus> keyValuePair in batch)
{
if (Directory.Exists(keyValuePair.Key))
@@ -347,16 +332,28 @@ public void Remove(IEnumerable<string> paths)
private IDictionary<string, FileStatus> PrepareBatch(IEnumerable<string> paths)
{
+ Ensure.ArgumentNotNull(paths, "paths");
+
IDictionary<string, FileStatus> dic = new Dictionary<string, FileStatus>();
foreach (string path in paths)
{
+ if (string.IsNullOrEmpty(path))
+ {
+ throw new ArgumentException("At least one provided path is either null or empty.", "paths");
+ }
+
string relativePath = BuildRelativePathFrom(repo, path);
FileStatus fileStatus = RetrieveStatus(relativePath);
dic.Add(relativePath, fileStatus);
}
+ if (dic.Count == 0)
+ {
+ throw new ArgumentException("No path has been provided.", "paths");
+ }
+
return dic;
}
Please sign in to comment.
Something went wrong with that request. Please try again.