@@ -1138,30 +1138,22 @@ Repository.prototype.getSubmoduleNames = function(callback) {
11381138} ;
11391139
11401140/**
1141- * This will set the HEAD to point to the local branch and then attempt
1141+ * This will set the HEAD to point to the reference and then attempt
11421142 * to update the index and working tree to match the content of the
1143- * latest commit on that branch
1143+ * latest commit on that reference
11441144 *
11451145 * @async
1146- * @param {String| Reference } branch the branch to checkout
1146+ * @param {Reference } reference the reference to checkout
11471147 * @param {Object|CheckoutOptions } opts the options to use for the checkout
11481148 */
1149- Repository . prototype . checkoutBranch = function ( branch , opts ) {
1149+ Repository . prototype . checkoutRef = function ( reference , opts ) {
11501150 var repo = this ;
1151- var reference ;
11521151 opts = opts || { } ;
11531152
11541153 opts . checkoutStrategy = opts . checkoutStrategy ||
11551154 ( NodeGit . Checkout . STRATEGY . SAFE |
11561155 NodeGit . Checkout . STRATEGY . RECREATE_MISSING ) ;
1157- return repo . getReference ( branch )
1158- . then ( function ( ref ) {
1159- if ( ! ref . isBranch ( ) ) {
1160- return false ;
1161- }
1162- reference = ref ;
1163- return repo . getBranchCommit ( ref . name ( ) ) ;
1164- } )
1156+ return repo . getReferenceCommit ( reference . name ( ) )
11651157 . then ( function ( commit ) {
11661158 return commit . getTree ( ) ;
11671159 } )
@@ -1174,6 +1166,27 @@ Repository.prototype.checkoutBranch = function(branch, opts) {
11741166 } ) ;
11751167} ;
11761168
1169+ /**
1170+ * This will set the HEAD to point to the local branch and then attempt
1171+ * to update the index and working tree to match the content of the
1172+ * latest commit on that branch
1173+ *
1174+ * @async
1175+ * @param {String|Reference } branch the branch to checkout
1176+ * @param {Object|CheckoutOptions } opts the options to use for the checkout
1177+ */
1178+ Repository . prototype . checkoutBranch = function ( branch , opts ) {
1179+ var repo = this ;
1180+
1181+ return repo . getReference ( branch )
1182+ . then ( function ( ref ) {
1183+ if ( ! ref . isBranch ( ) ) {
1184+ return false ;
1185+ }
1186+ return repo . checkoutRef ( ref , opts ) ;
1187+ } ) ;
1188+ } ;
1189+
11771190var fetchheadForeach = Repository . prototype . fetchheadForeach ;
11781191/**
11791192 * @async
0 commit comments