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:
authorKeith Dahlby <dahlbyk@gmail.com>2012-04-21 04:44:27 +0400
committerKeith Dahlby <dahlbyk@gmail.com>2012-04-21 04:44:27 +0400
commit186ca1782f4346b4ed9f904103a393f1abfa2c1e (patch)
tree616bfabb7e0e0c3bf78c2c4e6f06446df0fcb4c5 /LibGit2Sharp
parentd1993af681c2edd61cdc1440d2cb7d5de83522de (diff)
Move Checkout() to Repository
Closes #107
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/BranchCollection.cs15
-rw-r--r--LibGit2Sharp/Repository.cs22
2 files changed, 24 insertions, 13 deletions
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs
index 422d7ee4..22954329 100644
--- a/LibGit2Sharp/BranchCollection.cs
+++ b/LibGit2Sharp/BranchCollection.cs
@@ -67,21 +67,10 @@ namespace LibGit2Sharp
/// </summary>
/// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
/// <returns></returns>
+ [Obsolete("This method will be removed in the next release. Please use Repository.Checkout() instead.")]
public Branch Checkout(string shaOrReferenceName)
{
- // TODO: This does not yet checkout (write) the working directory
-
- Branch branch = this[shaOrReferenceName];
-
- if (branch != null)
- {
- repo.Refs.UpdateTarget("HEAD", branch.CanonicalName);
- return branch;
- }
-
- ObjectId commitId = repo.LookupCommit(shaOrReferenceName).Id;
- repo.Refs.UpdateTarget("HEAD", commitId.Sha);
- return repo.Head;
+ return repo.Checkout(shaOrReferenceName);
}
/// <summary>
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 9aea29a9..e6f2ab39 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -342,6 +342,28 @@ namespace LibGit2Sharp
}
/// <summary>
+ /// Checkout the specified branch, reference or SHA.
+ /// </summary>
+ /// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
+ /// <returns>The new HEAD.</returns>
+ public Branch Checkout(string shaOrReferenceName)
+ {
+ // TODO: This does not yet checkout (write) the working directory
+
+ var branch = Branches[shaOrReferenceName];
+
+ if (branch != null)
+ {
+ Refs.UpdateTarget("HEAD", branch.CanonicalName);
+ return branch;
+ }
+
+ var commitId = LookupCommit(shaOrReferenceName).Id;
+ Refs.UpdateTarget("HEAD", commitId.Sha);
+ return Head;
+ }
+
+ /// <summary>
/// Sets the current <see cref = "Head" /> to the specified commit and optionally resets the <see cref = "Index" /> and
/// the content of the working tree to match.
/// </summary>