Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deploy): gh-pages checkout initial branch on error #3378

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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