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:
authornulltoken <emeric.fermas@gmail.com>2011-10-05 17:14:28 +0400
committernulltoken <emeric.fermas@gmail.com>2011-10-05 17:14:28 +0400
commit1142c4425c6b8fcf5399837efae6ebc01bfadba0 (patch)
treeab1afa9ef9a559c04f16b4f7738856ffd39e2fee /LibGit2Sharp/BranchCollection.cs
parentcfa7860bb748072d0d9c3f4db3e7af6f34dac354 (diff)
Ensure one can't checkout a non existent branch
Diffstat (limited to 'LibGit2Sharp/BranchCollection.cs')
-rw-r--r--LibGit2Sharp/BranchCollection.cs17
1 files changed, 12 insertions, 5 deletions
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs
index 756d2f6b..ed432e59 100644
--- a/LibGit2Sharp/BranchCollection.cs
+++ b/LibGit2Sharp/BranchCollection.cs
@@ -65,17 +65,24 @@ namespace LibGit2Sharp
/// <summary>
/// Checkout the branch with the specified by name.
/// </summary>
- /// <param name = "name">The name of the branch to checkout.</param>
+ /// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
/// <returns></returns>
- public Branch Checkout(string name)
+ public Branch Checkout(string shaOrReferenceName)
{
// TODO: Allow checkout of an arbitrary commit, thus putting HEAD in detached state.
// TODO: This does not yet checkout (write) the working directory
- Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(shaOrReferenceName, "shaOrReferenceName");
- repo.Refs.UpdateTarget("HEAD", this[name].CanonicalName);
+ var branch = this[shaOrReferenceName];
- return this[name];
+ if (branch == null)
+ {
+ throw new LibGit2Exception(String.Format(CultureInfo.InvariantCulture, "No commit object identified by '{0}' can be found in the repository.", shaOrReferenceName));
+ }
+
+ repo.Refs.UpdateTarget("HEAD", branch.CanonicalName);
+
+ return branch;
}
/// <summary>