Skip to content

Commit c5cd095

Browse files
rolyatsatshansl
authored andcommitted
fix(deploy): gh-pages checkout initial branch on error (#3378)
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
1 parent a5a33fa commit c5cd095

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/angular-cli/commands/github-pages-deploy.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const githubPagesDeployCommand = Command.extend({
102102
let ghPagesBranch = 'gh-pages';
103103
let destinationBranch = options.userPage ? 'master' : ghPagesBranch;
104104
let initialBranch: string;
105+
let branchErrMsg = ' You might also need to return to the initial branch manually.';
105106

106107
// declared here so that tests can stub exec
107108
const execPromise = <(cmd: string, options?: any) => Promise<string>>denodeify(exec);
@@ -240,15 +241,22 @@ const githubPagesDeployCommand = Command.extend({
240241
function addAndCommit() {
241242
return execPromise('git add .', execOptions)
242243
.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+
});
244250
}
245251

246252
function returnStartingBranch() {
247253
return execPromise(`git checkout ${initialBranch}`);
248254
}
249255

250256
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) ));
252260
}
253261

254262
function printProjectUrl() {
@@ -267,8 +275,7 @@ const githubPagesDeployCommand = Command.extend({
267275
ui.writeLine(error.message);
268276
let msg = 'There was a permissions error during git file operations, ' +
269277
'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)));
272279
} else {
273280
return Promise.reject(error);
274281
}

0 commit comments

Comments
 (0)