Skip to content

Commit

Permalink
Merge pull request #35 from cksource/t/34
Browse files Browse the repository at this point in the history
Checking out to specific commit (hash) works as it should.
  • Loading branch information
Reinmar authored Jan 24, 2017
2 parents 8790302 + 9d97977 commit 8367a67
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ module.exports = {
if ( stdout ) {
throw new Error( `Package "${ data.packageName }" has uncommitted changes. Aborted.` );
}
} )
.then( () => {

return execCommand.execute( getExecData( `git fetch` ) );
} )
.then( ( response ) => {
Expand All @@ -67,6 +66,20 @@ module.exports = {
} )
.then( ( response ) => {
log.concat( response.logs );
} )
.then( () => {
return execCommand.execute( getExecData( 'git branch' ) );
} )
.then( ( response ) => {
const stdout = response.logs.info.join( '\n' ).trim();
const isOnBranchRegexp = /HEAD detached at [\w\d]+/;

// If on a detached commit, mgit must not pull the changes.
if ( isOnBranchRegexp.test( stdout ) ) {
log.info( `Package "${ data.packageName }" is on a detached commit.` );

return resolve( { logs: log.all() } );
}

return execCommand.execute( getExecData( `git pull origin ${ data.repository.branch }` ) );
} )
Expand Down

0 comments on commit 8367a67

Please sign in to comment.