Skip to content

Command fails if remote file starting with '-' exists #592

@sherlockdoyle

Description

@sherlockdoyle

Summary

The gh-pages library fails when deploying if a file in the gh-pages branch of the remote repository has a name starting with a - (dash). This happens because git rm interprets such filenames as options rather than file paths.

Steps to Reproduce

  1. Clone the example repository:
    git clone https://github.com/sherlockdoyle/gh-pages-bug-demo
    
  2. Navigate into the repository:
    cd gh-pages-bug-demo
    
  3. Install dependencies:
    npm install
    
  4. Deploy using gh-pages:
    npm run deploy
    

Expected Behavior

The gh-pages command should correctly handle files with names starting with a - (dash) and deploy successfully.

Actual Behavior

The deployment fails with the following error:

ProcessError: error: unknown switch `t'
usage: git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
              [--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]
              [--] [<pathspec>...]

The file -test.js in the gh-pages branch causes git rm to interpret -t as an invalid option.

Root Cause

The issue arises because git rm is called without properly escaping filenames. Files starting with a - are treated as command-line options by Git instead of file paths.

Suggested Fix

Use -- to signal the end of command options in the git rm command. For example:

git rm -- <filename>

This ensures Git treats -test.js as a file name rather than an option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions