From 8e93cceeb2423b11fa1acd735d71b0e425057735 Mon Sep 17 00:00:00 2001 From: Taylor Brink Date: Fri, 2 Dec 2016 19:03:31 -0600 Subject: [PATCH] fix(deploy): clean up gh-pages obsolete files (#3081) (#3333) Prevents the gh-pages branch from growing indefinitely by cleaning up before copying new files. Fixes #3081 --- .../angular-cli/commands/github-pages-deploy.ts | 15 +++++++++++++++ tests/acceptance/github-pages-deploy.spec.js | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/angular-cli/commands/github-pages-deploy.ts b/packages/angular-cli/commands/github-pages-deploy.ts index bf8334c8f959..5987b7f19152 100644 --- a/packages/angular-cli/commands/github-pages-deploy.ts +++ b/packages/angular-cli/commands/github-pages-deploy.ts @@ -147,6 +147,7 @@ const githubPagesDeployCommand = Command.extend({ .then(saveStartingBranchName) .then(createGitHubRepoIfNeeded) .then(checkoutGhPages) + .then(cleanGhPagesBranch) .then(copyFiles) .then(createNotFoundPage) .then(addAndCommit) @@ -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) => { diff --git a/tests/acceptance/github-pages-deploy.spec.js b/tests/acceptance/github-pages-deploy.spec.js index dff59065bac3..cd44a3cc078a 100644 --- a/tests/acceptance/github-pages-deploy.spec.js +++ b/tests/acceptance/github-pages-deploy.spec.js @@ -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}`) @@ -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}`) @@ -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}`) @@ -122,6 +128,8 @@ describe('Acceptance: ng github-pages:deploy', function() { .addExecSuccess(`git remote add origin git@github.com:${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}`) @@ -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');