Skip to content

Commit

Permalink
fix(deploy): clean up gh-pages obsolete files (#3081)
Browse files Browse the repository at this point in the history
Prevents the gh-pages branch from growing indefinitely by cleaning up before copying new files.

Fixes #3081
  • Loading branch information
rolyatsats committed Dec 1, 2016
1 parent f6f24e7 commit 9fb8863
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/angular-cli/commands/github-pages-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const githubPagesDeployCommand = Command.extend({
.then(saveStartingBranchName)
.then(createGitHubRepoIfNeeded)
.then(checkoutGhPages)
.then(cleanGhPagesBranch)
.then(copyFiles)
.then(createNotFoundPage)
.then(addAndCommit)
Expand Down Expand Up @@ -205,6 +206,20 @@ const githubPagesDeployCommand = Command.extend({
.then(() => execPromise(`git commit -m \"initial ${ghPagesBranch} commit\"`));
}

function cleanGhPagesBranch() {
return execPromise('git ls-files')
.then(function(stdout) {
let files = '';
stdout.split(/\n/).forEach(function(f) {
// skip .gitignore & 404.html
if (( f != '') && (f != '.gitignore') && (f != '404.html')) {
files = files.concat(`"${f}" `);
}
});
return execPromise(`git rm -r ${files}`);
});
}

function copyFiles() {
return fsReadDir(outDir)
.then((files: string[]) => Promise.all(files.map((file) => {
Expand Down
10 changes: 10 additions & 0 deletions tests/acceptance/github-pages-deploy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
.addExecSuccess('git remote -v', remote)
.addExecSuccess(`git checkout ${ghPagesBranch}`)
.addExecSuccess('git ls-files')
.addExecSuccess('git rm -r ')
.addExecSuccess('git add .')
.addExecSuccess(`git commit -m "${message}"`)
.addExecSuccess(`git checkout ${initialBranch}`)
Expand All @@ -83,6 +85,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
.addExecSuccess('git remote -v', remote)
.addExecSuccess(`git checkout ${ghPagesBranch}`)
.addExecSuccess('git ls-files')
.addExecSuccess('git rm -r ')
.addExecSuccess('git add .')
.addExecSuccess(`git commit -m "${message}"`)
.addExecSuccess(`git checkout ${initialBranch}`)
Expand All @@ -102,6 +106,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
.addExecSuccess('git add .gitignore')
.addExecSuccess('git clean -f -d')
.addExecSuccess(`git commit -m \"initial ${ghPagesBranch} commit\"`)
.addExecSuccess('git ls-files')
.addExecSuccess('git rm -r ')
.addExecSuccess('git add .')
.addExecSuccess(`git commit -m "${message}"`)
.addExecSuccess(`git checkout ${initialBranch}`)
Expand All @@ -122,6 +128,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
.addExecSuccess(`git remote add origin [email protected]:${username}/${project}.git`)
.addExecSuccess(`git push -u origin ${initialBranch}`)
.addExecSuccess(`git checkout ${ghPagesBranch}`)
.addExecSuccess('git ls-files')
.addExecSuccess('git rm -r ')
.addExecSuccess('git add .')
.addExecSuccess(`git commit -m "${message}"`)
.addExecSuccess(`git checkout ${initialBranch}`)
Expand Down Expand Up @@ -220,6 +228,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
.addExecSuccess('git remote -v', remote)
.addExecSuccess(`git checkout ${ghPagesBranch}`)
.addExecSuccess('git ls-files')
.addExecSuccess('git rm -r ')
.addExecSuccess('git add .')
.addExecSuccess(`git commit -m "${message}"`)
.addExecError(`git checkout ${initialBranch}`, 'error: cannot stat \'src/client\': Permission denied');
Expand Down

0 comments on commit 9fb8863

Please sign in to comment.