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