stageAll() public method

Stages all files under the given path. No path = stage all files in whole working directory.
public stageAll ( string | null $path = null )
$path string | null Null (the default) means the whole working directory
Example #1
0
 /**
  * Calls Git `add -A` on files that are related to the given $changeInfo.
  * The "exchange format" is an array documented in {@see TrackedChangedInfo::getChangedFiles()}.
  *
  * @param TrackedChangeInfo|ChangeInfoEnvelope $changeInfo
  */
 private function stageRelatedFiles($changeInfo)
 {
     if ($changeInfo instanceof ChangeInfoEnvelope) {
         /** @var TrackedChangeInfo $subChangeInfo */
         foreach ($changeInfo->getChangeInfoList() as $subChangeInfo) {
             $this->stageRelatedFiles($subChangeInfo);
         }
         return;
     }
     $changes = $changeInfo->getChangedFiles();
     foreach ($changes as $change) {
         if ($change["type"] === "storage-file") {
             $entityName = $change["entity"];
             $entityId = $change["id"];
             $parentId = $change["parent-id"];
             $path = $this->storageFactory->getStorage($entityName)->getEntityFilename($entityId, $parentId);
         } elseif ($change["type"] === "all-storage-files") {
             $entityName = $change["entity"];
             $path = $this->storageFactory->getStorage($entityName)->getPathCommonToAllEntities();
         } elseif ($change["type"] === "path") {
             $path = $change["path"];
         } else {
             continue;
         }
         $this->repository->stageAll($path);
     }
 }
 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();
     }
 }
Example #3
0
 /**
  * @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]];
 }
Example #5
0
 /**
  * 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", "*****@*****.**");
 }
Example #8
0
 private function commitFile($file, $commitMessage, $fileContent = '')
 {
     file_put_contents(self::$repositoryPath . '/' . $file, $fileContent);
     self::$repository->stageAll();
     $this->commit($commitMessage);
 }
 public static function commit($message = 'Default commit message')
 {
     self::$gitRepository->stageAll();
     self::$gitRepository->commit($message, GitConfig::$wpcliUserName, GitConfig::$wpcliUserEmail);
 }