diff --git a/lib/publish-gh-pages.js b/lib/publish-gh-pages.js index 78a3789c6b..0d5cd093ff 100755 --- a/lib/publish-gh-pages.js +++ b/lib/publish-gh-pages.js @@ -56,17 +56,23 @@ if ( shell.cd(`${CIRCLE_PROJECT_REPONAME}-gh-pages`); -if ( - shell.exec("git checkout origin/gh-pages").code + +if (shell.exec("git checkout origin/gh-pages").code !== 0) { + if (shell.exec("git checkout --orphan gh-pages").code !== 0) { + shell.echo("Error: Git checkout gh-pages failed"); + shell.exit(1); + } +} else { + if ( shell.exec("git checkout -b gh-pages").code + - shell.exec("git branch --set-upstream-to=origin/gh-pages").code !== - 0 -) { - shell.echo("Error: Git checkout gh-pages failed"); - shell.exit(1); + shell.exec("git branch --set-upstream-to=origin/gh-pages").code !== + 0 + ) { + shell.echo("Error: Git checkout gh-pages failed"); + shell.exit(1); + } } -shell.exec("rm -rf *"); +shell.exec("git rm -rf ."); shell.cd("../..");