예제 #1
0
 public function hasLocalModifications()
 {
     $indicators = array(\PHPGit\Command\StatusCommand::MODIFIED, \PHPGit\Command\StatusCommand::UNTRACKED);
     $status = $this->git->status();
     foreach ($status['changes'] as $mod) {
         if (in_array($mod['index'], $indicators)) {
             return true;
         }
     }
     return false;
 }
예제 #2
0
 public function testCheckoutOrphan()
 {
     $git = new Git();
     $git->setRepository($this->directory);
     $git->checkout->orphan('gh-pages', 'master', array('force' => true));
     $status = $git->status();
     $this->assertEquals('gh-pages', $status['branch']);
 }
예제 #3
0
 public function testTrackingBranchStatus()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', '1');
     $git->add('test.txt');
     $git->commit('test');
     $status = $git->status();
     $this->assertEquals('master', $status['branch']);
 }
예제 #4
0
 public function testException()
 {
     $git = new Git();
     $git->setRepository(sys_get_temp_dir());
     try {
         $git->status();
         $this->fail('Previous operation should fail');
     } catch (GitException $e) {
         $command = $e->getCommandLine();
         $command = str_replace(array('"', "'"), '', $command);
         $this->assertStringEndsWith('status --porcelain -s -b --null', $command);
     }
 }
예제 #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 testStashBranch()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'hello');
     $git->add('.');
     $git->commit('Initial commit');
     $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
     $git->stash();
     $git->stash->branch('dev', 'stash@{0}');
     $status = $git->status();
     $this->assertEquals('dev', $status['branch']);
     $this->assertEquals('hi!', file_get_contents($this->directory . '/README.md'));
 }