initRepoWithCommit creates a real git repository with a single commit whose message is `message`, and returns the repo directory and the commit hash.
(t *testing.T, message string)
| 309 | // initRepoWithCommit creates a real git repository with a single commit whose |
| 310 | // message is `message`, and returns the repo directory and the commit hash. |
| 311 | func initRepoWithCommit(t *testing.T, message string) (string, string) { |
| 312 | t.Helper() |
| 313 | repo := t.TempDir() |
| 314 | run := func(args ...string) []byte { |
| 315 | cmd := exec.Command("git", args...) |
| 316 | cmd.Dir = repo |
| 317 | out, err := cmd.CombinedOutput() |
| 318 | if err != nil { |
| 319 | t.Fatalf("git %v failed: %v\n%s", args, err, out) |
| 320 | } |
| 321 | return out |
| 322 | } |
| 323 | run("init", "-q") |
| 324 | run("config", "user.email", "test@example.com") |
| 325 | run("config", "user.name", "Test") |
| 326 | run("config", "commit.gpgsign", "false") |
| 327 | if err := os.WriteFile(filepath.Join(repo, "file.txt"), []byte("hello\n"), 0o600); err != nil { |
| 328 | t.Fatalf("write file: %v", err) |
| 329 | } |
| 330 | run("add", ".") |
| 331 | run("commit", "-q", "-m", message) |
| 332 | hash := strings.TrimSpace(string(run("rev-parse", "HEAD"))) |
| 333 | return repo, hash |
| 334 | } |
| 335 | |
| 336 | // TestBackgroundFromCommitThenFile reproduces the resolution order used by |
| 337 | // runReview when --background-file is supplied but --background is not: the |
no test coverage detected