@@ -12,19 +12,19 @@ import (
1212
1313func setupTestGitRepo (t * testing.T , dir string ) {
1414 t .Helper ()
15-
15+
1616 cmd := exec .Command ("git" , "init" )
1717 cmd .Dir = dir
1818 if err := cmd .Run (); err != nil {
1919 t .Fatalf ("failed to init git repo: %v" , err )
2020 }
21-
21+
2222 cmd = exec .Command ("git" , "config" , "user.email" , "test@example.com" )
2323 cmd .Dir = dir
2424 if err := cmd .Run (); err != nil {
2525 t .Fatalf ("failed to set git email: %v" , err )
2626 }
27-
27+
2828 cmd = exec .Command ("git" , "config" , "user.name" , "Test User" )
2929 cmd .Dir = dir
3030 if err := cmd .Run (); err != nil {
@@ -35,75 +35,75 @@ func setupTestGitRepo(t *testing.T, dir string) {
3535func TestServeDiffsHTML (t * testing.T ) {
3636 req := httptest .NewRequest ("GET" , "/" , nil )
3737 req .Header .Set ("Accept" , "text/html" )
38-
38+
3939 w := httptest .NewRecorder ()
4040 diffsHandler (w , req )
41-
41+
4242 resp := w .Result ()
4343 if resp .StatusCode != http .StatusOK {
4444 t .Errorf ("expected status 200, got %d" , resp .StatusCode )
4545 }
46-
46+
4747 contentType := resp .Header .Get ("Content-Type" )
4848 if ! strings .Contains (contentType , "text/html" ) {
4949 t .Errorf ("expected content-type text/html, got %s" , contentType )
5050 }
51-
51+
5252 body := w .Body .String ()
53- if ! strings .Contains (body , "<!DOCTYPE html>" ) {
53+ if ! strings .Contains (body , "<!doctype html>" ) {
5454 t .Errorf ("expected HTML document" )
5555 }
5656}
5757
5858func TestServeDiffsText_PWDIsGitRepo (t * testing.T ) {
5959 tmpDir := t .TempDir ()
60-
60+
6161 setupTestGitRepo (t , tmpDir )
62-
62+
6363 testFile := filepath .Join (tmpDir , "test.txt" )
6464 if err := os .WriteFile (testFile , []byte ("initial content\n " ), 0644 ); err != nil {
6565 t .Fatalf ("failed to write test file: %v" , err )
6666 }
67-
67+
6868 cmd := exec .Command ("git" , "add" , "test.txt" )
6969 cmd .Dir = tmpDir
7070 if err := cmd .Run (); err != nil {
7171 t .Fatalf ("failed to git add: %v" , err )
7272 }
73-
73+
7474 cmd = exec .Command ("git" , "commit" , "-m" , "initial commit" )
7575 cmd .Dir = tmpDir
7676 if err := cmd .Run (); err != nil {
7777 t .Fatalf ("failed to commit: %v" , err )
7878 }
79-
79+
8080 if err := os .WriteFile (testFile , []byte ("modified content\n " ), 0644 ); err != nil {
8181 t .Fatalf ("failed to modify test file: %v" , err )
8282 }
83-
83+
8484 oldDir , _ := os .Getwd ()
8585 defer os .Chdir (oldDir )
86-
86+
8787 if err := os .Chdir (tmpDir ); err != nil {
8888 t .Fatalf ("failed to chdir: %v" , err )
8989 }
90-
90+
9191 req := httptest .NewRequest ("GET" , "/" , nil )
9292 req .Header .Set ("Accept" , "text/x-diff" )
93-
93+
9494 w := httptest .NewRecorder ()
9595 diffsHandler (w , req )
96-
96+
9797 resp := w .Result ()
9898 if resp .StatusCode != http .StatusOK {
9999 t .Errorf ("expected status 200, got %d" , resp .StatusCode )
100100 }
101-
101+
102102 contentType := resp .Header .Get ("Content-Type" )
103103 if ! strings .Contains (contentType , "text/x-diff" ) {
104104 t .Errorf ("expected content-type text/x-diff, got %s" , contentType )
105105 }
106-
106+
107107 body := w .Body .String ()
108108 if ! strings .Contains (body , "diff --git" ) {
109109 t .Errorf ("expected diff output, got: %s" , body )
@@ -115,53 +115,53 @@ func TestServeDiffsText_PWDIsGitRepo(t *testing.T) {
115115
116116func TestServeDiffsText_GitSubdirectory (t * testing.T ) {
117117 tmpDir := t .TempDir ()
118-
118+
119119 subDir := filepath .Join (tmpDir , "subproject" )
120120 if err := os .MkdirAll (subDir , 0755 ); err != nil {
121121 t .Fatalf ("failed to create subdir: %v" , err )
122122 }
123-
123+
124124 setupTestGitRepo (t , subDir )
125-
125+
126126 testFile := filepath .Join (subDir , "sub.txt" )
127127 if err := os .WriteFile (testFile , []byte ("sub content\n " ), 0644 ); err != nil {
128128 t .Fatalf ("failed to write test file: %v" , err )
129129 }
130-
130+
131131 cmd := exec .Command ("git" , "add" , "sub.txt" )
132132 cmd .Dir = subDir
133133 if err := cmd .Run (); err != nil {
134134 t .Fatalf ("failed to git add: %v" , err )
135135 }
136-
136+
137137 cmd = exec .Command ("git" , "commit" , "-m" , "sub commit" )
138138 cmd .Dir = subDir
139139 if err := cmd .Run (); err != nil {
140140 t .Fatalf ("failed to commit: %v" , err )
141141 }
142-
142+
143143 if err := os .WriteFile (testFile , []byte ("modified sub\n " ), 0644 ); err != nil {
144144 t .Fatalf ("failed to modify test file: %v" , err )
145145 }
146-
146+
147147 oldDir , _ := os .Getwd ()
148148 defer os .Chdir (oldDir )
149-
149+
150150 if err := os .Chdir (tmpDir ); err != nil {
151151 t .Fatalf ("failed to chdir: %v" , err )
152152 }
153-
153+
154154 req := httptest .NewRequest ("GET" , "/" , nil )
155155 req .Header .Set ("Accept" , "text/x-diff" )
156-
156+
157157 w := httptest .NewRecorder ()
158158 diffsHandler (w , req )
159-
159+
160160 resp := w .Result ()
161161 if resp .StatusCode != http .StatusOK {
162162 t .Errorf ("expected status 200, got %d" , resp .StatusCode )
163163 }
164-
164+
165165 body := w .Body .String ()
166166 if ! strings .Contains (body , "diff --git" ) {
167167 t .Errorf ("expected diff output, got: %s" , body )
@@ -176,111 +176,110 @@ func TestServeDiffsText_GitSubdirectory(t *testing.T) {
176176
177177func TestServeDiffsText_LargeDiffTruncation (t * testing.T ) {
178178 tmpDir := t .TempDir ()
179-
179+
180180 setupTestGitRepo (t , tmpDir )
181-
181+
182182 testFile := filepath .Join (tmpDir , "large.txt" )
183183 largeContent := strings .Repeat ("x" , 1024 * 1024 )
184184 if err := os .WriteFile (testFile , []byte (largeContent ), 0644 ); err != nil {
185185 t .Fatalf ("failed to write test file: %v" , err )
186186 }
187-
187+
188188 cmd := exec .Command ("git" , "add" , "large.txt" )
189189 cmd .Dir = tmpDir
190190 if err := cmd .Run (); err != nil {
191191 t .Fatalf ("failed to git add: %v" , err )
192192 }
193-
193+
194194 cmd = exec .Command ("git" , "commit" , "-m" , "large commit" )
195195 cmd .Dir = tmpDir
196196 if err := cmd .Run (); err != nil {
197197 t .Fatalf ("failed to commit: %v" , err )
198198 }
199-
199+
200200 modifiedContent := strings .Repeat ("y" , 1024 * 1024 )
201201 if err := os .WriteFile (testFile , []byte (modifiedContent ), 0644 ); err != nil {
202202 t .Fatalf ("failed to modify test file: %v" , err )
203203 }
204-
204+
205205 anotherFile := filepath .Join (tmpDir , "another.txt" )
206206 moreContent := strings .Repeat ("z" , 5 * 1024 * 1024 )
207207 if err := os .WriteFile (anotherFile , []byte (moreContent ), 0644 ); err != nil {
208208 t .Fatalf ("failed to write another file: %v" , err )
209209 }
210-
210+
211211 cmd = exec .Command ("git" , "add" , "another.txt" )
212212 cmd .Dir = tmpDir
213213 if err := cmd .Run (); err != nil {
214214 t .Fatalf ("failed to git add: %v" , err )
215215 }
216-
216+
217217 cmd = exec .Command ("git" , "commit" , "-m" , "another commit" )
218218 cmd .Dir = tmpDir
219219 if err := cmd .Run (); err != nil {
220220 t .Fatalf ("failed to commit: %v" , err )
221221 }
222-
222+
223223 yetAnotherContent := strings .Repeat ("w" , 5 * 1024 * 1024 )
224224 if err := os .WriteFile (anotherFile , []byte (yetAnotherContent ), 0644 ); err != nil {
225225 t .Fatalf ("failed to modify another file: %v" , err )
226226 }
227-
227+
228228 oldDir , _ := os .Getwd ()
229229 defer os .Chdir (oldDir )
230-
230+
231231 if err := os .Chdir (tmpDir ); err != nil {
232232 t .Fatalf ("failed to chdir: %v" , err )
233233 }
234-
234+
235235 req := httptest .NewRequest ("GET" , "/" , nil )
236236 req .Header .Set ("Accept" , "text/x-diff" )
237-
237+
238238 w := httptest .NewRecorder ()
239239 diffsHandler (w , req )
240-
240+
241241 resp := w .Result ()
242242 if resp .StatusCode != http .StatusOK {
243243 t .Errorf ("expected status 200, got %d" , resp .StatusCode )
244244 }
245-
245+
246246 body := w .Body .String ()
247247 if len (body ) > 5 * 1024 * 1024 {
248248 t .Errorf ("expected diff to be truncated to 5MB, got %d bytes" , len (body ))
249249 }
250-
250+
251251 if len (body ) == 0 {
252252 t .Error ("expected some diff output" )
253253 }
254254}
255255
256256func TestServeDiffsText_NonGitDirectory (t * testing.T ) {
257257 tmpDir := t .TempDir ()
258-
258+
259259 // Create a non-git directory with a file
260260 testFile := filepath .Join (tmpDir , "test.txt" )
261261 if err := os .WriteFile (testFile , []byte ("test content\n " ), 0644 ); err != nil {
262262 t .Fatalf ("failed to write test file: %v" , err )
263263 }
264-
264+
265265 oldDir , _ := os .Getwd ()
266266 defer os .Chdir (oldDir )
267-
267+
268268 if err := os .Chdir (tmpDir ); err != nil {
269269 t .Fatalf ("failed to chdir: %v" , err )
270270 }
271-
271+
272272 req := httptest .NewRequest ("GET" , "/" , nil )
273273 req .Header .Set ("Accept" , "text/x-diff" )
274-
274+
275275 w := httptest .NewRecorder ()
276276 diffsHandler (w , req )
277-
277+
278278 resp := w .Result ()
279279 if resp .StatusCode != http .StatusOK {
280280 t .Errorf ("expected status 200, got %d" , resp .StatusCode )
281281 }
282-
282+
283283 // Should return empty response since there are no git repos
284284 // This tests that the handler completes successfully even with no repos
285285}
286-
0 commit comments