@@ -162,7 +162,112 @@ mod tests {
162162 use std:: fs;
163163 use std:: process:: Command ;
164164
165- fn setup_git_repo ( ) -> TestDir {
165+ /// Check if we should use native Git (CI only) or Docker (local development)
166+ fn should_use_native_git ( ) -> bool {
167+ std:: env:: var ( "CI" ) . is_ok ( )
168+ }
169+
170+ /// Setup Git repo - uses native Git in CI, Docker locally
171+ fn setup_test_git_repo ( ) -> TestDir {
172+ if should_use_native_git ( ) {
173+ setup_native_git_repo ( )
174+ } else {
175+ setup_docker_git_repo ( )
176+ }
177+ }
178+
179+ /// Setup Git repo with tag - uses native Git in CI, Docker locally
180+ fn setup_test_git_repo_with_tag ( tag : & str ) -> TestDir {
181+ if should_use_native_git ( ) {
182+ setup_native_git_repo_with_tag ( tag)
183+ } else {
184+ setup_docker_git_repo_with_tag ( tag)
185+ }
186+ }
187+
188+ /// Setup Git repo using native Git commands (CI only)
189+ fn setup_native_git_repo ( ) -> TestDir {
190+ let temp_dir = TestDir :: new ( ) . expect ( "should create temp dir" ) ;
191+ let path = temp_dir. path ( ) ;
192+
193+ // Create initial file
194+ fs:: write ( path. join ( "README.md" ) , "# Test Repo" ) . expect ( "should write README" ) ;
195+
196+ // Use isolated Git config to avoid affecting user's settings
197+ let git_cmd = |args : & [ & str ] | {
198+ Command :: new ( "git" )
199+ . env ( "GIT_CONFIG_GLOBAL" , "/dev/null" )
200+ . env ( "GIT_CONFIG_SYSTEM" , "/dev/null" )
201+ . args ( args)
202+ . current_dir ( path)
203+ . output ( )
204+ . expect ( "should execute git command" )
205+ } ;
206+
207+ let commands = [
208+ & [ "init" ] [ ..] ,
209+ & [ "config" , "user.name" , "Test User" ] ,
210+ & [ "config" , "user.email" , "test@example.com" ] ,
211+ & [ "add" , "." ] ,
212+ & [ "commit" , "-m" , "Initial commit" ] ,
213+ ] ;
214+
215+ for args in commands {
216+ let output = git_cmd ( args) ;
217+ assert ! (
218+ output. status. success( ) ,
219+ "Git command '{:?}' failed: {}" ,
220+ args,
221+ String :: from_utf8_lossy( & output. stderr)
222+ ) ;
223+ }
224+
225+ temp_dir
226+ }
227+
228+ /// Setup Git repo with tag using native Git commands (CI only)
229+ fn setup_native_git_repo_with_tag ( tag : & str ) -> TestDir {
230+ let temp_dir = TestDir :: new ( ) . expect ( "should create temp dir" ) ;
231+ let path = temp_dir. path ( ) ;
232+
233+ // Create initial file
234+ fs:: write ( path. join ( "README.md" ) , "# Test Repo" ) . expect ( "should write README" ) ;
235+
236+ // Use isolated Git config
237+ let git_cmd = |args : & [ & str ] | {
238+ Command :: new ( "git" )
239+ . env ( "GIT_CONFIG_GLOBAL" , "/dev/null" )
240+ . env ( "GIT_CONFIG_SYSTEM" , "/dev/null" )
241+ . args ( args)
242+ . current_dir ( path)
243+ . output ( )
244+ . expect ( "should execute git command" )
245+ } ;
246+
247+ let commands = [
248+ & [ "init" ] [ ..] ,
249+ & [ "config" , "user.name" , "Test User" ] ,
250+ & [ "config" , "user.email" , "test@example.com" ] ,
251+ & [ "add" , "." ] ,
252+ & [ "commit" , "-m" , "Initial commit" ] ,
253+ & [ "tag" , tag] ,
254+ ] ;
255+
256+ for args in commands {
257+ let output = git_cmd ( args) ;
258+ assert ! (
259+ output. status. success( ) ,
260+ "Git command '{:?}' failed: {}" ,
261+ args,
262+ String :: from_utf8_lossy( & output. stderr)
263+ ) ;
264+ }
265+
266+ temp_dir
267+ }
268+
269+ /// Setup Git repo using Docker (local development)
270+ fn setup_docker_git_repo ( ) -> TestDir {
166271 let temp_dir = TestDir :: new ( ) . expect ( "should create temp dir" ) ;
167272 let path = temp_dir. path ( ) ;
168273
@@ -206,12 +311,7 @@ mod tests {
206311 temp_dir
207312 }
208313
209- fn setup_git_repo_with_commit ( ) -> TestDir {
210- // Just return the basic repo since it already has a commit
211- setup_git_repo ( )
212- }
213-
214- fn setup_git_repo_with_tag ( tag : & str ) -> TestDir {
314+ fn setup_docker_git_repo_with_tag ( tag : & str ) -> TestDir {
215315 let temp_dir = TestDir :: new ( ) . expect ( "should create temp dir" ) ;
216316 let path = temp_dir. path ( ) ;
217317
@@ -257,9 +357,8 @@ mod tests {
257357 }
258358
259359 #[ test]
260- #[ ignore = "docker" ]
261360 fn test_git_vcs_new ( ) {
262- let temp_dir = setup_git_repo ( ) ;
361+ let temp_dir = setup_test_git_repo ( ) ;
263362 let result = GitVcs :: new ( temp_dir. path ( ) ) ;
264363 assert ! ( result. is_ok( ) ) ;
265364 }
@@ -272,9 +371,8 @@ mod tests {
272371 }
273372
274373 #[ test]
275- #[ ignore = "docker" ]
276374 fn test_is_available ( ) {
277- let temp_dir = setup_git_repo ( ) ;
375+ let temp_dir = setup_test_git_repo ( ) ;
278376 let git_vcs = GitVcs :: new ( temp_dir. path ( ) ) . expect ( "should create GitVcs" ) ;
279377 assert ! ( git_vcs. is_available( temp_dir. path( ) ) ) ;
280378 }
@@ -289,9 +387,8 @@ mod tests {
289387 }
290388
291389 #[ test]
292- #[ ignore = "docker" ]
293390 fn test_get_vcs_data_with_commit ( ) {
294- let temp_dir = setup_git_repo_with_commit ( ) ;
391+ let temp_dir = setup_test_git_repo ( ) ;
295392 let git_vcs = GitVcs :: new ( temp_dir. path ( ) ) . expect ( "should create GitVcs" ) ;
296393 let data = git_vcs. get_vcs_data ( ) . expect ( "should get vcs data" ) ;
297394
@@ -303,9 +400,8 @@ mod tests {
303400 }
304401
305402 #[ test]
306- #[ ignore = "docker" ]
307403 fn test_get_vcs_data_with_tag ( ) {
308- let temp_dir = setup_git_repo_with_tag ( "v1.0.0" ) ;
404+ let temp_dir = setup_test_git_repo_with_tag ( "v1.0.0" ) ;
309405 let git_vcs = GitVcs :: new ( temp_dir. path ( ) ) . expect ( "should create GitVcs" ) ;
310406 let data = git_vcs. get_vcs_data ( ) . expect ( "should get vcs data" ) ;
311407
@@ -317,33 +413,64 @@ mod tests {
317413 }
318414
319415 #[ test]
320- #[ ignore = "docker" ]
321416 fn test_get_vcs_data_with_distance ( ) {
322- let temp_dir = setup_git_repo_with_tag ( "v1.0.0" ) ;
417+ let temp_dir = setup_test_git_repo_with_tag ( "v1.0.0" ) ;
323418 let path = temp_dir. path ( ) ;
324419
325- // Add another commit after tag using Docker
326- let output = Command :: new ( "docker" )
327- . args ( [
328- "run" ,
329- "--rm" ,
330- "--entrypoint" ,
331- "sh" ,
332- "-v" ,
333- & format ! ( "{}:/workspace" , path. display( ) ) ,
334- "-w" ,
335- "/workspace" ,
336- "alpine/git:latest" ,
337- "-c" ,
338- "echo 'test content 2' > test2.txt && git --git-dir=.git add . && git --git-dir=.git commit -m 'second commit'" ,
339- ] )
340- . output ( )
341- . expect ( "should execute docker command" ) ;
342- assert ! (
343- output. status. success( ) ,
344- "Docker git second commit failed: {}" ,
345- String :: from_utf8_lossy( & output. stderr)
346- ) ;
420+ // Add another commit after tag
421+ fs:: write ( path. join ( "test2.txt" ) , "test content 2" ) . expect ( "should write file" ) ;
422+
423+ if should_use_native_git ( ) {
424+ // Use native Git
425+ let output = Command :: new ( "git" )
426+ . env ( "GIT_CONFIG_GLOBAL" , "/dev/null" )
427+ . env ( "GIT_CONFIG_SYSTEM" , "/dev/null" )
428+ . args ( [ "add" , "." ] )
429+ . current_dir ( path)
430+ . output ( )
431+ . expect ( "should execute git add" ) ;
432+ assert ! (
433+ output. status. success( ) ,
434+ "Git add failed: {}" ,
435+ String :: from_utf8_lossy( & output. stderr)
436+ ) ;
437+
438+ let output = Command :: new ( "git" )
439+ . env ( "GIT_CONFIG_GLOBAL" , "/dev/null" )
440+ . env ( "GIT_CONFIG_SYSTEM" , "/dev/null" )
441+ . args ( [ "commit" , "-m" , "second commit" ] )
442+ . current_dir ( path)
443+ . output ( )
444+ . expect ( "should execute git commit" ) ;
445+ assert ! (
446+ output. status. success( ) ,
447+ "Git commit failed: {}" ,
448+ String :: from_utf8_lossy( & output. stderr)
449+ ) ;
450+ } else {
451+ // Use Docker
452+ let output = Command :: new ( "docker" )
453+ . args ( [
454+ "run" ,
455+ "--rm" ,
456+ "--entrypoint" ,
457+ "sh" ,
458+ "-v" ,
459+ & format ! ( "{}:/workspace" , path. display( ) ) ,
460+ "-w" ,
461+ "/workspace" ,
462+ "alpine/git:latest" ,
463+ "-c" ,
464+ "git --git-dir=.git add . && git --git-dir=.git commit -m 'second commit'" ,
465+ ] )
466+ . output ( )
467+ . expect ( "should execute docker command" ) ;
468+ assert ! (
469+ output. status. success( ) ,
470+ "Docker git second commit failed: {}" ,
471+ String :: from_utf8_lossy( & output. stderr)
472+ ) ;
473+ }
347474
348475 let git_vcs = GitVcs :: new ( temp_dir. path ( ) ) . expect ( "should create GitVcs" ) ;
349476 let data = git_vcs. get_vcs_data ( ) . expect ( "should get vcs data" ) ;
@@ -353,9 +480,8 @@ mod tests {
353480 }
354481
355482 #[ test]
356- #[ ignore = "docker" ]
357483 fn test_dirty_working_directory ( ) {
358- let temp_dir = setup_git_repo_with_commit ( ) ;
484+ let temp_dir = setup_test_git_repo ( ) ;
359485 let path = temp_dir. path ( ) ;
360486
361487 // Create untracked file
@@ -368,12 +494,21 @@ mod tests {
368494 }
369495
370496 #[ test]
371- #[ ignore = "docker" ]
372497 fn test_clean_working_directory ( ) {
373- let temp_dir = setup_git_repo ( ) ;
498+ let temp_dir = setup_test_git_repo ( ) ;
374499 let git_vcs = GitVcs :: new ( temp_dir. path ( ) ) . expect ( "should create GitVcs" ) ;
375500 let data = git_vcs. get_vcs_data ( ) . expect ( "should get vcs data" ) ;
376501
377502 assert ! ( !data. is_dirty) ;
378503 }
504+
505+ // Keep Docker-specific tests for local development
506+ #[ test]
507+ #[ ignore = "docker" ]
508+ fn test_docker_git_integration ( ) {
509+ let temp_dir = setup_docker_git_repo ( ) ;
510+ let git_vcs = GitVcs :: new ( temp_dir. path ( ) ) . expect ( "should create GitVcs" ) ;
511+ let data = git_vcs. get_vcs_data ( ) . expect ( "should get vcs data" ) ;
512+ assert ! ( !data. commit_hash. is_empty( ) ) ;
513+ }
379514}
0 commit comments