예제 #1
0
 public function testMergeAbort()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     // branch:master
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('master');
     // branch:develop
     $git->checkout->create('develop');
     $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
     $git->add('test.txt');
     $git->commit('develop');
     // branch:master
     $git->checkout('master');
     $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
     $git->add('test.txt');
     $git->commit('master');
     try {
         $git->merge('develop');
         $this->fail('$git->merge("develop") should fail');
     } catch (Exception $e) {
     }
     $git->merge->abort();
     $this->assertEquals('baz', file_get_contents($this->directory . '/test.txt'));
 }
예제 #2
0
 public function testCheckout()
 {
     $git = new Git();
     $git->setRepository($this->directory);
     $git->branch->create('next');
     $git->checkout('next');
     $branches = $git->branch();
     $this->assertArrayHasKey('next', $branches);
     $this->assertTrue($branches['next']['current']);
 }
예제 #3
0
 public function testDetachedHeadStatus()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/item1.txt', '1');
     $git->add('item1.txt');
     $git->commit('initial commit');
     $logs = $git->log();
     $hash = $logs[0]['hash'];
     $git->checkout($hash);
     $status = $git->status();
     $this->assertEquals(null, $status['branch']);
 }
 /**
  * Return the path to the checked out repository for the supplied
  * manual and version.
  *
  * @param string $manual
  * @param string $version
  * @return string
  */
 private function getStoragePath($manual, $version)
 {
     $storagePath = storage_path('codex/' . $manual . '/' . $version);
     if (!file_exists($storagePath)) {
         $this->files->copyDirectory($this->storagePath . '/' . $manual, $storagePath, 0);
         $this->git->setRepository($storagePath);
         $this->git->checkout($version);
     } else {
         $this->cache->remember("{$manual}.{$version}.checkout", 10, function () use($version, $storagePath) {
             $this->git->setRepository($storagePath);
             $this->git->pull('origin', $version);
             return true;
         });
     }
     return $storagePath;
 }
예제 #5
0
 /**
  * 1. Checkout to new branch modvert/test based on origin/test
  * or movert/develop based on origin/develop
  * 2. Load remote resources
  * 3. Show message:
  *   1. Check changes `git diff --name-only -- storage`
  *   2. Commit if has changes
  *   3. Checkout to the main branch (test/develop/feature/QUES-*)
  *   4. Merge `git merge movert/test` or `git merge movert/develop`
  *
  * Если
  */
 public function loadRemote($stage)
 {
     /** @var $resource IResource **/
     $repository = new Repository();
     $driver = new RemoteDriver($stage);
     $repository->setDriver($driver);
     if ($repository->isLocked()) {
         // If remote stage is Locked
         return $this->output->writeln('<error>Remote stage is locked. Please try again!</error>');
     }
     $storage = new Storage($this->getConnection());
     $git = new Git();
     $git->setRepository(Application::getInstance()->getAppPath());
     $status = $git->status();
     $current_branch = $status['branch'];
     // do not checkout if has unstaged changes
     if (count($status['changes'])) {
         return $this->output->writeln('<error>Please commit changes before!</error>');
     }
     $temp_branch = 'modvert/develop';
     $parent_branch = 'origin/develop';
     try {
         $git->branch->delete($temp_branch, ['force' => true]);
     } catch (\Exception $ex) {
         /** the branch not found */
     }
     $git->checkout->create($temp_branch, $parent_branch);
     $storage->loadRemote($stage);
     $storage_changes = ArrayHelper::matchValue($git->status()['changes'], 'file', '/^storage/');
     if (count($storage_changes)) {
         $this->output->writeln('<info>You have unstaged remote changes! Commit them and merge with main branch!</info>');
     } else {
         $git->checkout($current_branch);
     }
 }
예제 #6
0
 public function testRebaseSkip()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('initial commit');
     $git->checkout->create('next');
     $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
     $git->add('test.txt');
     $git->commit('next commit');
     $git->checkout('master');
     $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
     $git->add('test.txt');
     $git->commit('master commit');
     try {
         $git->rebase('next');
         $this->fail('GitException should be thrown');
     } catch (\PHPGit\Exception\GitException $e) {
     }
     $git->rebase->skip();
 }