示例#1
0
 /**
  * @static
  * @param GitCommand $gitCommand
  * @param Repository $repository
  * @param Branch $branch
  * @param bool $deleteOnly
  * @return void
  */
 public static function synchronize(GitCommand $gitCommand, Repository $repository, Branch $branch, $deleteOnly = false)
 {
     $branchGit = $gitCommand->getNoMergedBranchInfos($repository->getGitDir(), $branch->getBaseBranchName(), $branch->getName());
     $branchModel = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByName($branch->getName())->findOne();
     if ($branchModel) {
         if (is_null($branchGit)) {
             $branchModel->delete();
         } elseif (!$branchModel->getIsBlacklisted() && !$deleteOnly) {
             $lastSynchronizationCommit = $branchModel->getLastCommit();
             $branchModel->setCommitReference($branchGit['commit_reference']);
             $branchModel->setLastCommit($branchGit['last_commit']);
             $branchModel->setLastCommitDesc($branchGit['last_commit_desc']);
             $branchModel->save();
             return FilePeer::synchronize($gitCommand, $branchModel, $lastSynchronizationCommit);
         }
     }
     return 0;
 }
 /**
  * Adds File to .gitignore and remove file git index.
  *
  * @Route("/ignore/{filePath}", name="project_fileignore")
  * @Method("GET")
  * @Template("VersionControlGitControlBundle:ProjectFiles:fileList.html.twig")
  * @ProjectAccess(grantType="MASTER")
  */
 public function ignoreAction($id, $filePath)
 {
     //$this->initAction($id,'MASTER');
     $params = array('id' => $id);
     $filePath = trim(urldecode($filePath));
     $pathInfo = pathinfo($filePath);
     if (trim($pathInfo['dirname']) && $pathInfo['dirname'] != '.') {
         $currentDir = $pathInfo['dirname'];
         $params['currentDir'] = $currentDir . '/';
     }
     try {
         $response = $this->gitFilesCommands->ignoreFile($filePath, $this->branchName);
         $this->get('session')->getFlashBag()->add('notice', $response);
     } catch (\Exception $e) {
         $this->get('session')->getFlashBag()->add('error', $e->getMessage());
     }
     return $this->redirect($this->generateUrl('project_filelist', $params));
 }
 /**
  * @param int $id
  */
 public function initAction($id, $grantType = 'VIEW')
 {
     $em = $this->getDoctrine()->getManager();
     $this->project = $em->getRepository('VersionControlGitControlBundle:Project')->find($id);
     if (!$this->project) {
         throw $this->createNotFoundException('Unable to find Project entity.');
     }
     //Redirect is not ajax
     $request = $this->container->get('request_stack')->getCurrentRequest();
     //Do not redirect if in test mode
     if ($this->ajaxOnly == true && !$request->isXmlHttpRequest() && $this->container->getParameter('kernel.environment') != 'test') {
         return $this->generateUrl('project', array('section' => urlencode($request->getRequestUri())));
     }
     $this->checkProjectAuthorization($this->project, $grantType);
     $projectEnvironment = $this->getProjectEnvironment();
     $this->gitCommands = $this->get('version_control.git_commands')->setGitEnvironment($projectEnvironment);
     $this->branchName = $this->gitCommands->command('branch')->getCurrentBranch();
     $this->viewVariables = array_merge($this->viewVariables, array('project' => $this->project, 'branchName' => $this->branchName));
 }
 /**
  * Show Git commit diff.
  *
  * @Route("/commitfile/{commitHash}/{filePath}/{diffCommitHash}", name="project_commitfilediff" , defaults={"diffCommitHash" = 0})
  * @Method("GET")
  * @Template()
  * @ProjectAccess(grantType="VIEW")
  */
 public function fileDiffAction($id, $commitHash, $filePath, $diffCommitHash)
 {
     $gitDiffCommand = $this->gitCommands->command('diff');
     $difffile = urldecode($filePath);
     if ($diffCommitHash) {
         $previousCommitHash = $diffCommitHash;
     } else {
         $previousCommitHash = $gitDiffCommand->getPreviousCommitHash($commitHash, $difffile);
     }
     if (!$previousCommitHash) {
         $previousCommitHash = 'HEAD';
     }
     $gitDiffs = $gitDiffCommand->getDiffFileBetweenCommits($difffile, $previousCommitHash, $commitHash);
     $this->gitLogCommand->setLogCount(60)->setCommitHash($commitHash)->setPath($difffile)->setLimit(60);
     $gitPreviousLogs = $this->gitLogCommand->execute()->getResults();
     //First element is current commit so need to remove first element
     array_shift($gitPreviousLogs);
     return array_merge($this->viewVariables, array('diffs' => $gitDiffs, 'previousLogs' => $gitPreviousLogs, 'commitHash' => $commitHash, 'diffCommitHash' => $previousCommitHash, 'filePath' => $difffile));
 }
