Пример #1
0
 public function testCloned_CheckoutMyFeature_Newfile()
 {
     $upstream = $this->createUpstreamRepo();
     ProcessUtil::runOk($this->command("", "git clone file://{$upstream->getPath()} downstream"));
     $downstream = new GitRepo($this->fixturePath . '/downstream');
     ProcessUtil::runOk($downstream->command("git checkout my-feature"));
     $this->assertEquals("example text plus my feature", $downstream->readFile("example.txt"));
     $downstream->writeFile("example-2.txt", "second");
     $this->assertIsCommit($downstream->getCommit());
     $this->assertEquals('my-feature', $downstream->getLocalBranch());
     $this->assertEquals('origin/my-feature', $downstream->getUpstreamBranch());
     $this->assertEquals(FALSE, $downstream->hasUncommittedChanges());
     $this->assertEquals(TRUE, $downstream->hasUntrackedFiles());
     $this->assertEquals(array(), $upstream->getRemotes());
     $this->assertEquals(array('origin'), $downstream->getRemotes());
     $this->assertEquals("file://{$upstream->getPath()}", $downstream->getRemoteUrl('origin'));
     $this->assertEquals(array('origin' => "file://{$upstream->getPath()}"), $downstream->getRemoteUrls());
 }
Пример #2
0
 /**
  * Ensure that we've checked out a branch where we can do merges.
  *
  * @param \GitScan\GitRepo $gitRepo
  */
 protected function checkoutAutomergeBranch(InputInterface $input, OutputInterface $output, GitRepo $gitRepo, $repoName)
 {
     if ($gitRepo->hasUncommittedChanges(TRUE)) {
         throw new \RuntimeException("Cannot apply patch");
     }
     $localBranch = $gitRepo->getLocalBranch();
     $upstreamBranch = $gitRepo->getUpstreamBranch();
     $newLocalBranch = "merge-{$localBranch}-" . date('YmdHis');
     $mode = $this->getAutomergeMode($input, $output, $repoName, $localBranch, $upstreamBranch, $newLocalBranch);
     switch ($mode) {
         case 'keep':
             $output->writeln("In \"<info>{$repoName}</info>\", keep the current branch \"<info>{$localBranch}</info>\".");
             return;
         case 'rebuild':
             $backupBranch = 'backup-' . $localBranch . '-' . date('YmdHis') . '-' . rand(0, 100);
             $output->writeln("In \"<info>{$repoName}</info>\", rename \"<info>{$localBranch}</info>\" to \"<info>{$backupBranch}</info>\".");
             Process::runOk($gitRepo->command("git branch -m {$localBranch} {$backupBranch}"));
             $output->writeln("In \"<info>{$repoName}</info>\", create \"<info>{$localBranch}</info>\" using \"<info>{$upstreamBranch}</info>\".");
             Process::runOk($gitRepo->command("git checkout {$upstreamBranch} -b {$localBranch}"));
             return;
         case 'new':
             $output->writeln("In \"<info>{$repoName}</info>\", create \"<info>{$newLocalBranch}</info>\" using \"<info>{$upstreamBranch}</info>\".");
             Process::runOk($gitRepo->command("git checkout {$upstreamBranch} -b {$newLocalBranch}"));
             return;
         case 'abort':
             // Pass through...
         // Pass through...
         default:
             throw new \RuntimeException("Could not decide how to base local branch.");
     }
 }