From 186ca1782f4346b4ed9f904103a393f1abfa2c1e Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Fri, 20 Apr 2012 19:44:27 -0500 Subject: Move Checkout() to Repository Closes #107 --- LibGit2Sharp/BranchCollection.cs | 15 ++------------- LibGit2Sharp/Repository.cs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) (limited to 'LibGit2Sharp') 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 /// /// The sha of the commit, a canonical reference name or the name of the branch to checkout. /// + [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); } /// diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 9aea29a9..e6f2ab39 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -341,6 +341,28 @@ namespace LibGit2Sharp return discoveredPath.Native; } + /// + /// Checkout the specified branch, reference or SHA. + /// + /// The sha of the commit, a canonical reference name or the name of the branch to checkout. + /// The new HEAD. + 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; + } + /// /// Sets the current to the specified commit and optionally resets the and /// the content of the working tree to match. -- cgit v1.2.3