Fast implementation of Git in pure Go

Revert "test: Make gitCmd accept an stdin []byte"

This reverts commit f762271dbfc121eaac7eb59c0beb01620a09118f.

runxiyu.tngl.sh e0e56e63 b140f267

verified
+239 -213
+38 -38
commitgraph_read_test.go
··· 28 28 if err := os.WriteFile(path, []byte(content), 0o644); err != nil { 29 29 t.Fatalf("write %s: %v", name, err) 30 30 } 31 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 32 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("commit %d", i)) 31 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 32 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("commit %d", i)) 33 33 } 34 34 35 - gitCmd(t, repoPath, nil, "repack", "-a", "-d") 36 - gitCmd(t, repoPath, nil, "commit-graph", "write", "--reachable", "--changed-paths") 35 + gitCmd(t, repoPath, "repack", "-a", "-d") 36 + gitCmd(t, repoPath, "commit-graph", "write", "--reachable", "--changed-paths") 37 37 38 38 repo, err := OpenRepository(repoPath) 39 39 if err != nil { ··· 46 46 t.Fatalf("CommitGraph failed: %v", err) 47 47 } 48 48 49 - revList := gitCmd(t, repoPath, nil, "rev-list", "--all") 49 + revList := gitCmd(t, repoPath, "rev-list", "--all") 50 50 commits := strings.Fields(revList) 51 51 if len(commits) == 0 { 52 52 t.Fatal("no commits found") ··· 67 67 t.Fatalf("CommitAt failed: %v", err) 68 68 } 69 69 70 - treeStr := string(gitCmd(t, repoPath, nil, "show", "-s", "--format=%T", oidStr)) 70 + treeStr := string(gitCmd(t, repoPath, "show", "-s", "--format=%T", oidStr)) 71 71 tree, err := repo.ParseHash(treeStr) 72 72 if err != nil { 73 73 t.Fatalf("ParseHash tree failed: %v", err) ··· 76 76 t.Fatalf("tree mismatch for %s: got %s want %s", oidStr, cc.Tree.String(), tree.String()) 77 77 } 78 78 79 - parentStr := string(gitCmd(t, repoPath, nil, "show", "-s", "--format=%P", oidStr)) 79 + parentStr := string(gitCmd(t, repoPath, "show", "-s", "--format=%P", oidStr)) 80 80 parents := strings.Fields(parentStr) 81 81 if len(parents) != len(cc.Parents) { 82 82 t.Fatalf("parent count mismatch for %s: got %d want %d", oidStr, len(cc.Parents), len(parents)) ··· 95 95 } 96 96 } 97 97 98 - ctStr := gitCmd(t, repoPath, nil, "show", "-s", "--format=%ct", oidStr) 98 + ctStr := gitCmd(t, repoPath, "show", "-s", "--format=%ct", oidStr) 99 99 ct, err := strconv.ParseInt(ctStr, 10, 64) 100 100 if err != nil { 101 101 t.Fatalf("parse commit time: %v", err) ··· 104 104 t.Fatalf("commit time mismatch for %s: got %d want %d", oidStr, cc.CommitTime, ct) 105 105 } 106 106 107 - changed := gitCmd(t, repoPath, nil, "diff-tree", "--no-commit-id", "--name-only", "-r", "--root", oidStr) 107 + changed := gitCmd(t, repoPath, "diff-tree", "--no-commit-id", "--name-only", "-r", "--root", oidStr) 108 108 for _, path := range strings.Fields(changed) { 109 109 if path == "" { 110 110 continue ··· 126 126 workDir, cleanupWork := setupWorkDir(t) 127 127 defer cleanupWork() 128 128 129 - gitCmd(t, workDir, nil, "init") 129 + gitCmd(t, workDir, "init") 130 130 131 131 if err := os.WriteFile(filepath.Join(workDir, "base.txt"), []byte("base\n"), 0o644); err != nil { 132 132 t.Fatalf("write base: %v", err) 133 133 } 134 - gitCmd(t, workDir, nil, "add", ".") 135 - gitCmd(t, workDir, nil, "commit", "-m", "base") 134 + gitCmd(t, workDir, "add", ".") 135 + gitCmd(t, workDir, "commit", "-m", "base") 136 136 137 - gitCmd(t, workDir, nil, "checkout", "-b", "branch1") 137 + gitCmd(t, workDir, "checkout", "-b", "branch1") 138 138 if err := os.WriteFile(filepath.Join(workDir, "b1.txt"), []byte("b1\n"), 0o644); err != nil { 139 139 t.Fatalf("write b1: %v", err) 140 140 } 141 - gitCmd(t, workDir, nil, "add", ".") 142 - gitCmd(t, workDir, nil, "commit", "-m", "b1") 141 + gitCmd(t, workDir, "add", ".") 142 + gitCmd(t, workDir, "commit", "-m", "b1") 143 143 144 - gitCmd(t, workDir, nil, "checkout", "master") 145 - gitCmd(t, workDir, nil, "checkout", "-b", "branch2") 144 + gitCmd(t, workDir, "checkout", "master") 145 + gitCmd(t, workDir, "checkout", "-b", "branch2") 146 146 if err := os.WriteFile(filepath.Join(workDir, "b2.txt"), []byte("b2\n"), 0o644); err != nil { 147 147 t.Fatalf("write b2: %v", err) 148 148 } 149 - gitCmd(t, workDir, nil, "add", ".") 150 - gitCmd(t, workDir, nil, "commit", "-m", "b2") 149 + gitCmd(t, workDir, "add", ".") 150 + gitCmd(t, workDir, "commit", "-m", "b2") 151 151 152 - gitCmd(t, workDir, nil, "checkout", "master") 153 - gitCmd(t, workDir, nil, "checkout", "-b", "branch3") 152 + gitCmd(t, workDir, "checkout", "master") 153 + gitCmd(t, workDir, "checkout", "-b", "branch3") 154 154 if err := os.WriteFile(filepath.Join(workDir, "b3.txt"), []byte("b3\n"), 0o644); err != nil { 155 155 t.Fatalf("write b3: %v", err) 156 156 } 157 - gitCmd(t, workDir, nil, "add", ".") 158 - gitCmd(t, workDir, nil, "commit", "-m", "b3") 157 + gitCmd(t, workDir, "add", ".") 158 + gitCmd(t, workDir, "commit", "-m", "b3") 159 159 160 - gitCmd(t, workDir, nil, "checkout", "master") 161 - gitCmd(t, workDir, nil, "merge", "--no-ff", "-m", "octopus", "branch1", "branch2", "branch3") 160 + gitCmd(t, workDir, "checkout", "master") 161 + gitCmd(t, workDir, "merge", "--no-ff", "-m", "octopus", "branch1", "branch2", "branch3") 162 162 163 - gitCmd(t, workDir, nil, "repack", "-a", "-d") 164 - gitCmd(t, workDir, nil, "commit-graph", "write", "--reachable") 163 + gitCmd(t, workDir, "repack", "-a", "-d") 164 + gitCmd(t, workDir, "commit-graph", "write", "--reachable") 165 165 166 166 repo, err := OpenRepository(filepath.Join(workDir, ".git")) 167 167 if err != nil { ··· 174 174 t.Fatalf("CommitGraph failed: %v", err) 175 175 } 176 176 177 - mergeHash := gitCmd(t, workDir, nil, "rev-parse", "HEAD") 177 + mergeHash := gitCmd(t, workDir, "rev-parse", "HEAD") 178 178 id, _ := repo.ParseHash(mergeHash) 179 179 pos, ok := cg.CommitPosition(id) 180 180 if !ok { ··· 184 184 if err != nil { 185 185 t.Fatalf("CommitAt failed: %v", err) 186 186 } 187 - parentStr := gitCmd(t, workDir, nil, "show", "-s", "--format=%P", mergeHash) 187 + parentStr := gitCmd(t, workDir, "show", "-s", "--format=%P", mergeHash) 188 188 parents := strings.Fields(parentStr) 189 189 if len(cc.Parents) != len(parents) { 190 190 t.Fatalf("octopus parent mismatch: got %d want %d", len(cc.Parents), len(parents)) ··· 203 203 if err := os.WriteFile(path, []byte(fmt.Sprintf("v%d\n", i)), 0o644); err != nil { 204 204 t.Fatalf("write %s: %v", path, err) 205 205 } 206 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 207 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("commit %d", i)) 206 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 207 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("commit %d", i)) 208 208 } 209 209 210 - gitCmd(t, repoPath, nil, "repack", "-a", "-d") 211 - gitCmd(t, repoPath, nil, "commit-graph", "write", "--reachable", "--changed-paths", "--split=no-merge") 210 + gitCmd(t, repoPath, "repack", "-a", "-d") 211 + gitCmd(t, repoPath, "commit-graph", "write", "--reachable", "--changed-paths", "--split=no-merge") 212 212 213 213 // more commits needed to get a split chain with base layer 214 214 for i := 5; i < 8; i++ { ··· 216 216 if err := os.WriteFile(path, []byte(fmt.Sprintf("v%d\n", i)), 0o644); err != nil { 217 217 t.Fatalf("write %s: %v", path, err) 218 218 } 219 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 220 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("commit %d", i)) 219 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 220 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("commit %d", i)) 221 221 } 222 - gitCmd(t, repoPath, nil, "repack", "-a", "-d") 223 - gitCmd(t, repoPath, nil, "commit-graph", "write", "--reachable", "--changed-paths", "--split=no-merge", "--append") 222 + gitCmd(t, repoPath, "repack", "-a", "-d") 223 + gitCmd(t, repoPath, "commit-graph", "write", "--reachable", "--changed-paths", "--split=no-merge", "--append") 224 224 225 225 repo, err := OpenRepository(repoPath) 226 226 if err != nil { ··· 242 242 if cg.numCommitsInBase == 0 { 243 243 t.Fatalf("expected non-zero base commit count") 244 244 } 245 - revList := gitCmd(t, repoPath, nil, "rev-list", "--max-parents=0", "HEAD") 245 + revList := gitCmd(t, repoPath, "rev-list", "--max-parents=0", "HEAD") 246 246 id, _ := repo.ParseHash(revList) 247 247 if _, ok := cg.CommitPosition(id); !ok { 248 248 t.Fatalf("base commit not found in commit-graph chain")
+12 -12
difftrees_test.go
··· 22 22 writeTestFile(t, filepath.Join(workDir, "treeB", "legacy.txt"), "legacy root\n") 23 23 writeTestFile(t, filepath.Join(workDir, "treeB", "sub", "retired.txt"), "retired\n") 24 24 25 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 26 - baseTreeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 25 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 26 + baseTreeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 27 27 28 28 writeTestFile(t, filepath.Join(workDir, "README.md"), "updated readme\n") 29 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "rm", "-f", "dir/file_a.txt") 29 + gitCmd(t, repoPath, "--work-tree="+workDir, "rm", "-f", "dir/file_a.txt") 30 30 writeTestFile(t, filepath.Join(workDir, "dir", "nested", "file_b.txt"), "beta v2\n") 31 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "rm", "-f", "dir/nested/deeper/old.txt") 31 + gitCmd(t, repoPath, "--work-tree="+workDir, "rm", "-f", "dir/nested/deeper/old.txt") 32 32 writeTestFile(t, filepath.Join(workDir, "dir", "nested", "deeper", "new.txt"), "new branch entry\n") 33 33 writeTestFile(t, filepath.Join(workDir, "dir", "nested", "deeper", "branch", "info.md"), "branch info\n") 34 34 writeTestFile(t, filepath.Join(workDir, "dir", "nested", "deeper", "branch", "subbranch", "leaf.txt"), "leaf data\n") 35 35 writeTestFile(t, filepath.Join(workDir, "dir", "nested", "deeper", "branch", "subbranch", "deep", "final.txt"), "final artifact\n") 36 36 writeTestFile(t, filepath.Join(workDir, "dir", "newchild.txt"), "brand new sibling\n") 37 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "rm", "-r", "-f", "treeB") 37 + gitCmd(t, repoPath, "--work-tree="+workDir, "rm", "-r", "-f", "treeB") 38 38 writeTestFile(t, filepath.Join(workDir, "features", "alpha", "README.md"), "alpha docs\n") 39 39 writeTestFile(t, filepath.Join(workDir, "features", "alpha", "beta", "gamma.txt"), "gamma payload\n") 40 40 writeTestFile(t, filepath.Join(workDir, "modules", "v2", "core", "main.go"), "package core\n") 41 41 writeTestFile(t, filepath.Join(workDir, "root_addition.txt"), "root level file\n") 42 42 43 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 44 - updatedTreeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 43 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 44 + updatedTreeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 45 45 46 46 repo, err := OpenRepository(repoPath) 47 47 if err != nil { ··· 108 108 writeTestFile(t, filepath.Join(workDir, "old_dir", "sub1", "legacy.txt"), "legacy path\n") 109 109 writeTestFile(t, filepath.Join(workDir, "old_dir", "sub1", "nested", "end.txt"), "legacy end\n") 110 110 111 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 112 - originalTreeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 111 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 112 + originalTreeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 113 113 114 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "rm", "-r", "-f", "old_dir") 114 + gitCmd(t, repoPath, "--work-tree="+workDir, "rm", "-r", "-f", "old_dir") 115 115 writeTestFile(t, filepath.Join(workDir, "fresh", "alpha", "beta", "new.txt"), "brand new directory\n") 116 116 writeTestFile(t, filepath.Join(workDir, "fresh", "alpha", "docs", "note.md"), "docs note\n") 117 117 writeTestFile(t, filepath.Join(workDir, "fresh", "alpha", "beta", "gamma", "delta.txt"), "delta payload\n") 118 118 119 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 120 - nextTreeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 119 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 120 + nextTreeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 121 121 122 122 repo, err := OpenRepository(repoPath) 123 123 if err != nil {
+18 -18
hybrid_test.go
··· 29 29 t.Fatalf("failed to create deep.txt: %v", err) 30 30 } 31 31 32 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 33 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 32 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 33 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 34 34 35 35 repo, err := OpenRepository(repoPath) 36 36 if err != nil { ··· 83 83 t.Fatalf("failed to create symlink: %v", err) 84 84 } 85 85 86 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 87 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 86 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 87 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 88 88 89 89 repo, err := OpenRepository(repoPath) 90 90 if err != nil { ··· 130 130 if err != nil { 131 131 t.Fatalf("failed to create %s: %v", filename, err) 132 132 } 133 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 134 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("Commit %d", i)) 135 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 133 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 134 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("Commit %d", i)) 135 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 136 136 commits = append(commits, commitHash) 137 137 } 138 138 ··· 185 185 if err != nil { 186 186 t.Fatalf("failed to create file.txt: %v", err) 187 187 } 188 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 189 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Tagged commit") 190 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 188 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 189 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Tagged commit") 190 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 191 191 192 192 tags := []string{"v1.0.0", "v1.0.1", "v1.1.0", "v2.0.0"} 193 193 for _, tagName := range tags { 194 - gitCmd(t, repoPath, nil, "tag", "-a", "-m", fmt.Sprintf("Release %s", tagName), tagName, commitHash) 194 + gitCmd(t, repoPath, "tag", "-a", "-m", fmt.Sprintf("Release %s", tagName), tagName, commitHash) 195 195 } 196 196 197 197 repo, err := OpenRepository(repoPath) ··· 203 203 }() 204 204 205 205 for _, tagName := range tags { 206 - tagHash := gitCmd(t, repoPath, nil, "rev-parse", tagName) 206 + tagHash := gitCmd(t, repoPath, "rev-parse", tagName) 207 207 hash, _ := repo.ParseHash(tagHash) 208 208 obj, err := repo.ReadObject(hash) 209 209 if err != nil { ··· 231 231 repoPath, cleanup := setupTestRepo(t) 232 232 defer cleanup() 233 233 234 - gitCmd(t, repoPath, nil, "config", "gc.auto", "0") 234 + gitCmd(t, repoPath, "config", "gc.auto", "0") 235 235 236 236 workDir, cleanupWork := setupWorkDir(t) 237 237 defer cleanupWork() ··· 241 241 if err != nil { 242 242 t.Fatalf("failed to create file%d.txt: %v", i, err) 243 243 } 244 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 245 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("Commit %d", i)) 246 - gitCmd(t, repoPath, nil, "repack", "-d") 244 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 245 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", fmt.Sprintf("Commit %d", i)) 246 + gitCmd(t, repoPath, "repack", "-d") 247 247 } 248 248 249 - gitCmd(t, repoPath, nil, "repack", "-a", "-d") 249 + gitCmd(t, repoPath, "repack", "-a", "-d") 250 250 251 251 repo, err := OpenRepository(repoPath) 252 252 if err != nil { ··· 256 256 _ = repo.Close() 257 257 }() 258 258 259 - headHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 259 + headHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 260 260 hash, _ := repo.ParseHash(headHash) 261 261 262 262 obj, err := repo.ReadObject(hash)
+11 -11
obj_commit_test.go
··· 87 87 if err != nil { 88 88 t.Fatalf("failed to write file.txt: %v", err) 89 89 } 90 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 91 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Test commit") 92 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 90 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 91 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Test commit") 92 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 93 93 94 94 repo, err := OpenRepository(repoPath) 95 95 if err != nil { ··· 135 135 if err != nil { 136 136 t.Fatalf("failed to write file1.txt: %v", err) 137 137 } 138 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 139 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "First commit") 140 - parent1Hash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 138 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 139 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "First commit") 140 + parent1Hash := gitCmd(t, repoPath, "rev-parse", "HEAD") 141 141 142 142 err = os.WriteFile(filepath.Join(workDir, "file2.txt"), []byte("content2"), 0o644) 143 143 if err != nil { 144 144 t.Fatalf("failed to write file2.txt: %v", err) 145 145 } 146 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 147 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Second commit") 148 - parent2Hash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 146 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 147 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Second commit") 148 + parent2Hash := gitCmd(t, repoPath, "rev-parse", "HEAD") 149 149 150 150 err = os.WriteFile(filepath.Join(workDir, "file3.txt"), []byte("content3"), 0o644) 151 151 if err != nil { 152 152 t.Fatalf("failed to write file3.txt: %v", err) 153 153 } 154 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 155 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 154 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 155 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 156 156 157 157 mergeCommitData := fmt.Sprintf("tree %s\nparent %s\nparent %s\nauthor Test Author <test@example.org> 1234567890 +0000\ncommitter Test Committer <committer@example.org> 1234567890 +0000\n\nMerge commit\n", 158 158 treeHash, parent1Hash, parent2Hash)
+11 -11
obj_tag_test.go
··· 19 19 if err != nil { 20 20 t.Fatalf("failed to write file.txt: %v", err) 21 21 } 22 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 23 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Tagged commit") 24 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 22 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 23 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Tagged commit") 24 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 25 25 26 26 repo, err := OpenRepository(repoPath) 27 27 if err != nil { ··· 90 90 if err != nil { 91 91 t.Fatalf("failed to write file.txt: %v", err) 92 92 } 93 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 94 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Commit for tag") 95 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 93 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 94 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Commit for tag") 95 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 96 96 97 - gitCmd(t, repoPath, nil, "tag", "-a", "-m", "Tag message", "v1.0.0", commitHash) 98 - tagHash := gitCmd(t, repoPath, nil, "rev-parse", "v1.0.0") 97 + gitCmd(t, repoPath, "tag", "-a", "-m", "Tag message", "v1.0.0", commitHash) 98 + tagHash := gitCmd(t, repoPath, "rev-parse", "v1.0.0") 99 99 100 100 repo, err := OpenRepository(repoPath) 101 101 if err != nil { ··· 136 136 if err != nil { 137 137 t.Fatalf("failed to write file.txt: %v", err) 138 138 } 139 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 140 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Commit") 141 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 139 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 140 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Commit") 141 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 142 142 143 143 repo, err := OpenRepository(repoPath) 144 144 if err != nil {
+11 -11
obj_tree_test.go
··· 39 39 t.Errorf("git type: got %q, want %q", gitType, "tree") 40 40 } 41 41 42 - gitLsTree := gitCmd(t, repoPath, nil, "ls-tree", treeHash.String()) 42 + gitLsTree := gitCmd(t, repoPath, "ls-tree", treeHash.String()) 43 43 if !strings.Contains(gitLsTree, "file.txt") { 44 44 t.Errorf("git ls-tree doesn't contain file.txt: %s", gitLsTree) 45 45 } ··· 68 68 t.Fatalf("failed to write c.txt: %v", err) 69 69 } 70 70 71 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 72 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 71 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 72 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 73 73 74 74 repo, err := OpenRepository(repoPath) 75 75 if err != nil { ··· 124 124 t.Fatalf("failed to write c.txt: %v", err) 125 125 } 126 126 127 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 128 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 127 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 128 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 129 129 130 130 repo, err := OpenRepository(repoPath) 131 131 if err != nil { ··· 175 175 t.Fatalf("failed to write dir/nested.txt: %v", err) 176 176 } 177 177 178 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 179 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 178 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 179 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 180 180 181 181 repo, err := OpenRepository(repoPath) 182 182 if err != nil { ··· 233 233 repoPath, cleanup := setupTestRepo(t) 234 234 defer cleanup() 235 235 236 - gitCmd(t, repoPath, nil, "config", "gc.auto", "0") 236 + gitCmd(t, repoPath, "config", "gc.auto", "0") 237 237 238 238 workDir, cleanupWork := setupWorkDir(t) 239 239 defer cleanupWork() ··· 248 248 } 249 249 } 250 250 251 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 252 - treeHash := gitCmd(t, repoPath, nil, "--work-tree="+workDir, "write-tree") 251 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 252 + treeHash := gitCmd(t, repoPath, "--work-tree="+workDir, "write-tree") 253 253 254 254 repo, err := OpenRepository(repoPath) 255 255 if err != nil { ··· 265 265 t.Errorf("tree entries: got %d, want %d", len(tree.Entries), numFiles) 266 266 } 267 267 268 - gitCount := gitCmd(t, repoPath, nil, "ls-tree", treeHash) 268 + gitCount := gitCmd(t, repoPath, "ls-tree", treeHash) 269 269 gitLines := strings.Count(gitCount, "\n") + 1 270 270 if len(tree.Entries) != gitLines { 271 271 t.Errorf("furgit found %d entries, git found %d", len(tree.Entries), gitLines)
+12 -12
packed_read_test.go
··· 13 13 repoPath, cleanup := setupTestRepo(t) 14 14 defer cleanup() 15 15 16 - gitCmd(t, repoPath, nil, "config", "gc.auto", "0") 16 + gitCmd(t, repoPath, "config", "gc.auto", "0") 17 17 18 18 workDir, cleanupWork := setupWorkDir(t) 19 19 defer cleanupWork() ··· 27 27 t.Fatalf("failed to write file2.txt: %v", err) 28 28 } 29 29 30 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 31 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Test commit") 32 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 30 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 31 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Test commit") 32 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 33 33 34 - gitCmd(t, repoPath, nil, "repack", "-a", "-d") 34 + gitCmd(t, repoPath, "repack", "-a", "-d") 35 35 36 36 repo, err := OpenRepository(repoPath) 37 37 if err != nil { ··· 64 64 t.Errorf("tree entries: got %d, want 2", len(tree.Entries)) 65 65 } 66 66 67 - gitLsTree := gitCmd(t, repoPath, nil, "ls-tree", commit.Tree.String()) 67 + gitLsTree := gitCmd(t, repoPath, "ls-tree", commit.Tree.String()) 68 68 for _, entry := range tree.Entries { 69 69 if !strings.Contains(gitLsTree, string(entry.Name)) { 70 70 t.Errorf("git ls-tree doesn't contain %s", entry.Name) ··· 80 80 repoPath, cleanup := setupTestRepo(t) 81 81 defer cleanup() 82 82 83 - gitCmd(t, repoPath, nil, "config", "gc.auto", "0") 83 + gitCmd(t, repoPath, "config", "gc.auto", "0") 84 84 85 85 workDir, cleanupWork := setupWorkDir(t) 86 86 defer cleanupWork() ··· 95 95 } 96 96 } 97 97 98 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 99 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Large commit") 100 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 98 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 99 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Large commit") 100 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 101 101 102 - gitCmd(t, repoPath, nil, "repack", "-a", "-d") 102 + gitCmd(t, repoPath, "repack", "-a", "-d") 103 103 104 104 repo, err := OpenRepository(repoPath) 105 105 if err != nil { ··· 118 118 t.Errorf("tree entries: got %d, want %d", len(tree.Entries), numFiles) 119 119 } 120 120 121 - gitCount := gitCmd(t, repoPath, nil, "ls-tree", commit.Tree.String()) 121 + gitCount := gitCmd(t, repoPath, "ls-tree", commit.Tree.String()) 122 122 gitLines := strings.Count(gitCount, "\n") + 1 123 123 if len(tree.Entries) != gitLines { 124 124 t.Errorf("furgit found %d entries, git found %d", len(tree.Entries), gitLines)
+54 -25
packed_write_test.go
··· 6 6 "encoding/binary" 7 7 "fmt" 8 8 "os" 9 + "os/exec" 9 10 "path/filepath" 10 11 "strings" 11 12 "testing" ··· 108 109 } 109 110 } 110 111 111 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 112 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Test commit") 113 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 112 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 113 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Test commit") 114 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 114 115 115 116 commitBody := gitCatFile(t, repoPath, "commit", commitHash) 116 117 lines := bytes.Split(commitBody, []byte{'\n'}) ··· 119 120 } 120 121 treeHash := strings.TrimSpace(string(bytes.TrimPrefix(lines[0], []byte("tree ")))) 121 122 122 - lsTree := gitCmd(t, repoPath, nil, "ls-tree", "-r", treeHash) 123 + lsTree := gitCmd(t, repoPath, "ls-tree", "-r", treeHash) 123 124 var blobHashes []string 124 125 for _, line := range strings.Split(lsTree, "\n") { 125 126 if line == "" { ··· 176 177 t.Fatalf("pack stream invalid: %v", err) 177 178 } 178 179 179 - _ = gitCmd(t, repoPath, nil, "index-pack", "-o", idxPath, packPath) 180 + cmd := exec.Command("git", "index-pack", "-o", idxPath, packPath) 181 + cmd.Dir = repoPath 182 + cmd.Env = append(os.Environ(), 183 + "GIT_CONFIG_GLOBAL=/dev/null", 184 + "GIT_CONFIG_SYSTEM=/dev/null", 185 + ) 186 + output, err := cmd.CombinedOutput() 187 + if err != nil { 188 + t.Fatalf("git index-pack failed: %v\n%s", err, output) 189 + } 180 190 181 - verifyOut := gitCmd(t, repoPath, nil, "verify-pack", "-v", idxPath) 191 + verifyOut := gitCmd(t, repoPath, "verify-pack", "-v", idxPath) 182 192 seen := make(map[string]struct{}) 183 193 for _, line := range strings.Split(verifyOut, "\n") { 184 194 if strings.TrimSpace(line) == "" { ··· 205 215 } 206 216 } 207 217 for _, oid := range expectedOids { 208 - _ = gitCmd(t, repoPath, nil, "cat-file", "-p", oid) 218 + _ = gitCmd(t, repoPath, "cat-file", "-p", oid) 209 219 } 210 220 211 - _ = gitCmd(t, repoPath, nil, "fsck", "--full", "--strict") 221 + _ = gitCmd(t, repoPath, "fsck", "--full", "--strict") 212 222 } 213 223 214 224 func TestPackWriteDeltas(t *testing.T) { ··· 233 243 } 234 244 } 235 245 236 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 237 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "Delta commit") 238 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 246 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 247 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "Delta commit") 248 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 239 249 240 250 commitBody := gitCatFile(t, repoPath, "commit", commitHash) 241 251 lines := bytes.Split(commitBody, []byte{'\n'}) ··· 244 254 } 245 255 treeHash := strings.TrimSpace(string(bytes.TrimPrefix(lines[0], []byte("tree ")))) 246 256 247 - lsTree := gitCmd(t, repoPath, nil, "ls-tree", "-r", treeHash) 257 + lsTree := gitCmd(t, repoPath, "ls-tree", "-r", treeHash) 248 258 var blobHashes []string 249 259 for _, line := range strings.Split(lsTree, "\n") { 250 260 if line == "" { ··· 304 314 t.Fatalf("pack stream invalid: %v", err) 305 315 } 306 316 307 - _ = gitCmd(t, repoPath, nil, "index-pack", "-o", idxPath, packPath) 317 + cmd := exec.Command("git", "index-pack", "-o", idxPath, packPath) 318 + cmd.Dir = repoPath 319 + cmd.Env = append(os.Environ(), 320 + "GIT_CONFIG_GLOBAL=/dev/null", 321 + "GIT_CONFIG_SYSTEM=/dev/null", 322 + ) 323 + output, err := cmd.CombinedOutput() 324 + if err != nil { 325 + t.Fatalf("git index-pack failed: %v\n%s", err, output) 326 + } 308 327 309 - verifyOut := gitCmd(t, repoPath, nil, "verify-pack", "-v", idxPath) 328 + verifyOut := gitCmd(t, repoPath, "verify-pack", "-v", idxPath) 310 329 seen := make(map[string]struct{}) 311 330 for _, line := range strings.Split(verifyOut, "\n") { 312 331 if strings.TrimSpace(line) == "" { ··· 333 352 } 334 353 } 335 354 for _, oid := range expectedOids { 336 - _ = gitCmd(t, repoPath, nil, "cat-file", "-p", oid) 355 + _ = gitCmd(t, repoPath, "cat-file", "-p", oid) 337 356 } 338 357 339 - _ = gitCmd(t, repoPath, nil, "fsck", "--full", "--strict") 358 + _ = gitCmd(t, repoPath, "fsck", "--full", "--strict") 340 359 } 341 360 342 361 func TestPackWriteThinPackReachable(t *testing.T) { ··· 350 369 if err := os.WriteFile(filepath.Join(workDir, "file.txt"), base, 0o644); err != nil { 351 370 t.Fatalf("write base file: %v", err) 352 371 } 353 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 354 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "base") 355 - haveHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 372 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 373 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "base") 374 + haveHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 356 375 357 376 mod := append([]byte(nil), base...) 358 377 mod[1024] = 'B' 359 378 if err := os.WriteFile(filepath.Join(workDir, "file.txt"), mod, 0o644); err != nil { 360 379 t.Fatalf("write mod file: %v", err) 361 380 } 362 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 363 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "target") 364 - wantHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 381 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 382 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "target") 383 + wantHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 365 384 366 385 repo, err := OpenRepository(repoPath) 367 386 if err != nil { ··· 404 423 _ = os.Remove(packPath) 405 424 _ = os.Remove(idxPath) 406 425 407 - _ = gitCmd(t, repoPath, buf.Bytes(), "index-pack", "--stdin", "--fix-thin", "-o", idxPath, packPath) 426 + cmd := exec.Command("git", "index-pack", "--stdin", "--fix-thin", "-o", idxPath, packPath) 427 + cmd.Dir = repoPath 428 + cmd.Env = append(os.Environ(), 429 + "GIT_CONFIG_GLOBAL=/dev/null", 430 + "GIT_CONFIG_SYSTEM=/dev/null", 431 + ) 432 + cmd.Stdin = bytes.NewReader(buf.Bytes()) 433 + output, err := cmd.CombinedOutput() 434 + if err != nil { 435 + t.Fatalf("git index-pack --fix-thin failed: %v\n%s", err, output) 436 + } 408 437 409 - _ = gitCmd(t, repoPath, nil, "cat-file", "-p", wantHash) 410 - _ = gitCmd(t, repoPath, nil, "fsck", "--full", "--strict") 438 + _ = gitCmd(t, repoPath, "cat-file", "-p", wantHash) 439 + _ = gitCmd(t, repoPath, "fsck", "--full", "--strict") 411 440 412 441 _ = os.Remove(packPath) 413 442 _ = os.Remove(idxPath)
+11 -11
reachability_test.go
··· 20 20 if err := os.WriteFile(path, []byte{byte('a' + i), '\n'}, 0o644); err != nil { 21 21 t.Fatalf("write file: %v", err) 22 22 } 23 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 24 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit") 25 - commits = append(commits, gitCmd(t, repoPath, nil, "rev-parse", "HEAD")) 23 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 24 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit") 25 + commits = append(commits, gitCmd(t, repoPath, "rev-parse", "HEAD")) 26 26 } 27 27 28 28 repo, err := OpenRepository(repoPath) ··· 97 97 if err := os.WriteFile(filepath.Join(workDir, "dir", "file2.txt"), []byte("two\n"), 0o644); err != nil { 98 98 t.Fatalf("write file2: %v", err) 99 99 } 100 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 101 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit") 100 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 101 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit") 102 102 103 103 repo, err := OpenRepository(repoPath) 104 104 if err != nil { ··· 106 106 } 107 107 defer func() { _ = repo.Close() }() 108 108 109 - head := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 109 + head := gitCmd(t, repoPath, "rev-parse", "HEAD") 110 110 wantID, _ := repo.ParseHash(head) 111 111 walk, err := repo.ReachableObjects(ReachabilityQuery{ 112 112 Wants: []Hash{wantID}, ··· 124 124 t.Fatalf("Reachability walk error: %v", err) 125 125 } 126 126 127 - treeStr := gitCmd(t, repoPath, nil, "show", "-s", "--format=%T", head) 127 + treeStr := gitCmd(t, repoPath, "show", "-s", "--format=%T", head) 128 128 treeID, _ := repo.ParseHash(treeStr) 129 - lsTree := gitCmd(t, repoPath, nil, "ls-tree", "-r", treeStr) 129 + lsTree := gitCmd(t, repoPath, "ls-tree", "-r", treeStr) 130 130 fields := strings.Fields(lsTree) 131 131 if len(fields) < 3 { 132 132 t.Fatalf("unexpected ls-tree output: %q", lsTree) ··· 157 157 if err := os.WriteFile(path, []byte{byte('a' + i), '\n'}, 0o644); err != nil { 158 158 t.Fatalf("write file: %v", err) 159 159 } 160 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 161 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit") 162 - commits = append(commits, gitCmd(t, repoPath, nil, "rev-parse", "HEAD")) 160 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 161 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit") 162 + commits = append(commits, gitCmd(t, repoPath, "rev-parse", "HEAD")) 163 163 } 164 164 165 165 repo, err := OpenRepository(repoPath)
+60 -60
refs_test.go
··· 18 18 if err != nil { 19 19 t.Fatalf("Failed to write test.txt: %v", err) 20 20 } 21 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 22 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "test") 23 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 24 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commitHash) 21 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 22 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "test") 23 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 24 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commitHash) 25 25 26 26 repo, err := OpenRepository(repoPath) 27 27 if err != nil { ··· 42 42 t.Errorf("resolved hash: got %s, want %s", resolved.Hash, hashObj) 43 43 } 44 44 45 - gitRevParse := gitCmd(t, repoPath, nil, "rev-parse", "refs/heads/main") 45 + gitRevParse := gitCmd(t, repoPath, "rev-parse", "refs/heads/main") 46 46 if resolved.Hash.String() != gitRevParse { 47 47 t.Errorf("furgit resolved %s, git resolved %s", resolved.Hash, gitRevParse) 48 48 } ··· 64 64 if err != nil { 65 65 t.Fatalf("failed to write test.txt: %v", err) 66 66 } 67 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 68 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "test") 69 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 70 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commitHash) 71 - gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main") 67 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 68 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "test") 69 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 70 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commitHash) 71 + gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main") 72 72 73 73 repo, err := OpenRepository(repoPath) 74 74 if err != nil { ··· 89 89 t.Errorf("HEAD symbolic ref: got %q, want %q", ref.Ref, "refs/heads/main") 90 90 } 91 91 92 - gitSymRef := gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD") 92 + gitSymRef := gitCmd(t, repoPath, "symbolic-ref", "HEAD") 93 93 if ref.Ref != gitSymRef { 94 94 t.Errorf("furgit resolved %v, git resolved %s", ref.Ref, gitSymRef) 95 95 } ··· 106 106 if err != nil { 107 107 t.Fatalf("failed to write test.txt: %v", err) 108 108 } 109 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 110 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit1") 111 - commit1Hash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 109 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 110 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit1") 111 + commit1Hash := gitCmd(t, repoPath, "rev-parse", "HEAD") 112 112 113 113 err = os.WriteFile(filepath.Join(workDir, "test2.txt"), []byte("content2"), 0o644) 114 114 if err != nil { 115 115 t.Fatalf("failed to write test2.txt: %v", err) 116 116 } 117 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 118 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit2") 119 - commit2Hash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 117 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 118 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit2") 119 + commit2Hash := gitCmd(t, repoPath, "rev-parse", "HEAD") 120 120 121 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/branch1", commit1Hash) 122 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/branch2", commit2Hash) 123 - gitCmd(t, repoPath, nil, "update-ref", "refs/tags/v1.0", commit1Hash) 121 + gitCmd(t, repoPath, "update-ref", "refs/heads/branch1", commit1Hash) 122 + gitCmd(t, repoPath, "update-ref", "refs/heads/branch2", commit2Hash) 123 + gitCmd(t, repoPath, "update-ref", "refs/tags/v1.0", commit1Hash) 124 124 125 - gitCmd(t, repoPath, nil, "pack-refs", "--all") 125 + gitCmd(t, repoPath, "pack-refs", "--all") 126 126 127 127 repo, err := OpenRepository(repoPath) 128 128 if err != nil { ··· 141 141 t.Errorf("branch1: got %s, want %s", resolved1.Hash, hash1) 142 142 } 143 143 144 - gitResolved1 := gitCmd(t, repoPath, nil, "rev-parse", "refs/heads/branch1") 144 + gitResolved1 := gitCmd(t, repoPath, "rev-parse", "refs/heads/branch1") 145 145 if resolved1.Hash.String() != gitResolved1 { 146 146 t.Errorf("furgit resolved %s, git resolved %s", resolved1.Hash, gitResolved1) 147 147 } ··· 175 175 if err != nil { 176 176 t.Fatalf("failed to write file.txt: %v", err) 177 177 } 178 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 179 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "init") 180 - commit := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 178 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 179 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "init") 180 + commit := gitCmd(t, repoPath, "rev-parse", "HEAD") 181 181 182 182 // Create two layers of symbolic refs 183 - gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/level1", "refs/heads/level2") 184 - gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/level2", "refs/heads/main") 185 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit) 183 + gitCmd(t, repoPath, "symbolic-ref", "refs/heads/level1", "refs/heads/level2") 184 + gitCmd(t, repoPath, "symbolic-ref", "refs/heads/level2", "refs/heads/main") 185 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit) 186 186 187 187 repo, err := OpenRepository(repoPath) 188 188 if err != nil { ··· 215 215 } 216 216 defer func() { _ = repo.Close() }() 217 217 218 - gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/A", "refs/heads/B") 219 - gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/B", "refs/heads/A") 218 + gitCmd(t, repoPath, "symbolic-ref", "refs/heads/A", "refs/heads/B") 219 + gitCmd(t, repoPath, "symbolic-ref", "refs/heads/B", "refs/heads/A") 220 220 221 221 _, err = repo.ResolveRefFully("refs/heads/A") 222 222 if err == nil { ··· 239 239 if err != nil { 240 240 t.Fatalf("failed to write file.txt: %v", err) 241 241 } 242 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 243 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "init") 242 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 243 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "init") 244 244 245 - commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 245 + commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD") 246 246 247 247 repo, err := OpenRepository(repoPath) 248 248 if err != nil { ··· 287 287 workDir, cleanupWork := setupWorkDir(t) 288 288 defer cleanupWork() 289 289 290 - gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main") 290 + gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main") 291 291 292 292 err := os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("one"), 0o644) 293 293 if err != nil { 294 294 t.Fatalf("failed to write file.txt: %v", err) 295 295 } 296 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 297 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c1") 298 - commit1 := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 296 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 297 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c1") 298 + commit1 := gitCmd(t, repoPath, "rev-parse", "HEAD") 299 299 300 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit1) 301 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/feature", commit1) 302 - gitCmd(t, repoPath, nil, "pack-refs", "--all", "--prune") 300 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit1) 301 + gitCmd(t, repoPath, "update-ref", "refs/heads/feature", commit1) 302 + gitCmd(t, repoPath, "pack-refs", "--all", "--prune") 303 303 304 304 err = os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("two"), 0o644) 305 305 if err != nil { 306 306 t.Fatalf("failed to write file.txt: %v", err) 307 307 } 308 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 309 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c2") 310 - commit2 := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 311 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit2) 308 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 309 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c2") 310 + commit2 := gitCmd(t, repoPath, "rev-parse", "HEAD") 311 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit2) 312 312 313 313 repo, err := OpenRepository(repoPath) 314 314 if err != nil { ··· 360 360 workDir, cleanupWork := setupWorkDir(t) 361 361 defer cleanupWork() 362 362 363 - gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main") 363 + gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main") 364 364 365 365 err := os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("one"), 0o644) 366 366 if err != nil { 367 367 t.Fatalf("failed to write file.txt: %v", err) 368 368 } 369 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 370 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c1") 371 - commit1 := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 369 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 370 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c1") 371 + commit1 := gitCmd(t, repoPath, "rev-parse", "HEAD") 372 372 373 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit1) 374 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/feature", commit1) 375 - gitCmd(t, repoPath, nil, "pack-refs", "--all", "--prune") 373 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit1) 374 + gitCmd(t, repoPath, "update-ref", "refs/heads/feature", commit1) 375 + gitCmd(t, repoPath, "pack-refs", "--all", "--prune") 376 376 377 377 repo, err := OpenRepository(repoPath) 378 378 if err != nil { ··· 404 404 workDir, cleanupWork := setupWorkDir(t) 405 405 defer cleanupWork() 406 406 407 - gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main") 407 + gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main") 408 408 409 409 err := os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("one"), 0o644) 410 410 if err != nil { 411 411 t.Fatalf("failed to write file.txt: %v", err) 412 412 } 413 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".") 414 - gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c1") 415 - commit := gitCmd(t, repoPath, nil, "rev-parse", "HEAD") 413 + gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".") 414 + gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c1") 415 + commit := gitCmd(t, repoPath, "rev-parse", "HEAD") 416 416 417 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit) 418 - gitCmd(t, repoPath, nil, "update-ref", "refs/heads/feature/one", commit) 419 - gitCmd(t, repoPath, nil, "update-ref", "refs/notes/review", commit) 420 - gitCmd(t, repoPath, nil, "update-ref", "refs/tags/v1", commit) 421 - gitCmd(t, repoPath, nil, "pack-refs", "--all", "--prune") 417 + gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit) 418 + gitCmd(t, repoPath, "update-ref", "refs/heads/feature/one", commit) 419 + gitCmd(t, repoPath, "update-ref", "refs/notes/review", commit) 420 + gitCmd(t, repoPath, "update-ref", "refs/tags/v1", commit) 421 + gitCmd(t, repoPath, "pack-refs", "--all", "--prune") 422 422 423 423 repo, err := OpenRepository(repoPath) 424 424 if err != nil {
+1 -4
testutil_test.go
··· 17 17 return workDir, func() { _ = os.RemoveAll(workDir) } 18 18 } 19 19 20 - func gitCmd(t *testing.T, dir string, stdin []byte, args ...string) string { 20 + func gitCmd(t *testing.T, dir string, args ...string) string { 21 21 t.Helper() 22 22 cmd := exec.Command("git", args...) 23 23 cmd.Dir = dir 24 - if stdin != nil { 25 - cmd.Stdin = bytes.NewReader(stdin) 26 - } 27 24 cmd.Env = append(os.Environ(), 28 25 "GIT_CONFIG_GLOBAL=/dev/null", 29 26 "GIT_CONFIG_SYSTEM=/dev/null",