示例#5
0
文件: FilePeer.php 项目: ratibus/Crew
 /**
  * @static
  * @param GitCommand $gitCommand
  * @param Branch $branch
  * @param string $lastBranchSynchronizationCommit
  * @return int 0 if succeed
  */
 public static function synchronize(GitCommand $gitCommand, Branch $branch, $lastBranchSynchronizationCommit = null)
 {
     $filesGit = $gitCommand->getDiffFilesFromBranch($branch->getRepository()->getGitDir(), $branch->getCommitReference(), $branch->getLastCommit());
     if (count($filesGit) > sfConfig::get('app_max_number_of_files_to_review', 4096)) {
         return count($filesGit);
     }
     $filesModel = FileQuery::create()->filterByBranchId($branch->getId())->find();
     if (count($filesModel) > 0) {
         $diffFilesFromLastSynch = $gitCommand->getDiffFilesFromBranch($branch->getRepository()->getGitDir(), !is_null($lastBranchSynchronizationCommit) ? $lastBranchSynchronizationCommit : $branch->getCommitReference(), $branch->getLastCommit(), false);
     }
     foreach ($filesModel as $fileModel) {
         /** @var $fileModel File */
         if (!array_key_exists($fileModel->getFilename(), $filesGit)) {
             $fileModel->delete();
         } else {
             $lastChangeCommit = $gitCommand->getLastModificationCommit($branch->getRepository()->getGitDir(), $branch->getName(), $fileModel->getFilename());
             if (isset($diffFilesFromLastSynch[$fileModel->getFilename()])) {
                 $fileModel->setReviewRequest(true)->setStatus(BranchPeer::A_TRAITER)->setCommitStatusChanged($lastChangeCommit);
             } else {
                 $fileModel->setReviewRequest(false);
             }
             if ($filesGit[$fileModel->getFilename()]['is-binary']) {
                 $fileModel->setIsBinary(true)->setNbAddedLines(0)->setNbDeletedLines(0);
             } else {
                 $fileModel->setIsBinary(false)->setNbAddedLines($filesGit[$fileModel->getFilename()]['added-lines'])->setNbDeletedLines($filesGit[$fileModel->getFilename()]['deleted-lines']);
             }
             $fileModel->setState($filesGit[$fileModel->getFilename()]['state'])->setLastChangeCommit($lastChangeCommit)->setCommitInfos($gitCommand->getCommitInfos($branch->getRepository()->getGitDir(), $lastChangeCommit, "%ce %s"))->setCommitReference($branch->getCommitReference())->save();
         }
         unset($filesGit[$fileModel->getFilename()]);
     }
     foreach ($filesGit as $fileGit) {
         $lastChangeCommit = $gitCommand->getLastModificationCommit($branch->getRepository()->getGitDir(), $branch->getName(), $fileGit['filename']);
         $file = new File();
         if ($fileGit['is-binary']) {
             $file->setIsBinary(true)->setNbAddedLines(0)->setNbDeletedLines(0);
         } else {
             $file->setIsBinary(false)->setNbAddedLines($fileGit['added-lines'])->setNbDeletedLines($fileGit['deleted-lines']);
         }
         $file->setFilename($fileGit['filename'])->setStatus(BranchPeer::A_TRAITER)->setState($fileGit['state'])->setBranchId($branch->getId())->setLastChangeCommit($lastChangeCommit)->setCommitInfos($gitCommand->getCommitInfos($branch->getRepository()->getGitDir(), $lastChangeCommit, "%ce %s"))->setCommitReference($branch->getCommitReference())->setReviewRequest(true)->save();
     }
     return 0;
 }
示例#6
0
 /**
  * @test
  */
 public function getCommandPath()
 {
     $object = new GitCommand();
     $object->setCommandPath('ls');
     $actual = $object->execute();
     $this->assertTrue(is_array($actual));
     $this->assertNotEmpty($actual);
 }
示例#7
0
 /**
  * @param GitCommand $gitCommand
  * @return string
  */
 protected function run(GitCommand $gitCommand)
 {
     $gitProcess = new GitProcess($this, $gitCommand);
     $gitProcess->run();
     if (!empty($gitProcess->getExitCode())) {
         throw new \RuntimeException('Git command "' . $gitCommand->getCommandLine() . '" in "' . $gitCommand->getDirectory() . '" failed with error "' . $gitProcess->getErrorOutput() . '"', 1456365593);
     }
     $output = $gitProcess->getOutput();
     if (empty($output)) {
         $output = $gitProcess->getErrorOutput();
     }
     return $output;
 }