MCPcopy Create free account
hub / github.com/alibaba/open-code-review / gitCommitFile

Function gitCommitFile

cmd/opencodereview/delegate_exec_test.go:52–63  ·  view source on GitHub ↗

gitCommitFile writes a file and commits it, returning after the commit lands.

(t *testing.T, dir, name, content, msg string)

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected