Skip to content
Closed
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
1 change: 0 additions & 1 deletion internal/scan/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ func (p *Provider) gitLs(ctx context.Context, args ...string) ([]string, error)
raw := strings.Split(strings.TrimRight(out, "\x00"), "\x00")
files := make([]string, 0, len(raw))
for _, f := range raw {
f = strings.TrimSpace(f)
if f != "" {
files = append(files, f)
}
Expand Down
27 changes: 27 additions & 0 deletions internal/scan/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"reflect"
"runtime"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -175,6 +176,32 @@ func TestProvider_Enumerate_FullRepo(t *testing.T) {
}
}

func TestProvider_Enumerate_PreservesWhitespacePaths(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Windows filenames cannot end with spaces")
}

repo := initTestRepo(t)
writeFile(t, repo, " leading.go", []byte("package leading\n"))
writeFile(t, repo, "trailing.go ", []byte("package trailing\n"))
gitCommit(t, repo, "add whitespace paths")

got, err := NewProvider(repo, nil, nil, 0).Enumerate(context.Background())
if err != nil {
t.Fatalf("Enumerate: %v", err)
}

paths := make([]string, 0, len(got))
for _, item := range got {
paths = append(paths, item.Path)
}
sort.Strings(paths)
want := []string{" leading.go", "trailing.go "}
if !reflect.DeepEqual(paths, want) {
t.Errorf("paths = %q, want %q", paths, want)
}
}

func TestProvider_Enumerate_NonGitDirectory(t *testing.T) {
// Plain temp dir — no `git init`. Walker fallback should kick in.
repo := t.TempDir()
Expand Down
Loading