@@ -102,6 +102,7 @@ const githubPagesDeployCommand = Command.extend({
102
102
let ghPagesBranch = 'gh-pages' ;
103
103
let destinationBranch = options . userPage ? 'master' : ghPagesBranch ;
104
104
let initialBranch : string ;
105
+ let branchErrMsg = ' You might also need to return to the initial branch manually.' ;
105
106
106
107
// declared here so that tests can stub exec
107
108
const execPromise = < ( cmd : string , options ?: any ) => Promise < string > > denodeify ( exec ) ;
@@ -240,15 +241,22 @@ const githubPagesDeployCommand = Command.extend({
240
241
function addAndCommit ( ) {
241
242
return execPromise ( 'git add .' , execOptions )
242
243
. then ( ( ) => execPromise ( `git commit -m "${ options . message } "` ) )
243
- . catch ( ( ) => Promise . reject ( new SilentError ( 'No changes found. Deployment skipped.' ) ) ) ;
244
+ . catch ( ( ) => {
245
+ let msg = 'No changes found. Deployment skipped.' ;
246
+ return returnStartingBranch ( )
247
+ . then ( ( ) => Promise . reject ( new SilentError ( msg ) ) )
248
+ . catch ( ( ) => Promise . reject ( new SilentError ( msg . concat ( branchErrMsg ) ) ) ) ;
249
+ } ) ;
244
250
}
245
251
246
252
function returnStartingBranch ( ) {
247
253
return execPromise ( `git checkout ${ initialBranch } ` ) ;
248
254
}
249
255
250
256
function pushToGitRepo ( ) {
251
- return execPromise ( `git push origin ${ ghPagesBranch } :${ destinationBranch } ` ) ;
257
+ return execPromise ( `git push origin ${ ghPagesBranch } :${ destinationBranch } ` )
258
+ . catch ( ( err ) => returnStartingBranch ( )
259
+ . catch ( ( ) => Promise . reject ( err ) ) ) ;
252
260
}
253
261
254
262
function printProjectUrl ( ) {
@@ -267,8 +275,7 @@ const githubPagesDeployCommand = Command.extend({
267
275
ui . writeLine ( error . message ) ;
268
276
let msg = 'There was a permissions error during git file operations, ' +
269
277
'please close any open project files/folders and try again.' ;
270
- msg += `\nYou might also need to return to the ${ initialBranch } branch manually.` ;
271
- return Promise . reject ( new SilentError ( msg ) ) ;
278
+ return Promise . reject ( new SilentError ( msg . concat ( branchErrMsg ) ) ) ;
272
279
} else {
273
280
return Promise . reject ( error ) ;
274
281
}
0 commit comments