Skip to content

Deploy command is not able to checkout deployment branch #5827

@sivapalan

Description

@sivapalan

🐛 Bug Report

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io
  • I have read the console error message carefully (if applicable)

Description

Shallow clone of repository (introduced in #5748) fetches the default branch only.

From Git - git-clone Documentation:

--depth <depth>
Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches.

This causes git checkout of the deployment branch to fail (with version 2.0.0-beta.8 of @docusaurus/core):

Cloning into '/tmp/my-docs-gh-pagesQ1g5AP'...
CMD: git clone --depth 1 ***github.com/my-org/my-docs.git /tmp/my-docs-gh-pagesQ1g5AP (code: 0)
main
error: pathspec 'origin/gh-pages' did not match any file(s) known to git
CMD: git checkout origin/gh-pages (code: 1)
CMD: git checkout --orphan gh-pages (code: 0)

As a result of this, the command will go on to attempt to force push the orphan branch, and thereby overwrite any existing commits on the deployment branch (unless there is a branch protection rule preventing force pushes, in which case the deployment will fail altogether).

Adding --no-single-branch to the command should solve this issue.

An alternative solution with --branch ${deploymentBranch} could probably also be used here.

Have you read the Contributing Guidelines on issues?

Yes.

Steps to reproduce

Deploy to GitHub Pages, and check the logs.

Expected behavior

Successful deployment and new commit pushed to existing deployment branch (without affecting old commits). Branch protection rule preventing force pushes should not be blocking this as the commit history should be linear.

Actual behavior

If the deployment branch has a branch protection rule preventing force pushes, the git push command will fail, and thereby also resulting in the deployment failing. Otherwise, the deployment will succeed, but the command will have overwritten any existing commits on that branch with a new single commit from the orphan branch that it has checked out.

Example with a branch protection rule on gh-pages branch preventing force pushes:

Cloning into '/tmp/my-docs-gh-pagesQ1g5AP'...
CMD: git clone --depth 1 ***github.com/my-org/my-docs.git /tmp/my-docs-gh-pagesQ1g5AP (code: 0)
main
error: pathspec 'origin/gh-pages' did not match any file(s) known to git
CMD: git checkout origin/gh-pages (code: 1)
CMD: git checkout --orphan gh-pages (code: 0)

...

CMD: git commit -m "Deploy website - based on 8ad7c4b52948f33859e5dc54b23a82b9eea9eccc" (code: 0)
remote: error: GH006: Protected branch update failed for refs/heads/gh-pages.        
remote: error: Cannot force-push to this protected branch        
To https://github.com/my-org/my-docs.git
 ! [remote rejected] gh-pages -> gh-pages (protected branch hook declined)
error: failed to push some refs to 'https://github.com/my-org/my-docs.git'
Error: Running "git push" command failed.
CMD: git push --force origin gh-pages (code: 1)

Your environment

  • Docusaurus version used: 2.0.0-beta.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its execution

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions