@@ -63,7 +63,7 @@ private function createFile(string $owner, string $repo, string $filepath, strin
6363 {
6464 $ giteaUrl = System::getEnv ('TESTS_GITEA_URL ' , 'http://gitea:3000 ' ) ?? '' ;
6565 $ url = "{$ giteaUrl }/api/v1/repos/ {$ owner }/ {$ repo }/contents/ {$ filepath }" ;
66-
66+
6767 $ ch = curl_init ($ url );
6868 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
6969 curl_setopt ($ ch , CURLOPT_POST , true );
@@ -75,9 +75,14 @@ private function createFile(string $owner, string $repo, string $filepath, strin
7575 'content ' => base64_encode ($ content ),
7676 'message ' => $ message
7777 ]));
78-
79- curl_exec ($ ch );
78+
79+ $ response = curl_exec ($ ch );
80+ $ httpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
8081 curl_close ($ ch );
82+
83+ if ($ httpCode >= 400 ) {
84+ throw new \Exception ("Failed to create file {$ filepath }: HTTP {$ httpCode }" );
85+ }
8186 }
8287
8388 public function testCreateRepository (): void
@@ -128,6 +133,42 @@ public function testGetComment(): void
128133 $ this ->markTestSkipped ('Will be implemented in follow-up PR ' );
129134 }
130135
136+ public function testGetRepositoryTreeWithSlashInBranchName (): void
137+ {
138+ $ repositoryName = 'test-branch-with-slash- ' . \uniqid ();
139+ $ this ->vcsAdapter ->createRepository (self ::$ owner , $ repositoryName , false );
140+
141+ // Create a file on main branch first
142+ $ this ->createFile (self ::$ owner , $ repositoryName , 'README.md ' , '# Test ' );
143+
144+ // Create a branch with a slash in the name using curl
145+ $ giteaUrl = System::getEnv ('TESTS_GITEA_URL ' , 'http://gitea:3000 ' ) ?? '' ;
146+ $ url = "{$ giteaUrl }/api/v1/repos/ " . self ::$ owner . "/ {$ repositoryName }/branches " ;
147+
148+ $ ch = curl_init ($ url );
149+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
150+ curl_setopt ($ ch , CURLOPT_POST , true );
151+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
152+ 'Authorization: token ' . self ::$ accessToken ,
153+ 'Content-Type: application/json '
154+ ]);
155+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ([
156+ 'new_branch_name ' => 'feature/test-branch ' ,
157+ 'old_branch_name ' => 'main '
158+ ]));
159+ curl_exec ($ ch );
160+ curl_close ($ ch );
161+
162+ // Now try to get tree from the branch with slash
163+ $ tree = $ this ->vcsAdapter ->getRepositoryTree (self ::$ owner , $ repositoryName , 'feature/test-branch ' );
164+
165+ $ this ->assertIsArray ($ tree );
166+ $ this ->assertNotEmpty ($ tree ); // Should have README.md
167+ $ this ->assertContains ('README.md ' , $ tree );
168+
169+ $ this ->vcsAdapter ->deleteRepository (self ::$ owner , $ repositoryName );
170+ }
171+
131172 public function testGetRepository (): void
132173 {
133174 $ repositoryName = 'test-get-repository- ' . \uniqid ();
@@ -280,7 +321,6 @@ public function testGetRepositoryContentFileNotFound(): void
280321 $ this ->expectException (\Utopia \VCS \Exception \FileNotFound::class);
281322 $ this ->vcsAdapter ->getRepositoryContent (self ::$ owner , $ repositoryName , 'non-existing.txt ' );
282323
283- $ this ->vcsAdapter ->deleteRepository (self ::$ owner , $ repositoryName );
284324 }
285325
286326 public function testListRepositoryContents (): void
@@ -446,6 +486,8 @@ public function testListRepositoryLanguages(): void
446486 $ this ->createFile (self ::$ owner , $ repositoryName , 'script.js ' , 'console.log("test"); ' );
447487 $ this ->createFile (self ::$ owner , $ repositoryName , 'style.css ' , 'body { margin: 0; } ' );
448488
489+ sleep (2 );
490+
449491 $ languages = $ this ->vcsAdapter ->listRepositoryLanguages (self ::$ owner , $ repositoryName );
450492
451493 $ this ->assertIsArray ($ languages );
0 commit comments