Skip to content

Commit 51869fb

Browse files
rolyatsatshansl
authored andcommitted
fix(deploy): clean up gh-pages obsolete files (angular#3081) (angular#3333)
Prevents the gh-pages branch from growing indefinitely by cleaning up before copying new files. Fixes angular#3081
1 parent 4dcfe27 commit 51869fb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const githubPagesDeployCommand = Command.extend({
147147
.then(saveStartingBranchName)
148148
.then(createGitHubRepoIfNeeded)
149149
.then(checkoutGhPages)
150+
.then(cleanGhPagesBranch)
150151
.then(copyFiles)
151152
.then(createNotFoundPage)
152153
.then(addAndCommit)
@@ -205,6 +206,20 @@ const githubPagesDeployCommand = Command.extend({
205206
.then(() => execPromise(`git commit -m \"initial ${ghPagesBranch} commit\"`));
206207
}
207208

209+
function cleanGhPagesBranch() {
210+
return execPromise('git ls-files')
211+
.then(function(stdout) {
212+
let files = '';
213+
stdout.split(/\n/).forEach(function(f) {
214+
// skip .gitignore & 404.html
215+
if (( f != '') && (f != '.gitignore') && (f != '404.html')) {
216+
files = files.concat(`"${f}" `);
217+
}
218+
});
219+
return execPromise(`git rm -r ${files}`);
220+
});
221+
}
222+
208223
function copyFiles() {
209224
return fsReadDir(outDir)
210225
.then((files: string[]) => Promise.all(files.map((file) => {

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

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
6666
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
6767
.addExecSuccess('git remote -v', remote)
6868
.addExecSuccess(`git checkout ${ghPagesBranch}`)
69+
.addExecSuccess('git ls-files')
70+
.addExecSuccess('git rm -r ')
6971
.addExecSuccess('git add .')
7072
.addExecSuccess(`git commit -m "${message}"`)
7173
.addExecSuccess(`git checkout ${initialBranch}`)
@@ -83,6 +85,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
8385
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
8486
.addExecSuccess('git remote -v', remote)
8587
.addExecSuccess(`git checkout ${ghPagesBranch}`)
88+
.addExecSuccess('git ls-files')
89+
.addExecSuccess('git rm -r ')
8690
.addExecSuccess('git add .')
8791
.addExecSuccess(`git commit -m "${message}"`)
8892
.addExecSuccess(`git checkout ${initialBranch}`)
@@ -102,6 +106,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
102106
.addExecSuccess('git add .gitignore')
103107
.addExecSuccess('git clean -f -d')
104108
.addExecSuccess(`git commit -m \"initial ${ghPagesBranch} commit\"`)
109+
.addExecSuccess('git ls-files')
110+
.addExecSuccess('git rm -r ')
105111
.addExecSuccess('git add .')
106112
.addExecSuccess(`git commit -m "${message}"`)
107113
.addExecSuccess(`git checkout ${initialBranch}`)
@@ -122,6 +128,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
122128
.addExecSuccess(`git remote add origin [email protected]:${username}/${project}.git`)
123129
.addExecSuccess(`git push -u origin ${initialBranch}`)
124130
.addExecSuccess(`git checkout ${ghPagesBranch}`)
131+
.addExecSuccess('git ls-files')
132+
.addExecSuccess('git rm -r ')
125133
.addExecSuccess('git add .')
126134
.addExecSuccess(`git commit -m "${message}"`)
127135
.addExecSuccess(`git checkout ${initialBranch}`)
@@ -220,6 +228,8 @@ describe('Acceptance: ng github-pages:deploy', function() {
220228
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
221229
.addExecSuccess('git remote -v', remote)
222230
.addExecSuccess(`git checkout ${ghPagesBranch}`)
231+
.addExecSuccess('git ls-files')
232+
.addExecSuccess('git rm -r ')
223233
.addExecSuccess('git add .')
224234
.addExecSuccess(`git commit -m "${message}"`)
225235
.addExecError(`git checkout ${initialBranch}`, 'error: cannot stat \'src/client\': Permission denied');

0 commit comments

Comments
 (0)