From 3786c605bb66a9f30e4d1059973d0e907e69dcf7 Mon Sep 17 00:00:00 2001 From: Taylor Brink Date: Sat, 3 Dec 2016 15:37:05 -0600 Subject: [PATCH] fix(deploy): gh-pages checkout initial branch on error If github-pages:deploy fails due to 'No changes found' or fails pushing to git repo, it then attempts to checkout the initial branch. Closes #3030 Closes #2663 --- .../angular-cli/commands/github-pages-deploy.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/angular-cli/commands/github-pages-deploy.ts b/packages/angular-cli/commands/github-pages-deploy.ts index 5987b7f19152..04bf69b8dd23 100644 --- a/packages/angular-cli/commands/github-pages-deploy.ts +++ b/packages/angular-cli/commands/github-pages-deploy.ts @@ -102,6 +102,7 @@ const githubPagesDeployCommand = Command.extend({ let ghPagesBranch = 'gh-pages'; let destinationBranch = options.userPage ? 'master' : ghPagesBranch; let initialBranch: string; + let branchErrMsg = ' You might also need to return to the initial branch manually.'; // declared here so that tests can stub exec const execPromise = <(cmd: string, options?: any) => Promise>denodeify(exec); @@ -240,7 +241,12 @@ const githubPagesDeployCommand = Command.extend({ function addAndCommit() { return execPromise('git add .', execOptions) .then(() => execPromise(`git commit -m "${options.message}"`)) - .catch(() => Promise.reject(new SilentError('No changes found. Deployment skipped.'))); + .catch(() => { + let msg = 'No changes found. Deployment skipped.'; + return returnStartingBranch() + .then(() => Promise.reject(new SilentError(msg))) + .catch(() => Promise.reject(new SilentError(msg.concat(branchErrMsg)))); + }); } function returnStartingBranch() { @@ -248,7 +254,9 @@ const githubPagesDeployCommand = Command.extend({ } function pushToGitRepo() { - return execPromise(`git push origin ${ghPagesBranch}:${destinationBranch}`); + return execPromise(`git push origin ${ghPagesBranch}:${destinationBranch}`) + .catch((err) => returnStartingBranch() + .catch(() => Promise.reject(err) )); } function printProjectUrl() { @@ -267,8 +275,7 @@ const githubPagesDeployCommand = Command.extend({ ui.writeLine(error.message); let msg = 'There was a permissions error during git file operations, ' + 'please close any open project files/folders and try again.'; - msg += `\nYou might also need to return to the ${initialBranch} branch manually.`; - return Promise.reject(new SilentError(msg)); + return Promise.reject(new SilentError(msg.concat(branchErrMsg))); } else { return Promise.reject(error); }