(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestGitDiffFilesInRepo(t *testing.T) { |
| 69 | tmpDir := setupGitRepo(t) |
| 70 | |
| 71 | // Create initial file and commit |
| 72 | initialFile := filepath.Join(tmpDir, "initial.go") |
| 73 | if err := os.WriteFile(initialFile, []byte("package main\n"), 0644); err != nil { |
| 74 | t.Fatal(err) |
| 75 | } |
| 76 | |
| 77 | cmd := exec.Command("git", "add", ".") |
| 78 | cmd.Dir = tmpDir |
| 79 | cmd.Run() |
| 80 | |
| 81 | cmd = exec.Command("git", "commit", "-m", "initial") |
| 82 | cmd.Dir = tmpDir |
| 83 | if err := cmd.Run(); err != nil { |
| 84 | t.Skipf("Could not create initial commit: %v", err) |
| 85 | } |
| 86 | |
| 87 | // Create main branch reference |
| 88 | cmd = exec.Command("git", "branch", "-M", "main") |
| 89 | cmd.Dir = tmpDir |
| 90 | cmd.Run() |
| 91 | |
| 92 | // Modify the file |
| 93 | if err := os.WriteFile(initialFile, []byte("package main\n\nfunc main() {}\n"), 0644); err != nil { |
| 94 | t.Fatal(err) |
| 95 | } |
| 96 | |
| 97 | // Create a new untracked file |
| 98 | newFile := filepath.Join(tmpDir, "new.go") |
| 99 | if err := os.WriteFile(newFile, []byte("package main\n"), 0644); err != nil { |
| 100 | t.Fatal(err) |
| 101 | } |
| 102 | |
| 103 | // Get diff info |
| 104 | info, err := GitDiffInfo(tmpDir, "main") |
| 105 | if err != nil { |
| 106 | t.Fatalf("GitDiffInfo failed: %v", err) |
| 107 | } |
| 108 | |
| 109 | // Should have both files as changed |
| 110 | if !info.Changed["initial.go"] { |
| 111 | t.Error("Expected initial.go in changed files") |
| 112 | } |
| 113 | if !info.Changed["new.go"] { |
| 114 | t.Error("Expected new.go in changed files") |
| 115 | } |
| 116 | |
| 117 | // Only new.go should be untracked |
| 118 | if info.Untracked["initial.go"] { |
| 119 | t.Error("initial.go should not be untracked") |
| 120 | } |
| 121 | if !info.Untracked["new.go"] { |
| 122 | t.Error("new.go should be untracked") |
| 123 | } |
| 124 | |
| 125 | // Check stats for modified file |
nothing calls this directly
no test coverage detected