返回 DeepSeek-Reasonix
workspace_partial_clone_test.go
根目录 / desktop / workspace_partial_clone_test.go
1 package main
2
3 import (
4 "errors"
5 "os"
6 "os/exec"
7 "path/filepath"
8 "testing"
9
10 "reasonix/internal/gitcmd"
11 )
12
13 // partialClone returns a blob-filtered clone of a three-commit repository, so
14 // the blobs of every commit but the checked-out one are absent locally.
15 func partialClone(t *testing.T) string {
16 t.Helper()
17 if _, err := exec.LookPath("git"); err != nil {
18 t.Skip("git not installed")
19 }
20 src := t.TempDir()
21 run := func(dir string, args ...string) {
22 t.Helper()
23 cmd := exec.Command("git", append([]string{"-C", dir}, args...)...)
24 cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@t", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@t")
25 if out, err := cmd.CombinedOutput(); err != nil {
26 t.Fatalf("git %v: %v\n%s", args, err, out)
27 }
28 }
29 run(src, "init", "-q")
30 for _, body := range []string{"1\n", "2\n", "3\n"} {
31 if err := os.WriteFile(filepath.Join(src, "a.txt"), []byte(body), 0o644); err != nil {
32 t.Fatal(err)
33 }
34 run(src, "add", "a.txt")
35 run(src, "commit", "-q", "-m", body)
36 }
37 run(src, "config", "uploadpack.allowFilter", "true")
38 clone := filepath.Join(t.TempDir(), "partial")
39 run(src, "clone", "-q", "--filter=blob:none", "file://"+src, clone)
40 return clone
41 }
42
43 // A historical patch in a partial clone fails with an error naming the
44 // unfetched objects, which the commit-detail view can tell from other failures.
45 func TestCommitDetailInPartialCloneReportsObjectNotLocal(t *testing.T) {
46 clone := partialClone(t)
47 out, err := workspaceGit(openWorkspaceRepo(clone), "-C", clone, "show", "--pretty=format:", "--patch", "HEAD~1", "--", "a.txt").Output()
48 if err == nil {
49 t.Fatalf("show of an unfetched commit succeeded: %s", out)
50 }
51 if got := notLocalOr(openWorkspaceRepo(clone), "HEAD~1", err); !errors.Is(got, gitcmd.ErrObjectNotLocal) {
52 t.Fatalf("notLocalOr = %v, want ErrObjectNotLocal", got)
53 }
54 other := errors.New("other")
55 if got := notLocalOr(openWorkspaceRepo(clone), "no-such-rev", other); !errors.Is(got, other) {
56 t.Fatalf("notLocalOr(no-such-rev) = %v, want the original error passed through", got)
57 }
58 }
59
59 lines GO