diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-02-28 23:40:57 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-03-03 15:50:41 +0400 |
commit | e32f933298a8086f4cdbb5c2d70a0c199bf67ff1 (patch) | |
tree | c90282ea13c18c5345f59ef311477f65e6adb9ba /LibGit2Sharp | |
parent | e6ba4c9d438aea285fff08d30f6f2cf5925348e2 (diff) |
Change the type of Exception which is returned when staging/unstaging/removing an empty collection of paths
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/Index.cs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs index d4285673..16e9734c 100644 --- a/LibGit2Sharp/Index.cs +++ b/LibGit2Sharp/Index.cs @@ -105,6 +105,8 @@ namespace LibGit2Sharp /// <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 @@ namespace LibGit2Sharp /// <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 @@ namespace LibGit2Sharp /// <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 @@ namespace LibGit2Sharp /// <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 @@ namespace LibGit2Sharp /// <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 @@ namespace LibGit2Sharp /// <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 @@ namespace LibGit2Sharp 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; } |