protected function buildBareRepository($callsign)
 {
     $existing_repository = id(new PhabricatorRepositoryQuery())->withCallsigns(array($callsign))->setViewer(PhabricatorUser::getOmnipotentUser())->executeOne();
     if ($existing_repository) {
         $existing_repository->delete();
     }
     $data_dir = dirname(__FILE__) . '/data/';
     $types = array('svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
     $hits = array();
     foreach ($types as $type => $const) {
         $path = $data_dir . $callsign . '.' . $type . '.tgz';
         if (Filesystem::pathExists($path)) {
             $hits[$const] = $path;
         }
     }
     if (!$hits) {
         throw new Exception("No test data for callsign '{$callsign}'. Expected an archive " . "like '{$callsign}.git.tgz' in '{$data_dir}'.");
     }
     if (count($hits) > 1) {
         throw new Exception("Expected exactly one archive matching callsign '{$callsign}', " . "found too many: " . implode(', ', $hits));
     }
     $path = head($hits);
     $vcs_type = head_key($hits);
     $dir = PhutilDirectoryFixture::newFromArchive($path);
     $local = new TempFile('.ignore');
     $user = $this->generateNewTestUser();
     $repo = PhabricatorRepository::initializeNewRepository($user)->setCallsign($callsign)->setName(pht('Test Repo "%s"', $callsign))->setVersionControlSystem($vcs_type)->setDetail('local-path', dirname($local) . '/' . $callsign)->setDetail('remote-uri', 'file://' . $dir->getPath() . '/');
     $this->didConstructRepository($repo);
     $repo->save();
     $repo->makeEphemeral();
     // Keep the disk resources around until we exit.
     $this->dirs[] = $dir;
     $this->dirs[] = $local;
     return $repo;
 }
 public function testStateParsing()
 {
     $dir = dirname(__FILE__) . '/state/';
     $tests = Filesystem::listDirectory($dir, $include_hidden = false);
     foreach ($tests as $test) {
         $fixture = PhutilDirectoryFixture::newFromArchive($dir . '/' . $test);
         $fixture_path = $fixture->getPath();
         $working_copy = ArcanistWorkingCopyIdentity::newFromPath($fixture_path);
         $api = ArcanistRepositoryAPI::newAPIFromWorkingCopyIdentity($working_copy);
         $api->setBaseCommitArgumentRules('arc:this');
         $this->assertCorrectState($test, $api);
     }
 }
 private function parseState($test)
 {
     $dir = dirname(__FILE__) . '/state/';
     $fixture = PhutilDirectoryFixture::newFromArchive($dir . '/' . $test);
     $fixture_path = $fixture->getPath();
     $working_copy = ArcanistWorkingCopyIdentity::newFromPath($fixture_path);
     $configuration_manager = new ArcanistConfigurationManager();
     $configuration_manager->setWorkingCopyIdentity($working_copy);
     $api = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
     $api->setBaseCommitArgumentRules('arc:this');
     if ($api instanceof ArcanistSubversionAPI) {
         // Upgrade the repository so that the test will still pass if the local
         // `svn` is newer than the `svn` which created the repository.
         // NOTE: Some versions of Subversion (1.7.x?) exit with an error code on
         // a no-op upgrade, although newer versions do not. We just ignore the
         // error here; if it's because of an actual problem we'll hit an error
         // shortly anyway.
         $api->execManualLocal('upgrade');
     }
     $this->assertCorrectState($test, $api);
 }
$console = PhutilConsole::getConsole();
$files = $args->getArg('files');
if (count($files) !== 1) {
    throw new PhutilArgumentUsageException(pht('Specify exactly one file to create or edit.'));
}
$file = head($files);
if ($is_create) {
    if (Filesystem::pathExists($file)) {
        throw new PhutilArgumentUsageException(pht('File "%s" already exists, so you can not %s it.', $file, '--create'));
    }
    $fixture = PhutilDirectoryFixture::newEmptyFixture();
} else {
    if (!Filesystem::pathExists($file)) {
        throw new PhutilArgumentUsageException(pht('File "%s" does not exist! Use %s to create a new fixture.', $file, '--create'));
    }
    $fixture = PhutilDirectoryFixture::newFromArchive($file);
}
$console->writeOut("%s\n\n", pht('Spawning an interactive shell. Working directory is:'));
$console->writeOut("    %s\n\n", $fixture->getPath());
if ($is_read_only) {
    $console->writeOut("%s\n", pht('Exit the shell when done (this fixture is read-only).'));
} else {
    $console->writeOut("%s\n", pht('Exit the shell after making changes.'));
}
$err = phutil_passthru('cd %s && sh', $fixture->getPath());
if ($err) {
    $console->writeOut("%s\n", pht('Shell exited with error %d, discarding changes.', $err));
    exit($err);
} else {
    if ($is_read_only) {
        $console->writeOut("%s\n", pht('Invoked in read-only mode, discarding changes.'));