Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2013-08-13 22:43:35 +0400
committerJameson Miller <jamill@microsoft.com>2013-08-13 22:43:35 +0400
commitd370aa69e34e6dea7032d852a16177fd719fb939 (patch)
tree1e3b5467a7270a75536fface73c9230ef9efeb6d /LibGit2Sharp/Repository.cs
parent88b4c1b33adb49e6e4f8adbb7567970b683f380f (diff)
Update CheckoutPaths method to handle null or empty paths parameter
Fixes an issue where passing an empty enumeration to CheckoutPaths results in the entire commit being checked out - which is not how I expect the method to operate. Instead, this method will now ensure that the path parameter is not null and if the path parameter is an empty list the method will return without checking out any paths.
Diffstat (limited to 'LibGit2Sharp/Repository.cs')
-rw-r--r--LibGit2Sharp/Repository.cs9
1 files changed, 8 insertions, 1 deletions
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 9f68637a..9ebab302 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -838,11 +838,18 @@ namespace LibGit2Sharp
/// </para>
/// </summary>
/// <param name = "committishOrBranchSpec">A revparse spec for the commit or branch to checkout paths from.</param>
- /// <param name="paths">The paths to checkout.</param>
+ /// <param name="paths">The paths to checkout. Will throw if null is passed in. Passing an empty enumeration results in nothing being checked out.</param>
/// <param name="checkoutOptions">Collection of parameters controlling checkout behavior.</param>
public void CheckoutPaths(string committishOrBranchSpec, IEnumerable<string> paths, CheckoutOptions checkoutOptions = null)
{
Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
+ Ensure.ArgumentNotNull(paths, "paths");
+
+ // If there are no paths, then there is nothing to do.
+ if (!paths.Any())
+ {
+ return;
+ }
Commit commit = LookupCommit(committishOrBranchSpec);
CheckoutTree(commit.Tree, paths.ToList(), checkoutOptions ?? new CheckoutOptions());