Beispiel #1
0
}
// check if there is an existing repo
if (is_dir("{$repoPath}/.git")) {
    die("{$repoPath} already contains a .git repo directory");
}
// write key to file
file_put_contents($keyPath, $_POST['privateKey']);
chmod($keyPath, 0600);
Benchmark::mark("saved key to {$keyPath}");
// write git wrapper to file
file_put_contents($gitWrapperPath, "#!/bin/bash\nssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {$keyPath} \$1 \$2");
chmod($gitWrapperPath, 0700);
putenv("GIT_SSH={$gitWrapperPath}");
Benchmark::mark("saved git wrapper to {$gitWrapperPath}");
// create new repo
$repo = PHPGit_Repository::create($repoPath, !empty($_REQUEST['debug']));
Benchmark::mark("initialized git repo in {$repoPath}");
// add remote
$repo->git("remote add origin {$repoCfg['remote']}");
Benchmark::mark("added origin {$repoCfg['remote']}");
// fetch remote branch
if (!empty($repoCfg['originBranch'])) {
    $repo->git("fetch origin {$repoCfg['originBranch']}");
    Benchmark::mark("fetched origin/{$repoCfg['originBranch']}");
}
// create local working branch
if (!empty($repoCfg['originBranch'])) {
    $repo->git("checkout -b {$repoCfg['workingBranch']} FETCH_HEAD");
    Benchmark::mark("created local branch {$repoCfg['workingBranch']}");
} else {
    die('TODO: handle initializing repo without originBranch');
Beispiel #2
0
 /**
  * Get PHPGit_Repository
  *
  * @return PHPGit_Repository
  */
 protected function getGitoliteRepository()
 {
     if (null === $this->gitoliteRepository) {
         if (null === $this->getGitLocalRepositoryPath()) {
             throw new \Exception('Git local repository path not defined');
         }
         try {
             $this->gitoliteRepository = new \PHPGit_Repository($this->getGitLocalRepositoryPath());
         } catch (\Exception $exc) {
             if (file_exists($this->getGitLocalRepositoryPath())) {
                 throw new \Exception("Directory {$this->getGitLocalRepositoryPath()} already exists, impossible to create repository");
             } else {
                 if (mkdir($this->getGitLocalRepositoryPath(), 0770)) {
                     $this->gitoliteRepository = \PHPGit_Repository::create($this->getGitLocalRepositoryPath());
                 } else {
                     throw new \Exception('Impossible to create Directory informed in Git local repository (possibly).');
                 }
             }
         }
     }
     return $this->gitoliteRepository;
 }
    $t->pass('wtf is not a valid command');
}
$t->comment('Use a valid git binary: /usr/bin/git');
$repo = _createTmpGitRepo($t, array('git_executable' => '/usr/bin/git'));
$t->comment('Use a invalid git binary: /usr/bin/git-foobar');
try {
    $repo = _createTmpGitRepo($t, array('git_executable' => '/usr/bin/git-foobar'));
    $repo->git('status');
    $t->fail('/usr/bin/git-foobar is not a valid git binary');
} catch (RuntimeException $e) {
    $t->pass('/usr/bin/git-foobar is not a valid git binary');
}
$repoDir = sys_get_temp_dir() . '/php-git-repo/' . uniqid();
mkdir($repoDir);
try {
    $repo = PHPGit_Repository::create($repoDir);
    $t->pass('Create a new Git repository in filesystem');
} catch (InvalidArgumentException $e) {
    $t->fail($e->getMessage());
}
$repo = _createTmpGitRepo($t);
$config = $repo->getConfiguration();
$t->ok($config->get('core.editor', true));
$config->set('core.editor', 'nano');
$t->is($config->get('core.editor'), 'nano');
$t->is($config->get('core.editor'), 'nano');
$config->remove('core.editor');
$t->ok($config->get('core.editor', true));
file_put_contents($repo->getDir() . '/README', 'No, finally, do not read me.');
$repo->git('add README');
$repo->git('commit -m "Add README"');