docusaurus: gh_pages publish error

Environment

OS: ubuntu 17.10 Node: v6.11.4 npm: 5.6.0 yarn: 1.3.2 (OS, Node, npm, yarn)

Steps to Reproduce

  1. publish use local project to remote use : yarn run publish-gh-pages command, first time is ok, but when checkout the second time fail;

  2. error info shows:

    $ docusaurus-publish master generate.js triggered… feed.js triggered… feed.js triggered… Site built successfully. Generated files in ‘build’ folder. Cloning into ‘fartpig.github.io-master’… git clone ok Note: checking out ‘origin/master’.

    You are in ‘detached HEAD’ state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

    If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b <new-branch-name>

    HEAD is now at 254a030… Delete CNAME fatal: A branch named ‘master’ already exists. fatal: could not set upstream of HEAD to origin/master when it does not point to any branch. Error: Git checkout master failed error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

  3. when i git log the branch , they has the same SHA code between the detached commit and master branch.

When I note the code :

if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
  if (shell.exec(`git checkout --orphan ${DEPLOYMENT_BRANCH}`).code !== 0) {
    shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
    shell.exit(1);
  }
} else {
  if (
    shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +
      shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)
        .code !==
    0
  ) {
    shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
    shell.exit(1);
  }
}

in docusaurus-publish.js , then it works. I thinks this should have a branch check before operation.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (15 by maintainers)

Most upvoted comments

HI @wang701 I just published to my user site. You need to make sure you set the branch to source when you publish:

e.g, my command was:

GIT_USER=JoelMarcey CURRENT_BRANCH=source USE_SSH=true yarn run publish-gh-pages

Also make sure you have the right settings in your siteConfig.js for your project and org. e.g., mine is:

url: 'https://JoelMarcey.github.io' /* your website url */,
baseUrl: '/' /* base url for your project */,
projectName: 'JoelMarcey.github.io',
organizationName: 'JoelMarcey',

Let me know if this helps you.

Given that #716 gives the correct error message and I see Docusaurus also supports deploying user or organization sites. These sites will be served from the master branch of the repo. So, you will want to have the Docusaurus infra, your docs, etc. in another branch (e.g., maybe call it source). To do this, just set projectName to "username.github.io" (where username is your username or organization name on GitHub) and organizationName to "username". The publish script will automatically deploy your site to the root of the master branch to be served. At https://docusaurus.io/docs/en/publishing.html#using-github-pages

I think less user will find this error. Should we close this @joelmarcey @yangshun?

@wang701 Would you be keen to create a PR to update the documentation?

@JoelMarcey 's solution work for me, but I need to remove my master branch and set default branch to source.

@JoelMarcey I looked into publish-gh-pages.js again. For this particular block,

if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {        
  if (shell.exec(`git checkout --orphan ${DEPLOYMENT_BRANCH}`).code !== 0) {    
    shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);              
    shell.exit(1);                                                              
  }                                                                             
} else {                                                                        
  if (                                                                          
    shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +                   
      shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)    
        .code !==                                                               
    0                                                                           
  ) {                                                                           
    shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);              
    shell.exit(1);                                                              
  }                                                                             
}

It means that if the first git checkout origin/${DEPLOYMENT_BRANCH} return code is 0, the script goes to the else block and tries to make a another ${DEPLOYMENT_BRANCH} branch which causes the error @t3573393 and I are experiencing. I am confused by code in the else block.

My rewrite is this:

if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {        
  if (shell.exec(`git checkout --orphan ${DEPLOYMENT_BRANCH}`).code !== 0) {    
    shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);              
    shell.exit(1);                                                              
  }                                                                             
  if (                                                                          
    shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +                   
      shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)    
        .code !==                                                               
    0                                                                           
  ) {                                                                           
    shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);              
    shell.exit(1);                                                              
  }                                                                             
} 

And it works for me.