Skip to content

fix: reject remote names starting with '-' - #95

Merged
him0 merged 1 commit into
mainfrom
fix/reject-dash-remote-names
Nov 20, 2026
Merged

him0 merged 1 commit into
mainfrom
fix/reject-dash-remote-names

Conversation

@him0

@him0 him0 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Problem

fetchRemote runs git fetch --prune --quiet --progress <name> without a --. Remote names come from git remote -v (that is, .git/config) and from --remote, and git accepts a remote named like --upload-pack=/path/to/script (git remote add -- <name> <url>). git fetch then reads the name as an option and runs the script. Exploiting this needs write access to .git/config, so the severity is low, but the other places that pass outside values to a command are already guarded (ssh -G --, worktree remove --, the - check on headRefOid).

Fix

A remote name starting with - is never passed to git. --end-of-options is not used because it needs git 2.24 and gh-sync supports git 2.23.

  • Main remote (automatically chosen or given with --remote): gh-sync stops with fatal: remote name '<name>' starts with '-' before anything is fetched.
  • Another remote that a branch tracks: fetchRemote itself refuses the name, so it is handled exactly like a remote that can't be fetched: a warning, the branches tracking it are skipped, the main remote's branches are still synced, and the exit status is 1. I chose this over failing the whole run because it is what already happens when one of these remotes is broken, and one bad branch.<name>.remote should not stop the unrelated branches from syncing. The non-zero exit status still makes it noticeable.

The check lives in fetchRemote, the only place a bare remote name is an argument to git, so a future caller is covered too. The other uses of a remote name were reviewed: they are all prefixed (refs/remotes/<name>/... in symbolic-ref, show-ref, for-each-ref, checkout --track, merge, branch -f) or only appear in messages.

README is not changed: the documented behavior ("Branches tracking a remote that can't be fetched are skipped with a warning") still holds, and this only adds an error for names no normal setup has.

Testing

  • New TestRunRejectsDashRemoteNames: main remote given with --remote, main remote chosen automatically, and a remote tracked by a branch. The --remote and tracked-remote cases were seen to reach git (which tried to run the named command) before the fix.
  • mise run test and mise run lint pass locally on Linux with git 2.34.1. Windows and macOS were not run locally; CI covers them.
  • Manual check with built binaries in a temporary repository having a remote named --upload-pack=<script that writes a marker file>: the binary built from main ran the script both with --remote=<name> and when a branch tracked that remote; the binary from this branch did not run it in either case and printed the messages above.

🤖 Generated with Claude Code

git fetch was given the remote name without a "--", and git allows a
remote named like "--upload-pack=<command>", so fetching it ran that
command. Such a name is now never passed to git: as the main remote it
is a fatal error before anything is fetched, and as another remote a
branch tracks it is handled like a remote that can't be fetched (a
warning, and the branches tracking it are skipped).

--end-of-options is not used because it needs git 2.24 and gh-sync
supports git 2.23.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14a4b18e-4b3a-40ef-89f0-f5b3bdf8acc6
Commits

Reviewing files that changed from the base of the PR and between 03e2162 and 28c30e4.

Files selected for processing: 2

  • main.go
  • main_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@him0
him0 merged commit 78571a4 into main Nov 20, 2026
6 checks passed
@him0
him0 deleted the fix/reject-dash-remote-names branch November 20, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant