@@ -16,16 +16,15 @@ impl DockerGit {
1616 . args ( [
1717 "run" ,
1818 "--rm" ,
19+ "--entrypoint" ,
20+ "sh" ,
1921 "-v" ,
2022 & format ! ( "{}:/workspace" , test_dir. path( ) . display( ) ) ,
2123 "-w" ,
2224 "/workspace" ,
23- "--user" ,
24- "root" ,
25- "alpine:latest" ,
26- "sh" ,
25+ "alpine/git:latest" ,
2726 "-c" ,
28- & format ! ( "apk add --no-cache git && { script}" ) ,
27+ script,
2928 ] )
3029 . output ( ) ?;
3130
@@ -52,32 +51,27 @@ impl DockerGit {
5251 . collect :: < Vec < _ > > ( )
5352 . join ( " " ) ;
5453
55- self . run_docker_command ( test_dir, & format ! ( "git {git_command}" ) )
54+ self . run_docker_command ( test_dir, & format ! ( "git --git-dir=.git {git_command}" ) )
5655 }
5756
5857 pub fn init_repo ( & self , test_dir : & TestDir ) -> io:: Result < ( ) > {
59- // Create initial file and setup repo in single command to avoid race conditions
58+ // Create initial file and setup repo with initial commit using working pattern
6059 test_dir. create_file ( "README.md" , "# Test Repository" ) ?;
61- let init_script = [
62- "git init -b main" ,
63- "git config user.name 'Test User'" ,
64- "git config user.email 'test@example.com'" ,
65- "git add ." ,
66- "git commit -m 'Initial commit'" ,
67- ]
68- . join ( " && " ) ;
69-
70- self . run_docker_command ( test_dir, & init_script) ?;
60+ let init_script = "git init && git --git-dir=.git config user.name 'Test User' && git --git-dir=.git config user.email 'test@example.com' && git --git-dir=.git add . && git --git-dir=.git commit -m 'Initial commit'" ;
61+ self . run_docker_command ( test_dir, init_script) ?;
7162 Ok ( ( ) )
7263 }
7364
7465 pub fn create_commit ( & self , test_dir : & TestDir , message : & str ) -> io:: Result < ( ) > {
75- self . run_docker_command ( test_dir, & format ! ( "git add . && git commit -m '{message}'" ) ) ?;
66+ self . run_docker_command (
67+ test_dir,
68+ & format ! ( "git --git-dir=.git add . && git --git-dir=.git commit -m '{message}'" ) ,
69+ ) ?;
7670 Ok ( ( ) )
7771 }
7872
7973 pub fn create_tag ( & self , test_dir : & TestDir , tag : & str ) -> io:: Result < ( ) > {
80- self . run_docker_command ( test_dir, & format ! ( "git tag {tag}" ) ) ?;
74+ self . run_docker_command ( test_dir, & format ! ( "git --git-dir=.git tag {tag}" ) ) ?;
8175 Ok ( ( ) )
8276 }
8377}
@@ -134,14 +128,7 @@ mod tests {
134128
135129 fn is_docker_available ( ) -> bool {
136130 Command :: new ( "docker" )
137- . args ( [
138- "run" ,
139- "--rm" ,
140- "alpine:latest" ,
141- "sh" ,
142- "-c" ,
143- "apk add --no-cache git && git --version" ,
144- ] )
131+ . args ( [ "run" , "--rm" , "alpine/git:latest" , "--version" ] )
145132 . output ( )
146133 . map ( |output| output. status . success ( ) )
147134 . unwrap_or ( false )
0 commit comments