Browse Source

Make the github driver behave like git if "no-api" is specified.

Nils Adermann 11 years ago
parent
commit
a80fde97d5
2 changed files with 23 additions and 8 deletions
  1. 5 0
      doc/05-repositories.md
  2. 18 8
      src/Composer/Repository/Vcs/GitHubDriver.php

+ 5 - 0
doc/05-repositories.md

@@ -292,6 +292,11 @@ The VCS driver to be used is detected automatically based on the URL. However,
 should you need to specify one for whatever reason, you can use `git`, `svn` or
 `hg` as the repository type instead of `vcs`.
 
+If you set the `no-api` key to `true` on a github repository it will clone the
+repository as it would with any other git repository instead of using the
+GitHub API. But unlike using the `git` driver directly, composer will still
+attempt to use github's zip files.
+
 #### Subversion Options
 
 Since Subversion has no native concept of branches and tags, Composer assumes

+ 18 - 8
src/Composer/Repository/Vcs/GitHubDriver.php

@@ -52,6 +52,11 @@ class GitHubDriver extends VcsDriver
         $this->originUrl = !empty($match[1]) ? $match[1] : $match[2];
         $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.$this->originUrl.'/'.$this->owner.'/'.$this->repository);
 
+        if (isset($this->repoConfig['no-api']) && $this->repoConfig['no-api']) {
+            $this->setupGitDriver();
+            return;
+        }
+
         $this->fetchRootIdentifier();
     }
 
@@ -405,14 +410,7 @@ class GitHubDriver extends VcsDriver
             // GitHub returns 404 for private repositories) and we
             // cannot ask for authentication credentials (because we
             // are not interactive) then we fallback to GitDriver.
-            $this->gitDriver = new GitDriver(
-                array('url' => $this->generateSshUrl()),
-                $this->io,
-                $this->config,
-                $this->process,
-                $this->remoteFilesystem
-            );
-            $this->gitDriver->initialize();
+            $this->setupGitDriver();
 
             return;
         } catch (\RuntimeException $e) {
@@ -422,4 +420,16 @@ class GitHubDriver extends VcsDriver
             throw $e;
         }
     }
+
+    protected function setupGitDriver()
+    {
+        $this->gitDriver = new GitDriver(
+            array('url' => $this->generateSshUrl()),
+            $this->io,
+            $this->config,
+            $this->process,
+            $this->remoteFilesystem
+        );
+        $this->gitDriver->initialize();
+    }
 }