/** * @test */ public function itSupportsWildcards() { touch(self::$repositoryPath . '/somefile'); touch(self::$repositoryPath . '/otherfile'); $this->commitEverything(); unlink(self::$repositoryPath . '/somefile'); $this->commitEverything(); $modifications = self::$repository->getFileModifications('*file'); $log = self::$repository->log(); $expectedModifications = [['status' => 'D', 'path' => 'somefile', 'commit' => $log[0]->getHash()], ['status' => 'A', 'path' => 'otherfile', 'commit' => $log[1]->getHash()], ['status' => 'A', 'path' => 'somefile', 'commit' => $log[1]->getHash()]]; $this->assertEquals($expectedModifications, $modifications); }
public function restoreAllDefinitionFilesFromHistory() { FileSystem::removeContent($this->directory); $definitionFilesWildcard = WP_PLUGIN_DIR . '/*/.versionpress/actions.yml'; $modifications = $this->gitRepository->getFileModifications($definitionFilesWildcard); $modifications = array_filter($modifications, function ($modification) { return $modification['status'] !== 'D'; }); $lastModifications = ArrayUtils::unique($modifications, function ($modification) { return $modification['path']; }); foreach ($lastModifications as $modification) { $fileContent = $this->gitRepository->getFileInRevision($modification['path'], $modification['commit']); $plugin = basename(dirname(dirname($modification['path']))); $targetFile = $this->getDefinitionFileName($plugin); file_put_contents($targetFile, $fileContent); } $this->saveDefinitionForPlugin('versionpress/versionpress.php'); }