log() public method

Returns an array of Commits based on {@link http://git-scm.com/docs/gitrevisions gitrevisions}
public log ( string $options = "", string $gitrevisions = "" ) : Commit[]
$options string Options passed to git log
$gitrevisions string Empty by default, i.e., calling full 'git log'
return Commit[]
 /**
  * @test
  */
 public function itSupportsWildcards()
 {
     touch(self::$repositoryPath . '/somefile');
     touch(self::$repositoryPath . '/otherfile');
     $this->commitEverything();
     unlink(self::$repositoryPath . '/somefile');
     $this->commitEverything();
     $modifications = self::$repository->getFileModifications('*file');
     $log = self::$repository->log();
     $expectedModifications = [['status' => 'D', 'path' => 'somefile', 'commit' => $log[0]->getHash()], ['status' => 'A', 'path' => 'otherfile', 'commit' => $log[1]->getHash()], ['status' => 'A', 'path' => 'somefile', 'commit' => $log[1]->getHash()]];
     $this->assertEquals($expectedModifications, $modifications);
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function allCommitsContainListOfChangedFiles()
 {
     touch(self::$repositoryPath . '/somefile');
     self::$repository->stageAll();
     self::$repository->commit(new CommitMessage("Some commit"), "Author name", "*****@*****.**");
     touch(self::$repositoryPath . '/otherfile');
     self::$repository->stageAll();
     self::$repository->commit(new CommitMessage("Other commit"), "Author name", "*****@*****.**");
     $log = self::$repository->log();
     $lastCommit = $log[0];
     $expectedChangedFilesInLastCommit = [['status' => 'A', 'path' => 'otherfile']];
     $this->assertEquals($expectedChangedFilesInLastCommit, $lastCommit->getChangedFiles());
     $previousCommit = $log[1];
     $expectedChangedFilesInPreviousCommit = [['status' => 'A', 'path' => 'somefile']];
     $this->assertEquals($expectedChangedFilesInPreviousCommit, $previousCommit->getChangedFiles());
 }
 /**
  * @test
  */
 public function committerIsThreadSafe()
 {
     $gitRepository = new GitRepository(self::$repositoryDir, __DIR__);
     $gitRepository->init();
     $numberOfParallelCommits = 50;
     $numberOfFilesInEachCommit = 10;
     /** @var Process[] $runningProcesses */
     $runningProcesses = [];
     for ($i = 0; $i < $numberOfParallelCommits; $i++) {
         $from = $i * $numberOfFilesInEachCommit;
         $to = ($i + 1) * $numberOfFilesInEachCommit;
         $process = new Process("php generate-files-and-commit.php --from={$from} --to={$to}", __DIR__);
         $process->start();
         $runningProcesses[] = $process;
     }
     foreach ($runningProcesses as $process) {
         $process->wait();
     }
     $log = $gitRepository->log();
     $this->assertCount($numberOfParallelCommits, $log);
     foreach ($log as $commit) {
         $files = $commit->getChangedFiles();
         $this->assertCount($numberOfFilesInEachCommit, $files, "Files: \n" . join("\n", array_column($files, 'path')));
     }
 }
 public function undoMultipleCommitsThatCannotBeReverted()
 {
     try {
         $log = $this->repository->log("HEAD~3..HEAD");
         $firstCommit = $log[0]->getHash();
         $secondCommit = $log[2]->getHash();
         $commits = [$firstCommit, $secondCommit];
         $this->wpAutomation->runWpCliCommand('vp', 'undo', [implode(',', $commits)]);
     } catch (\Exception $e) {
     }
     // Intentionally empty catch. Violated referetial integrity throws an exception.
 }
 /**
  * @param WP_REST_Request $request
  * @return WP_REST_Response|WP_Error
  */
 public function rollbackToCommit(WP_REST_Request $request)
 {
     $commitHash = $request['commit'];
     $initialCommitHash = $this->getInitialCommitHash();
     $log = $this->gitRepository->log($commitHash);
     if (!preg_match('/^[0-9a-f]+$/', $commitHash) || count($log) === 0) {
         return new WP_Error('error', 'Invalid commit hash', ['status' => 404]);
     }
     if (!$this->gitRepository->wasCreatedAfter($commitHash, $initialCommitHash) && $log[0]->getHash() !== $initialCommitHash) {
         return new WP_Error('error', 'Cannot roll back before initial commit', ['status' => 403]);
     }
     if ($log[0]->getHash() === $this->gitRepository->getLastCommitHash()) {
         return new WP_Error('error', 'Nothing to commit. Current state is the same as the one you want rollback to.', ['status' => 403]);
     }
     return $this->revertCommits('rollback', [$commitHash]);
 }