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

Function gitCommitFile

cmd/opencodereview/delegate_exec_test.go:41–52  ·  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

39
40// gitCommitFile writes a file and commits it, returning after the commit lands.
41func 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.

Calls

no outgoing calls

Tested by

no test coverage detected