Skip to content

Commit 7dc08a7

Browse files
committed
fix(deploy): fail gracefully for permissions error (#569)
1 parent 1940d96 commit 7dc08a7

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

addon/ng2/commands/github-pages-deploy.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ module.exports = Command.extend({
100100
.then(addAndCommit)
101101
.then(returnStartingBranch)
102102
.then(pushToGitRepo)
103-
.then(printProjectUrl);
103+
.then(printProjectUrl)
104+
.catch(failGracefully);
104105

105106
function checkForPendingChanges() {
106107
return execPromise('git status --porcelain')
@@ -120,7 +121,7 @@ module.exports = Command.extend({
120121

121122
function saveStartingBranchName() {
122123
return execPromise('git rev-parse --abbrev-ref HEAD')
123-
.then((stdout) => initialBranch = stdout);
124+
.then((stdout) => initialBranch = stdout.replace(/\s/g, ''));
124125
}
125126

126127
function createGitHubRepoIfNeeded() {
@@ -180,5 +181,15 @@ module.exports = Command.extend({
180181
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
181182
});
182183
}
184+
185+
function failGracefully(error) {
186+
if (error && (/git clean/.test(error.message) || /Permission denied/.test(error.message))) {
187+
let msg = 'There was a permissions error during git file operations, please close any open project files/folders and try again.';
188+
msg += `\nYou might also need to return to the ${initialBranch} branch manually.`;
189+
return Promise.reject(new SilentError(msg));
190+
} else {
191+
return Promise.reject(error);
192+
}
193+
}
183194
}
184195
});

tests/acceptance/github-pages-deploy.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,23 @@ describe('Acceptance: ng github-pages:deploy', function() {
240240
})
241241
.then(() => httpsStub.restore());
242242
});
243+
244+
it('should fail gracefully when checkout has permissions failure', function() {
245+
execStub.addExecSuccess('git status --porcelain')
246+
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
247+
.addExecSuccess('git remote -v', remote)
248+
.addExecSuccess(`git checkout ${branch}`)
249+
.addExecSuccess('git add .')
250+
.addExecSuccess(`git commit -m "${message}"`)
251+
.addExecError(`git checkout ${initialBranch}`, 'error: cannot stat \'src/client\': Permission denied');
252+
253+
return ng(['github-pages:deploy', '--skip-build'])
254+
.then(() => {
255+
throw new SilentError('Should not pass the deploy.');
256+
}, (ret) => {
257+
expect(ret.name).to.equal('SilentError');
258+
expect(ret.isSilentError).to.equal(true);
259+
expect(ret.message).to.contain('There was a permissions error');
260+
});
261+
});
243262
});

0 commit comments

Comments
 (0)