返回 DeepSeek-Reasonix
gitcmd_worktree_test.go
根目录 / internal / gitcmd / gitcmd_worktree_test.go
1 package gitcmd
2
3 import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "slices"
8 "testing"
9 )
10
11 func TestLocalFilterDriversReadsRealLinkedWorktreeConfigs(t *testing.T) {
12 if _, err := exec.LookPath("git"); err != nil {
13 t.Skip("git not installed")
14 }
15 main := t.TempDir()
16 linked := filepath.Join(t.TempDir(), "linked")
17 run := func(dir string, args ...string) {
18 t.Helper()
19 cmdArgs := append([]string{"-C", dir}, args...)
20 if out, err := exec.Command("git", cmdArgs...).CombinedOutput(); err != nil {
21 t.Fatalf("git %v: %v: %s", args, err, out)
22 }
23 }
24 run(main, "init", "--quiet")
25 if err := os.WriteFile(filepath.Join(main, "tracked.txt"), []byte("initial\n"), 0o600); err != nil {
26 t.Fatal(err)
27 }
28 run(main, "add", "tracked.txt")
29 run(main, "-c", "user.name=Reasonix Test", "-c", "user.email=reasonix@example.invalid", "commit", "--quiet", "-m", "initial")
30 run(main, "config", "extensions.worktreeConfig", "true")
31 run(main, "config", "filter.common.process", "malicious-process")
32 run(main, "worktree", "add", "--quiet", "--detach", linked, "HEAD")
33 run(linked, "config", "--worktree", "filter.local.clean", "malicious-clean")
34
35 want := []string{"common", "local"}
36 if got := localFilterDrivers(linked); !slices.Equal(got, want) {
37 t.Fatalf("localFilterDrivers(real linked worktree) = %v, want %v", got, want)
38 }
39 args := argsFor("linux", linked, nil, "diff", "HEAD")
40 for _, cfg := range []string{"filter.common.process=", "filter.local.process="} {
41 if !hasConfig(args, cfg) {
42 t.Fatalf("linked worktree diff args = %v, want -c %s", args, cfg)
43 }
44 }
45 }
46
46 lines GO