From 2c0e01a1ae59fa6f4e11c063118cb3182260d05a Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Mon, 23 Jan 2017 18:01:40 +0100 Subject: [PATCH 1/2] Fix: Checking out to specify commit work as it should. --- lib/commands/update.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/commands/update.js b/lib/commands/update.js index aac9ac2..aaf1197 100644 --- a/lib/commands/update.js +++ b/lib/commands/update.js @@ -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 ) => { @@ -67,6 +66,18 @@ 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 [A-Z\.0-9\-]+\)/i; + + // If branch is a commit, mgit must not pull the changes. + if ( isOnBranchRegexp.test( stdout ) ) { + return resolve( { logs: log.all() } ); + } return execCommand.execute( getExecData( `git pull origin ${ data.repository.branch }` ) ); } ) From 9d979770e4f2892909e6b8441b74588565f7db78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Tue, 24 Jan 2017 12:41:30 +0100 Subject: [PATCH 2/2] Improved logging and used a safer regexp (more future-proof). --- lib/commands/update.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/commands/update.js b/lib/commands/update.js index aaf1197..95aa314 100644 --- a/lib/commands/update.js +++ b/lib/commands/update.js @@ -72,10 +72,12 @@ module.exports = { } ) .then( ( response ) => { const stdout = response.logs.info.join( '\n' ).trim(); - const isOnBranchRegexp = /\* \(HEAD detached at [A-Z\.0-9\-]+\)/i; + const isOnBranchRegexp = /HEAD detached at [\w\d]+/; - // If branch is a commit, mgit must not pull the changes. + // 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() } ); }