Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deploy): clean up gh-pages obsolete files (#3081) #3333

Merged
merged 1 commit into from
Dec 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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