/** * Performs a git checkout. * * @return void * @throws phpucErrorException * If the git checkout fails. */ public function checkout() { $git = phpucFileUtil::findExecutable('git'); $url = escapeshellarg($this->url); $cmd = "{$git} clone {$url} source"; popen("{$cmd} 2>&1", "r"); if (!file_exists('source')) { throw new phpucErrorException('The project checkout has failed.'); } $cwd = getcwd(); // Switch into checkout directory chdir('source'); // Add tracked remote branch shell_exec("{$git} remote add {$this->remote} {$url}"); chdir($cwd); }
/** * Performs a subversion checkout. * * @return void * @throws phpucErrorException * If the subversion checkout fails. */ public function checkout() { $options = ' --no-auth-cache --non-interactive'; if ($this->username !== null) { $options .= ' --username ' . escapeshellarg($this->username); } if ($this->password !== null) { $options .= ' --password ' . escapeshellarg($this->password); } $svn = phpucFileUtil::findExecutable('svn'); $url = escapeshellarg($this->url); $cmd = "{$svn} co {$options} {$url} source"; popen("{$cmd} 2>&1", "r"); if (!file_exists('source')) { throw new phpucErrorException('The project checkout has failed.'); } }
/** * Tests that an exceptions is thrown if a requested executable doesn't * exist. * * @return void */ public function testFindExecutableWindowsFail() { $this->initExecutableTest(phpucFileUtil::OS_WINDOWS); $this->setExpectedException('phpucErrorException'); phpucFileUtil::findExecutable('cvs'); }
/** * Performs a project checkout against the specified repository. * * @return void */ public function execute() { $out = phpucConsoleOutput::get(); $out->writeLine('Performing checkout task.'); $out->startList(); // Get current working dir $cwd = getcwd(); $out->writeListItem('Checking out project.'); $projectPath = sprintf('%s/projects/%s', $this->args->getArgument('cc-install-dir'), $this->args->getOption('project-name')); // Switch working dir to the CruiseControl project directory chdir($projectPath); $checkout = phpucAbstractCheckout::createCheckout($this->args); $checkout->checkout(); chdir($cwd); $out->writeListItem('Preparing config.xml file.'); $fileName = sprintf('%s/config.xml', $this->args->getArgument('cc-install-dir')); $config = new phpucConfigFile($fileName); $project = $config->getProject($this->args->getOption('project-name')); $strapper = $project->createBootStrapper(); $strapper->localWorkingCopy = "{$projectPath}/source"; $strapper->strapperType = $this->args->getOption('version-control'); $trigger = $project->createBuildTrigger(); $trigger->localWorkingCopy = "{$projectPath}/source"; $trigger->triggerType = $this->args->getOption('version-control'); $config->store(); $out->writeListItem('Preparing build.xml checkout target.'); $buildFile = new phpucBuildFile("{$projectPath}/build.xml"); $buildTarget = $buildFile->createBuildTarget('checkout'); $execTask = phpucAbstractAntTask::create($buildFile, 'exec'); $execTask->executable = phpucFileUtil::findExecutable($this->args->getOption('version-control')); $execTask->argLine = $checkout->getUpdateCommand(); $execTask->failonerror = true; $buildTarget->addTask($execTask); $buildFile->store(); $out->writeLine(); }