Skip to content

fix(repository): pass file names to git add after -- - #373

Open
Bortlesboat wants to merge 1 commit into
dagger:mainfrom
Bortlesboat:fix/git-add-path-terminator
Open

fix(repository): pass file names to git add after --#373
Bortlesboat wants to merge 1 commit into
dagger:mainfrom
Bortlesboat:fix/git-add-path-terminator

Conversation

@Bortlesboat

Copy link
Copy Markdown

Fixes #354.

addNonBinaryFiles and addFilesFromUntrackedDirectory pass each path straight to git add, so a name starting with - is parsed as an option. A file named --all turns the call into git add --all and stages the whole worktree, including files the skip rules are meant to leave out. A directory named like an option makes the add fail outright (error: unknown option), which fails the commit.

This puts -- before the path in all four git add calls.

Tests: two new scenarios in TestSelectiveFileStaging, a file named --all next to a .zip that should stay untracked, and a file under a directory named --dry-run. Without the change the first stages bundle.zip and the second errors with unknown option; with it both pass.

go test -short ./repository/ passes on Linux, and gofmt -l and go vet are clean.

A path starting with "-" was parsed as a git add option: a file named
--all staged the whole worktree, and a directory named like an option
made the add fail. Terminate options before every path.

Fixes dagger#354
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.

[Bug]: Git option injection via flag-like filenames

1 participant