/** * Merge a patch into the currently-active branch. * * Ex: git scan automerge ;upstreamurlregex;/path/to/patchfile */ public function testAutoMergeCurrentConflict() { $upstream = $this->createUpstreamRepo(); mkdir("{$this->fixturePath}/subdir"); ProcessUtil::runOk($this->command("", "git clone file://{$upstream->getPath()} {$this->fixturePath}/subdir/downstream")); $downstream = new GitRepo($this->fixturePath . '/subdir/downstream'); $this->assertEquals("example text", $downstream->readFile("example.txt")); $this->assertEquals("master", $downstream->getLocalBranch()); $patchFile = $this->createPatchFile($upstream, 'mypatch'); $this->assertNotRegExp('/the future has been patched/', $downstream->readFile('changelog.txt')); $downstream->commitFile("example.txt", "some unrelated local changes"); $this->assertRegExp('/some unrelated local changes/', $downstream->readFile('example.txt')); // Introduce a conflict $downstream->commitFile("changelog.txt", "this is bad! it has conflict!"); try { $commandTester = $this->createCommandTester(array('command' => 'automerge', '--path' => $this->fixturePath, '--keep' => 1, 'url' => array(";/upstream;{$patchFile}"))); $this->fail("Expected ProcessErrorException"); } catch (ProcessErrorException $e) { $this->assertEquals(1, $e->getProcess()->getExitCode()); $this->assertContains('patch failed', $e->getProcess()->getErrorOutput()); } }
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()); }
/** * 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."); } }