Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func (r *Repository) addNonBinaryFiles(ctx context.Context, worktreePath string,
} else if !r.isBinaryFile(worktreePath, fileName) {
// Untracked file - add if not binary

_, err = RunGitCommand(ctx, worktreePath, "add", fileName)
_, err = RunGitCommand(ctx, worktreePath, "add", "--", fileName)
if err != nil {
return err
}
Expand All @@ -694,14 +694,14 @@ func (r *Repository) addNonBinaryFiles(ctx context.Context, worktreePath string,
continue
case indexStatus == 'D' || workTreeStatus == 'D':
// D = deleted files (always stage deletion)
_, err = RunGitCommand(ctx, worktreePath, "add", fileName)
_, err = RunGitCommand(ctx, worktreePath, "add", "--", fileName)
if err != nil {
return err
}
default:
// M, R, C and other statuses - add if not binary
if !r.isBinaryFile(worktreePath, fileName) {
_, err = RunGitCommand(ctx, worktreePath, "add", fileName)
_, err = RunGitCommand(ctx, worktreePath, "add", "--", fileName)
if err != nil {
return err
}
Expand Down Expand Up @@ -798,7 +798,7 @@ func (r *Repository) addFilesFromUntrackedDirectory(ctx context.Context, worktre
}

if !r.isBinaryFile(worktreePath, relPath) {
_, err = RunGitCommand(ctx, worktreePath, "add", relPath)
_, err = RunGitCommand(ctx, worktreePath, "add", "--", relPath)
if err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions repository/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ func TestSelectiveFileStaging(t *testing.T) {
shouldSkip: []string{"node_modules", "build"},
reason: "Dependencies and build outputs should be excluded",
},
{
name: "file_named_like_a_git_option",
setup: func(t *testing.T, dir string) {
writeFile(t, dir, "--all", "poc")
writeFile(t, dir, "bundle.zip", "archive")
},
shouldStage: []string{"--all"},
shouldSkip: []string{"bundle.zip"},
reason: "A file named --all must be staged as a path, not as git add --all",
},
{
name: "directory_named_like_a_git_option",
setup: func(t *testing.T, dir string) {
createDir(t, dir, "--dry-run")
writeFile(t, dir, "--dry-run/notes.txt", "notes")
},
shouldStage: []string{"--dry-run/notes.txt"},
shouldSkip: []string{},
reason: "Paths under a directory named like an option must reach git as paths",
},
}

for _, scenario := range scenarios {
Expand Down