}
$user_config = ArcanistBaseWorkflow::readUserConfigurationFile();
+ $global_config = ArcanistBaseWorkflow::readGlobalArcConfig();
$config = $working_copy->getConfig('arcanist_configuration');
if ($config) {
$need_conduit = $need_conduit ||
$need_auth;
$need_working_copy = $need_working_copy ||
- $need_conduit ||
$need_repository_api;
if ($need_working_copy) {
if (!$working_copy->getProjectRoot()) {
throw new ArcanistUsageException(
- "There is no '.arcconfig' file in this directory or any parent ".
- "directory. Create a '.arcconfig' file to configure this project ".
- "for use with Arcanist.");
+ "This command must be run in a Git, Mercurial or Subversion working ".
+ "copy.");
}
$workflow->setWorkingCopy($working_copy);
}
-
if ($force_conduit) {
$conduit_uri = $force_conduit;
} else {
- $conduit_uri = $working_copy->getConduitURI();
+ if ($working_copy->getConduitURI()) {
+ $conduit_uri = $working_copy->getConduitURI();
+ } else {
+ $conduit_uri = idx($global_config, 'default');
+ }
}
if ($conduit_uri) {
// Set the URI path to '/api/'. TODO: Originally, I contemplated letting
if ($need_conduit) {
if (!$conduit_uri) {
- throw new ArcanistUsageException(
- "No Conduit URI is specified in the .arcconfig file for this project. ".
- "Specify the Conduit URI for the host Differential is running on.");
+
+ $message = phutil_console_format(
+ "This command requires arc to connect to a Phabricator install, but ".
+ "no Phabricator installation is configured. To configure a ".
+ "Phabricator URI:\n\n".
+ " - set a default location with `arc set-config default <uri>`; or\n".
+ " - specify '--conduit-uri=uri' explicitly; or\n".
+ " - run 'arc' in a working copy with an '.arcconfig'.\n");
+
+ $message = phutil_console_wrap($message);
+ throw new ArcanistUsageException($message);
}
$workflow->establishConduit();
}
// this directory and belong to the same project.
$project = $this->getWorkingCopyIdentity()->getProjectID();
+ if (!$project) {
+ return array();
+ }
+
$results = $conduit->callMethodSynchronous(
'differential.query',
$query + array(
}
}
- protected function readGlobalArcConfig() {
+ public static function readGlobalArcConfig() {
return idx(self::readUserConfigurationFile(), 'config', array());
}
- protected function writeGlobalArcConfig(array $options) {
+ public static function writeGlobalArcConfig(array $options) {
$config = self::readUserConfigurationFile();
$config['config'] = $options;
self::writeUserConfigurationFile($config);
return $this->repositoryEncoding;
}
+ $default = 'UTF-8';
+
+ $project_id = $this->getWorkingCopy()->getProjectID();
+ if (!$project_id) {
+ return $default;
+ }
+
$project_info = $this->getConduit()->callMethodSynchronous(
'arcanist.projectinfo',
array(
- 'name' => $this->getWorkingCopy()->getProjectID(),
+ 'name' => $project_id,
));
- $this->repositoryEncoding = nonempty($project_info['encoding'], 'UTF-8');
+
+ $this->repositoryEncoding = nonempty($project_info['encoding'], $default);
+
return $this->repositoryEncoding;
}
$actually_close = true;
if ($is_finalize) {
- $project_info = $conduit->callMethodSynchronous(
- 'arcanist.projectinfo',
- array(
- 'name' => $this->getWorkingCopy()->getProjectID(),
- ));
- if ($project_info['tracked'] ||
- $revision['status'] != $status_accepted) {
- $actually_close = false;
+ $project_id = $this->getWorkingCopy()->getProjectID();
+ if ($project_id) {
+ $project_info = $conduit->callMethodSynchronous(
+ 'arcanist.projectinfo',
+ array(
+ 'name' => $project_id,
+ ));
+ if ($project_info['tracked'] ||
+ $revision['status'] != $status_accepted) {
+ $actually_close = false;
+ }
}
}
if ($actually_close) {
public function run() {
$argv = $this->getArgument('argv');
- $config = $this->readGlobalArcConfig();
+ $config = self::readGlobalArcConfig();
if ($argv) {
$keys = $argv;
} else {
throw new ArcanistUsageException("Specify a key and a value.");
}
- $config = $this->readGlobalArcConfig();
+ $config = self::readGlobalArcConfig();
$key = $argv[0];
$val = $argv[1];
if (!strlen($val)) {
unset($config[$key]);
- $this->writeGlobalArcConfig($config);
+ self::writeGlobalArcConfig($config);
if ($old === null) {
echo "Deleted key '{$key}'.\n";
}
} else {
$config[$key] = $val;
- $this->writeGlobalArcConfig($config);
+ self::writeGlobalArcConfig($config);
if ($old === null) {
echo "Set key '{$key}' = '{$val}'.\n";
$project_root = $dir;
break;
}
+
+ if (!$project_root) {
+ foreach (Filesystem::walkToRoot($path) as $dir) {
+ $try = array(
+ $dir.'/.svn',
+ $dir.'/.hg',
+ $dir.'/.git',
+ );
+ foreach ($try as $trydir) {
+ if (Filesystem::pathExists($trydir)) {
+ $project_root = $dir;
+ break 2;
+ }
+ }
+ }
+ }
+
return new ArcanistWorkingCopyIdentity($project_root, $config);
}