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

Function gitCommitFile

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

13
14// gitCommitFile writes a file and commits it, returning after the commit lands.
15func gitCommitFile(t *testing.T, dir, name, content, msg string) {
16 t.Helper()
17 if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil {
18 t.Fatalf("write %s: %v", name, err)
19 }
20 for _, args := range [][]string{{"add", "."}, {"commit", "-m", msg}} {
21 cmd := exec.Command("git", append([]string{"-C", dir}, args...)...)
22 if out, err := cmd.CombinedOutput(); err != nil {
23 t.Fatalf("git %v: %v: %s", args, err, out)
24 }
25 }
26}
27
28// silenceStdout redirects os.Stdout to /dev/null for the duration of fn so the
29// delegate commands' Printf output does not clutter test logs.

Callers 5

TestRunScanPreviewFunction · 0.85
TestRunPreviewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected