Skip to content

Commit 414b371

Browse files
committed
fix(deploy): clean up gh-pages obsolete files (angular#3081)
Prevents the gh-pages branch from growing indefinitely by cleaning up before copying new files. Fixes angular#3081
1 parent f6f24e7 commit 414b371

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-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+
var 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) => {

0 commit comments

Comments
 (0)