Skip to content

Commit

Permalink
fix(deploy): gh-pages checkout initial branch on error (#3378)
Browse files Browse the repository at this point in the history
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
Closes #1259
  • Loading branch information
rolyatsats authored and hansl committed Dec 5, 2016
1 parent a5a33fa commit c5cd095
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/angular-cli/commands/github-pages-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>>denodeify(exec);
Expand Down Expand Up @@ -240,15 +241,22 @@ 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() {
return execPromise(`git checkout ${initialBranch}`);
}

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() {
Expand All @@ -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);
}
Expand Down

0 comments on commit c5cd095

Please sign in to comment.