MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestGitDiffFilesHelper

Function TestGitDiffFilesHelper

scanner/git_test.go:133–179  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

131}
132
133func TestGitDiffFilesHelper(t *testing.T) {
134 tmpDir := setupGitRepo(t)
135
136 // Create and commit a file
137 if err := os.WriteFile(filepath.Join(tmpDir, "test.go"), []byte("test"), 0644); err != nil {
138 t.Fatal(err)
139 }
140
141 cmd := exec.Command("git", "add", ".")
142 cmd.Dir = tmpDir
143 cmd.Run()
144
145 cmd = exec.Command("git", "commit", "-m", "test")
146 cmd.Dir = tmpDir
147 if err := cmd.Run(); err != nil {
148 t.Skip("Could not create commit")
149 }
150
151 cmd = exec.Command("git", "branch", "-M", "main")
152 cmd.Dir = tmpDir
153 cmd.Run()
154
155 // Use GitDiffFiles helper
156 changed, err := GitDiffFiles(tmpDir, "main")
157 if err != nil {
158 t.Fatalf("GitDiffFiles failed: %v", err)
159 }
160
161 // No changes since last commit
162 if len(changed) != 0 {
163 t.Errorf("Expected no changes, got %v", changed)
164 }
165
166 // Modify file
167 if err := os.WriteFile(filepath.Join(tmpDir, "test.go"), []byte("modified"), 0644); err != nil {
168 t.Fatal(err)
169 }
170
171 changed, err = GitDiffFiles(tmpDir, "main")
172 if err != nil {
173 t.Fatalf("GitDiffFiles failed: %v", err)
174 }
175
176 if !changed["test.go"] {
177 t.Error("Expected test.go in changed files")
178 }
179}
180
181func TestGitDiffStatsHelper(t *testing.T) {
182 tmpDir := setupGitRepo(t)

Callers

nothing calls this directly

Calls 3

setupGitRepoFunction · 0.85
GitDiffFilesFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected