gitCommitFile writes a file and commits it, returning after the commit lands.
(t *testing.T, dir, name, content, msg string)
| 39 | |
| 40 | // gitCommitFile writes a file and commits it, returning after the commit lands. |
| 41 | func gitCommitFile(t *testing.T, dir, name, content, msg string) { |
| 42 | t.Helper() |
| 43 | if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil { |
| 44 | t.Fatalf("write %s: %v", name, err) |
| 45 | } |
| 46 | for _, args := range [][]string{{"add", "."}, {"commit", "-m", msg}} { |
| 47 | cmd := exec.Command("git", append([]string{"-C", dir}, args...)...) |
| 48 | if out, err := cmd.CombinedOutput(); err != nil { |
| 49 | t.Fatalf("git %v: %v: %s", args, err, out) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // silenceStdout redirects os.Stdout to /dev/null for the duration of fn so the |
| 55 | // delegate commands' Printf output does not clutter test logs. |
no outgoing calls
no test coverage detected