Skip to content

Commit 831ce54

Browse files
committed
feat: traverse untracked files in git walker
Closes #557 Signed-off-by: Brian McGee <[email protected]>
1 parent 3ba936c commit 831ce54

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

cmd/root_test.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -1359,11 +1359,15 @@ func TestGit(t *testing.T) {
13591359
as.NoError(gitCmd.Run(), "failed to init git repository")
13601360

13611361
// run before adding anything to the index
1362+
// we should pick up untracked files since we use `git ls-files -o`
13621363
treefmt(t,
13631364
withConfig(configPath, cfg),
13641365
withNoError(t),
13651366
withStats(t, map[stats.Type]int{
1366-
stats.Traversed: 0,
1367+
stats.Traversed: 31,
1368+
stats.Matched: 31,
1369+
stats.Formatted: 31,
1370+
stats.Changed: 0,
13671371
}),
13681372
)
13691373

@@ -1377,14 +1381,13 @@ func TestGit(t *testing.T) {
13771381
withStats(t, map[stats.Type]int{
13781382
stats.Traversed: 31,
13791383
stats.Matched: 31,
1380-
stats.Formatted: 31,
1384+
stats.Formatted: 0,
13811385
stats.Changed: 0,
13821386
}),
13831387
)
13841388

1385-
// remove python directory from the index
1386-
gitCmd = exec.Command("git", "rm", "--cached", "python/*")
1387-
as.NoError(gitCmd.Run(), "failed to remove python directory from the index")
1389+
// remove python directory
1390+
as.NoError(os.RemoveAll(filepath.Join(tempDir, "python")), "failed to remove python directory")
13881391

13891392
// we should traverse and match against fewer files, but no formatting should occur as no formatting signatures
13901393
// are impacted
@@ -1411,8 +1414,8 @@ func TestGit(t *testing.T) {
14111414
withConfig(configPath, cfg),
14121415
withNoError(t),
14131416
withStats(t, map[stats.Type]int{
1414-
stats.Traversed: 79,
1415-
stats.Matched: 79,
1417+
stats.Traversed: 76,
1418+
stats.Matched: 76,
14161419
stats.Formatted: 49, // the echo formatter should only be applied to the new files
14171420
stats.Changed: 0,
14181421
}),

walk/git.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func (g *GitReader) Read(ctx context.Context, files []*File) (n int, err error)
3838
r, w := io.Pipe()
3939

4040
// create a command which will execute from the specified sub path within root
41-
cmd := exec.Command("git", "ls-files")
41+
// we pass `-c` to pick up any files in the git index (this is the default ls-files behaviour)
42+
// we pass `-o` to pick up untracked files
43+
cmd := exec.Command("git", "ls-files", "-co")
4244
cmd.Dir = filepath.Join(g.root, g.path)
4345
cmd.Stdout = w
4446

0 commit comments

Comments
 (0)