private function doInitializationCommit($isUpdate) { $this->checkTimeout(); // Since WP-217 the `.active` file contains not the SHA1 of the first commit that VersionPress // created but the one before that (which may be an empty string if VersionPress's commit // was the first one in the repository). $lastCommitHash = $this->repository->getLastCommitHash(); file_put_contents(VERSIONPRESS_ACTIVATION_FILE, $lastCommitHash); $this->reportProgressChange(InitializerStates::CREATING_INITIAL_COMMIT); $action = $isUpdate ? 'update' : 'activate'; $committedFiles = [["type" => "path", "path" => "*"]]; $changeInfo = $this->changeInfoFactory->createTrackedChangeInfo('versionpress', $action, VersionPress::getVersion(), [], $committedFiles); $currentUser = wp_get_current_user(); /** @noinspection PhpUndefinedFieldInspection */ $authorName = $currentUser->display_name; /** @noinspection PhpUndefinedFieldInspection */ $authorEmail = $currentUser->user_email; if (defined('WP_CLI') && WP_CLI) { $authorName = GitConfig::$wpcliUserName; $authorEmail = GitConfig::$wpcliUserEmail; } try { $this->adjustGitProcessTimeout(); $this->repository->stageAll(); $this->adjustGitProcessTimeout(); $this->repository->commit($changeInfo->getCommitMessage(), $authorName, $authorEmail); } catch (ProcessTimedOutException $ex) { $this->abortInitialization(); } }
/** * @test */ public function allCommitsContainListOfChangedFiles() { touch(self::$repositoryPath . '/somefile'); self::$repository->stageAll(); self::$repository->commit(new CommitMessage("Some commit"), "Author name", "*****@*****.**"); touch(self::$repositoryPath . '/otherfile'); self::$repository->stageAll(); self::$repository->commit(new CommitMessage("Other commit"), "Author name", "*****@*****.**"); $log = self::$repository->log(); $lastCommit = $log[0]; $expectedChangedFilesInLastCommit = [['status' => 'A', 'path' => 'otherfile']]; $this->assertEquals($expectedChangedFilesInLastCommit, $lastCommit->getChangedFiles()); $previousCommit = $log[1]; $expectedChangedFilesInPreviousCommit = [['status' => 'A', 'path' => 'somefile']]; $this->assertEquals($expectedChangedFilesInPreviousCommit, $previousCommit->getChangedFiles()); }
public function prepare_undoNonDbChange() { $newFile = 'vp-file.txt'; file_put_contents($this->testConfig->testSite->path . '/' . $newFile, ''); $this->repository->stageAll($newFile); $this->repository->commit('Manual commit', 'John Tester', '*****@*****.**'); return [['D', $newFile]]; }
/** * Checks if there is any change in the `$mirror` and commits it. If there was a forced * change set, it takes precedence. */ public function commit() { if ($this->commitDisabled) { return; } if (count($this->forcedChangeInfos) > 0) { $changeInfoList = $this->forcedChangeInfos; } elseif ($this->shouldCommit()) { $changeInfoList = array_merge($this->postponedChangeInfos, $this->mirror->getChangeList()); if (empty($changeInfoList)) { return; } } else { return; } if ($this->commitPostponed) { $this->postponeChangeInfo($changeInfoList); $this->commitPostponed = false; $this->postponeKey = null; $this->flushChangeLists(); return; } if (is_user_logged_in() && is_admin()) { $currentUser = wp_get_current_user(); /** @noinspection PhpUndefinedFieldInspection */ $authorName = $currentUser->display_name; /** @noinspection PhpUndefinedFieldInspection */ $authorEmail = $currentUser->user_email; } else { if (defined('WP_CLI') && WP_CLI) { $authorName = GitConfig::$wpcliUserName; $authorEmail = GitConfig::$wpcliUserEmail; } else { $authorName = "Non-admin action"; $authorEmail = "*****@*****.**"; } } $changeInfoLists = $this->preprocessChangeInfoList($changeInfoList); $mutex = new Mutex(VERSIONPRESS_TEMP_DIR, 'committer-stage-commit'); $mutex->lock(); if (count($this->forcedChangeInfos) === 1) { // If there is one forced change info, we can commit all changes made by change info objects emitted from // storages. If there will be more forced change info objects in the future, we have to come up with // something smarter. For now, it solves WP-430. $this->stageRelatedFiles(new ChangeInfoEnvelope($this->mirror->getChangeList())); } foreach ($changeInfoLists as $listToCommit) { $changeInfoEnvelope = new ChangeInfoEnvelope($listToCommit); $this->stageRelatedFiles($changeInfoEnvelope); $this->repository->commit($changeInfoEnvelope->getCommitMessage(), $authorName, $authorEmail); } $mutex->release(); if (count($this->forcedChangeInfos) > 0 && $this->forcedChangeInfos[0]->getScope() === 'wordpress') { FileSystem::remove(ABSPATH . 'versionpress.maintenance'); } $this->flushChangeLists(); }
/** * Creates manual commit. Adds everything to stage. * * @param WP_REST_Request $request * @return WP_REST_Response|\WP_Error */ public function commit(WP_REST_Request $request) { $currentUser = wp_get_current_user(); if ($currentUser->ID === 0) { return new \WP_Error('error', 'You don\'t have permission to do this.', array('status' => 403)); } /** @noinspection PhpUndefinedFieldInspection */ $authorName = $currentUser->display_name; /** @noinspection PhpUndefinedFieldInspection */ $authorEmail = $currentUser->user_email; $this->gitRepository->stageAll(); $status = $this->gitRepository->getStatus(true); if (ArrayUtils::any($status, function ($fileStatus) { return Strings::contains($fileStatus[1], 'vpdb'); })) { $this->updateDatabase($status); } $this->gitRepository->commit($request['commit-message'], $authorName, $authorEmail); return new WP_REST_Response(true); }
/** * Creates manual commit. Adds everything to stage. * * @param WP_REST_Request $request * @return WP_REST_Response|WP_Error */ public function commit(WP_REST_Request $request) { $currentUser = wp_get_current_user(); if ($currentUser->ID === 0) { return new WP_Error('error', 'You don\'t have permission to do this.', ['status' => 403]); } /** @noinspection PhpUndefinedFieldInspection */ $authorName = $currentUser->display_name; /** @noinspection PhpUndefinedFieldInspection */ $authorEmail = $currentUser->user_email; $this->gitRepository->stageAll(); $status = $this->gitRepository->getStatus(true); if (ArrayUtils::any($status, function ($fileStatus) { $vpdbName = basename(VP_VPDB_DIR); return Strings::contains($fileStatus[1], $vpdbName); })) { $this->updateDatabase($status); } $commitMessage = new CommitMessage($request['commit-message']); $changeInfoEnvelope = new ChangeInfoEnvelope([new UntrackedChangeInfo($commitMessage)]); $this->gitRepository->commit($changeInfoEnvelope->getCommitMessage(), $authorName, $authorEmail); return new WP_REST_Response(true); }
private function commitEverything() { self::$repository->stageAll(); self::$repository->commit(new CommitMessage("Some commit"), "Author name", "*****@*****.**"); }
private function commit($message) { self::$repository->commit($message, 'Author name', '*****@*****.**'); }
public static function commit($message = 'Default commit message') { self::$gitRepository->stageAll(); self::$gitRepository->commit($message, GitConfig::$wpcliUserName, GitConfig::$wpcliUserEmail); }