(t *testing.T)
| 148 | } |
| 149 | |
| 150 | func TestScanRespectsGitignore(t *testing.T) { |
| 151 | t.Parallel() |
| 152 | |
| 153 | repoDir := initTestRepo(t) |
| 154 | logger := slogtest.Make(t, nil) |
| 155 | |
| 156 | // Add a .gitignore that ignores *.log files and the build/ directory. |
| 157 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, ".gitignore"), []byte("*.log\nbuild/\n"), 0o600)) |
| 158 | gitCmd(t, repoDir, "add", ".gitignore") |
| 159 | gitCmd(t, repoDir, "commit", "-m", "add gitignore") |
| 160 | |
| 161 | // Create unstaged files: two normal, three matching gitignore patterns. |
| 162 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "main.go"), []byte("package main\n"), 0o600)) |
| 163 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "util.go"), []byte("package util\n"), 0o600)) |
| 164 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "debug.log"), []byte("some log output\n"), 0o600)) |
| 165 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "error.log"), []byte("some error\n"), 0o600)) |
| 166 | require.NoError(t, os.MkdirAll(filepath.Join(repoDir, "build"), 0o700)) |
| 167 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "build", "output.bin"), []byte("binary\n"), 0o600)) |
| 168 | |
| 169 | h := agentgit.NewHandler(logger) |
| 170 | h.Subscribe([]string{filepath.Join(repoDir, "main.go")}) |
| 171 | |
| 172 | ctx := context.Background() |
| 173 | msg := h.Scan(ctx) |
| 174 | require.NotNil(t, msg) |
| 175 | require.Len(t, msg.Repositories, 1) |
| 176 | |
| 177 | diff := msg.Repositories[0].UnifiedDiff |
| 178 | |
| 179 | // The non-ignored files should appear in the diff. |
| 180 | assert.Contains(t, diff, "main.go") |
| 181 | assert.Contains(t, diff, "util.go") |
| 182 | // The gitignored files must not appear in the diff. |
| 183 | assert.NotContains(t, diff, "debug.log") |
| 184 | assert.NotContains(t, diff, "error.log") |
| 185 | assert.NotContains(t, diff, "output.bin") |
| 186 | } |
| 187 | |
| 188 | func TestScanRespectsGitignoreNestedNegation(t *testing.T) { |
| 189 | t.Parallel() |
nothing calls this directly
no test coverage detected