/** * Finishes `vp push` * * @subcommand finish-push * */ public function finishPush($args, $assoc_args) { global $versionPressContainer; // Update working copy $resetCommand = "git reset --hard"; $process = VPCommandUtils::exec($resetCommand); if (!$process->isSuccessful()) { WP_CLI::error("Working directory couldn't be reset"); } // Run synchronization /** @var SynchronizationProcess $syncProcess */ $syncProcess = $versionPressContainer->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS); $syncProcess->synchronizeAll(); vp_flush_regenerable_options(); vp_disable_maintenance(); $this->flushRewriteRules(); vp_enable_maintenance(); }
/** * Returns URL for a remote name, or null if the remote isn't configured. * For example, for "origin", it might return "https://github.com/project/repo.git". * * @param string $name Remote name, e.g., "origin" * @return string|null Remote URL, or null if remote isn't configured */ private function getRemoteUrl($name) { $listRemotesCommand = "git remote -v"; $remotesRaw = VPCommandUtils::exec($listRemotesCommand)->getConsoleOutput(); // https://regex101.com/r/iQ4kG4/2 $numberOfMatches = preg_match_all("/^([[:alnum:]]+)\\s+(.*) \\(fetch\\)\$/m", $remotesRaw, $matches); if ($numberOfMatches === 0) { return null; } $remotes = array(); foreach ($matches[1] as $i => $cloneName) { $url = $matches[2][$i]; $remotes[$cloneName] = $url; } if (isset($remotes[$name])) { return $remotes[$name]; } return null; }
/** * @test */ public function revertAllCanRevertToCommitInParallelBranch() { VPCommandUtils::exec('git branch test', self::$repositoryPath); $this->commitFile('some-file', 'Some commit'); VPCommandUtils::exec('git checkout test', self::$repositoryPath); $this->commitFile('other-file', 'Other commit'); $hash = self::$repository->getLastCommitHash(); VPCommandUtils::exec('git checkout master', self::$repositoryPath); VPCommandUtils::exec('git merge test', self::$repositoryPath); $commitAsserter = $this->createCommitAsserter(); self::$repository->revertAll($hash); $this->commit('Revert all'); $commitAsserter->assertNumCommits(1); $commitAsserter->assertCleanWorkingDirectory(); $commitAsserter->assertCountOfAffectedFiles(1); $commitAsserter->assertCommitPath('D', 'some-file'); }
/** * @test */ public function rollbackWorksWithMergeCommits() { $commitHash = $this->gitRepository->getLastCommitHash(); $sitePath = self::$testConfig->testSite->path; VPCommandUtils::exec('git branch test', $sitePath); self::$wpAutomation->createOption('vp_option_master', 'foo'); VPCommandUtils::exec('git checkout test', $sitePath); self::$wpAutomation->createOption('vp_option_test', 'foo'); VPCommandUtils::exec('git checkout master', $sitePath); VPCommandUtils::exec('git merge test', $sitePath); VPCommandUtils::exec('git branch -d test', $sitePath); $this->commitAsserter->reset(); self::$wpAutomation->runWpCliCommand('vp', 'rollback', [$commitHash]); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCleanWorkingDirectory(); $this->commitAsserter->assertCountOfAffectedFiles(2); $this->commitAsserter->assertCommitPath('D', '%vpdb%/options/vp/vp_option_master.ini'); $this->commitAsserter->assertCommitPath('D', '%vpdb%/options/vp/vp_option_test.ini'); DBAsserter::assertFilesEqualDatabase(); }
/** * Finishes `vp push` * * @subcommand finish-push * */ public function finishPush($args, $assoc_args) { global $versionPressContainer; // Update working copy $resetCommand = "git reset --hard"; $process = VPCommandUtils::exec($resetCommand); if (!$process->isSuccessful()) { WP_CLI::error("Working directory couldn't be reset"); } // Install current Composer dependencies if (file_exists(VP_PROJECT_ROOT . '/composer.json')) { $process = VPCommandUtils::exec('composer install', VP_PROJECT_ROOT); if ($process->isSuccessful()) { WP_CLI::success('Installed Composer dependencies'); } else { WP_CLI::error('Composer dependencies could not be restored.'); } } /** @var ActionsDefinitionRepository $actionsDefinitionRepository */ $actionsDefinitionRepository = $versionPressContainer->resolve(VersionPressServices::ACTIONS_DEFINITION_REPOSITORY); $actionsDefinitionRepository->restoreAllDefinitionFilesFromHistory(); // Run synchronization /** @var SynchronizationProcess $syncProcess */ $syncProcess = $versionPressContainer->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS); $syncProcess->synchronizeAll(); vp_flush_regenerable_options(); vp_disable_maintenance(); $this->flushRewriteRules(); vp_enable_maintenance(); }