@@ -168,6 +168,39 @@ func TestCloneRepo(t *testing.T) {
168168 }
169169}
170170
171+ func TestCloneRepo_NonMainDefaultBranch (t * testing.T ) {
172+ t .Parallel ()
173+
174+ // Test that cloning works when the remote's default branch is not "main".
175+ // This verifies that we detect the remote's HEAD instead of hardcoding "main".
176+ for _ , defaultBranch := range []string {"master" , "develop" , "trunk" } {
177+ defaultBranch := defaultBranch
178+ t .Run (defaultBranch , func (t * testing.T ) {
179+ t .Parallel ()
180+ srvFS := memfs .New ()
181+ _ = gittest .NewRepoWithBranch (t , srvFS , defaultBranch ,
182+ gittest .Commit (t , "README.md" , "Hello from " + defaultBranch , "Initial commit" ),
183+ )
184+ srv := httptest .NewServer (gittest .NewServer (srvFS ))
185+ t .Cleanup (srv .Close )
186+
187+ clientFS := memfs .New ()
188+ cloned , err := git .CloneRepo (context .Background (), t .Logf , git.CloneRepoOptions {
189+ Path : "/workspace" ,
190+ RepoURL : srv .URL ,
191+ Storage : clientFS ,
192+ SingleBranch : true , // This triggers the default branch detection
193+ })
194+ require .NoError (t , err )
195+ require .True (t , cloned )
196+
197+ // Verify the file was cloned correctly
198+ readme := mustRead (t , clientFS , "/workspace/README.md" )
199+ require .Equal (t , "Hello from " + defaultBranch , readme )
200+ })
201+ }
202+ }
203+
171204func TestShallowCloneRepo (t * testing.T ) {
172205 t .Parallel ()
173206
0 commit comments