2011-01-09 15:22:25 -08:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 11:36:08 -08:00
|
|
|
/**
|
|
|
|
* Interfaces with basic information about the working copy.
|
|
|
|
*
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
* @task config
|
2011-02-19 11:36:08 -08:00
|
|
|
*/
|
2015-06-15 15:45:13 +10:00
|
|
|
final class ArcanistWorkingCopyIdentity extends Phobject {
|
2011-01-09 15:22:25 -08:00
|
|
|
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
private $projectConfig;
|
|
|
|
private $projectRoot;
|
|
|
|
private $localConfig = array();
|
|
|
|
private $localMetaDir;
|
|
|
|
private $vcsType;
|
|
|
|
private $vcsRoot;
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2013-01-30 16:26:41 -08:00
|
|
|
public static function newDummyWorkingCopy() {
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
return self::newFromPathWithConfig('/', array());
|
2013-01-30 16:26:41 -08:00
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public static function newFromPath($path) {
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
return self::newFromPathWithConfig($path, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate all the information we need about a directory which we presume
|
|
|
|
* to be a working copy. Particularly, we want to discover:
|
|
|
|
*
|
|
|
|
* - Is the directory inside a working copy (hg, git, svn)?
|
|
|
|
* - If so, what is the root of the working copy?
|
|
|
|
* - Is there a `.arcconfig` file?
|
|
|
|
*
|
|
|
|
* This is complicated, mostly because Subversion has special rules. In
|
|
|
|
* particular:
|
|
|
|
*
|
|
|
|
* - Until 1.7, Subversion put a `.svn/` directory inside //every//
|
|
|
|
* directory in a working copy. After 1.7, it //only// puts one at the
|
|
|
|
* root.
|
|
|
|
* - We allow `.arcconfig` to appear anywhere in a Subversion working copy,
|
|
|
|
* and use the one closest to the directory.
|
|
|
|
* - Although we may use a `.arcconfig` from a subdirectory, we store
|
|
|
|
* metadata in the root's `.svn/`, because it's the only one guaranteed
|
|
|
|
* to exist.
|
|
|
|
*
|
|
|
|
* Users also do these kinds of things in the wild:
|
|
|
|
*
|
|
|
|
* - Put working copies inside other working copies.
|
|
|
|
* - Put working copies inside `.git/` directories.
|
|
|
|
* - Create `.arcconfig` files at `/.arcconfig`, `/home/.arcconfig`, etc.
|
|
|
|
*
|
|
|
|
* This method attempts to be robust against all sorts of possible
|
|
|
|
* misconfiguration.
|
|
|
|
*
|
|
|
|
* @param string Path to load information for, usually the current working
|
|
|
|
* directory (unless running unit tests).
|
|
|
|
* @param map|null Pass `null` to locate and load a `.arcconfig` file if one
|
|
|
|
* exists. Pass a map to use it to set configuration.
|
|
|
|
* @return ArcanistWorkingCopyIdentity Constructed working copy identity.
|
|
|
|
*/
|
|
|
|
private static function newFromPathWithConfig($path, $config) {
|
2011-01-09 15:22:25 -08:00
|
|
|
$project_root = null;
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
$vcs_root = null;
|
|
|
|
$vcs_type = null;
|
|
|
|
|
|
|
|
// First, find the outermost directory which is a Git, Mercurial or
|
|
|
|
// Subversion repository, if one exists. We go from the top because this
|
|
|
|
// makes it easier to identify the root of old SVN working copies (which
|
|
|
|
// have a ".svn/" directory inside every directory in the working copy) and
|
|
|
|
// gives us the right result if you have a Git repository inside a
|
|
|
|
// Subversion repository or something equally ridiculous.
|
|
|
|
|
|
|
|
$paths = Filesystem::walkToRoot($path);
|
|
|
|
$config_paths = array();
|
|
|
|
$paths = array_reverse($paths);
|
|
|
|
foreach ($paths as $path_key => $parent_path) {
|
|
|
|
$try = array(
|
|
|
|
'git' => $parent_path.'/.git',
|
|
|
|
'hg' => $parent_path.'/.hg',
|
|
|
|
'svn' => $parent_path.'/.svn',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($try as $vcs => $try_dir) {
|
|
|
|
if (!Filesystem::pathExists($try_dir)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: We're distinguishing between the `$project_root` and the
|
|
|
|
// `$vcs_root` because they may not be the same in Subversion. Normally,
|
|
|
|
// they are identical. However, in Subversion, the `$vcs_root` is the
|
|
|
|
// base directory of the working copy (the directory which has the
|
|
|
|
// `.svn/` directory, after SVN 1.7), while the `$project_root` might
|
|
|
|
// be any subdirectory of the `$vcs_root`: it's the the directory
|
|
|
|
// closest to the current directory which contains a `.arcconfig`.
|
|
|
|
|
|
|
|
$project_root = $parent_path;
|
|
|
|
$vcs_root = $parent_path;
|
|
|
|
$vcs_type = $vcs;
|
|
|
|
if ($vcs == 'svn') {
|
|
|
|
// For Subversion, we'll look for a ".arcconfig" file here or in
|
|
|
|
// any subdirectory, starting at the deepest subdirectory.
|
|
|
|
$config_paths = array_slice($paths, $path_key);
|
|
|
|
$config_paths = array_reverse($config_paths);
|
|
|
|
} else {
|
|
|
|
// For Git and Mercurial, we'll only look for ".arcconfig" right here.
|
|
|
|
$config_paths = array($parent_path);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
}
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-07 15:24:58 -07:00
|
|
|
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
2014-05-20 11:34:28 -07:00
|
|
|
$looked_in = array();
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
foreach ($config_paths as $config_path) {
|
|
|
|
$config_file = $config_path.'/.arcconfig';
|
2014-05-20 11:34:28 -07:00
|
|
|
$looked_in[] = $config_file;
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
if (Filesystem::pathExists($config_file)) {
|
|
|
|
// We always need to examine the filesystem to look for `.arcconfig`
|
|
|
|
// so we can set the project root correctly. We might or might not
|
|
|
|
// actually read the file: if the caller passed in configuration data,
|
|
|
|
// we'll ignore the actual file contents.
|
|
|
|
$project_root = $config_path;
|
|
|
|
if ($config === null) {
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
2015-05-13 18:05:15 +10:00
|
|
|
pht(
|
|
|
|
'Working Copy: Reading %s from "%s".',
|
|
|
|
'.arcconfig',
|
|
|
|
$config_file));
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
$config_data = Filesystem::readFile($config_file);
|
|
|
|
$config = self::parseRawConfigFile($config_data, $config_file);
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-07 15:24:58 -07:00
|
|
|
}
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
break;
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-07 15:24:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
if ($config === null) {
|
2014-05-20 11:34:28 -07:00
|
|
|
if ($looked_in) {
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
2015-05-13 18:05:15 +10:00
|
|
|
'Working Copy: Unable to find %s in any of these locations: %s.',
|
|
|
|
'.arcconfig',
|
2014-05-20 11:34:28 -07:00
|
|
|
implode(', ', $looked_in)));
|
|
|
|
} else {
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
2015-05-13 18:05:15 +10:00
|
|
|
'Working Copy: No candidate locations for %s from '.
|
|
|
|
'this working directory.',
|
|
|
|
'.arcconfig'));
|
2014-05-20 11:34:28 -07:00
|
|
|
}
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
$config = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($project_root === null) {
|
|
|
|
// We aren't in a working directory at all. This is fine if we're
|
|
|
|
// running a command like "arc help". If we're running something that
|
|
|
|
// requires a working directory, an exception will be raised a little
|
|
|
|
// later on.
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht('Working Copy: Path "%s" is not in any working copy.', $path));
|
|
|
|
return new ArcanistWorkingCopyIdentity($path, $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
'Working Copy: Path "%s" is part of `%s` working copy "%s".',
|
|
|
|
$path,
|
|
|
|
$vcs_type,
|
|
|
|
$vcs_root));
|
|
|
|
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
'Working Copy: Project root is at "%s".',
|
|
|
|
$project_root));
|
|
|
|
|
|
|
|
$identity = new ArcanistWorkingCopyIdentity($project_root, $config);
|
|
|
|
$identity->localMetaDir = $vcs_root.'/.'.$vcs_type;
|
|
|
|
$identity->localConfig = $identity->readLocalArcConfig();
|
|
|
|
$identity->vcsType = $vcs_type;
|
|
|
|
$identity->vcsRoot = $vcs_root;
|
|
|
|
|
|
|
|
return $identity;
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
2011-02-24 16:34:27 -08:00
|
|
|
public static function newFromRootAndConfigFile(
|
|
|
|
$root,
|
|
|
|
$config_raw,
|
|
|
|
$from_where) {
|
|
|
|
|
2013-08-22 16:02:41 -07:00
|
|
|
if ($config_raw === null) {
|
|
|
|
$config = array();
|
|
|
|
} else {
|
|
|
|
$config = self::parseRawConfigFile($config_raw, $from_where);
|
|
|
|
}
|
|
|
|
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
return self::newFromPathWithConfig($root, $config);
|
2011-02-15 14:57:24 -08:00
|
|
|
}
|
|
|
|
|
2011-02-24 16:34:27 -08:00
|
|
|
private static function parseRawConfigFile($raw_config, $from_where) {
|
2014-06-24 09:24:41 +10:00
|
|
|
try {
|
|
|
|
return phutil_json_decode($raw_config);
|
|
|
|
} catch (PhutilJSONParserException $ex) {
|
|
|
|
throw new PhutilProxyException(
|
2015-05-13 18:05:15 +10:00
|
|
|
pht("Unable to parse '%s' file '%s'.", '.arcconfig', $from_where),
|
2014-06-24 09:24:41 +10:00
|
|
|
$ex);
|
2011-02-15 14:57:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
private function __construct($root, array $config) {
|
|
|
|
$this->projectRoot = $root;
|
|
|
|
$this->projectConfig = $config;
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getProjectRoot() {
|
|
|
|
return $this->projectRoot;
|
|
|
|
}
|
|
|
|
|
Lay groundwork for configuration-driven linters
Summary:
Ref T2039. That task has a bunch of discussion, but basically we do a poor job of serving the midrange of lint configuration right now.
If you have something simple, the default linters work.
If you have something complex, building your own engine lets you do whatever you want.
But many users want something in between, which isn't really well accommodated. The idea is to let you write a `.arclint` file, which looks something like this:
{
"linters" : {
"css" : {
"type" : "csslint",
"include" : "(\.css$)",
"exclude" : "(^externals/)",
"bin" : "/usr/local/bin/csslint"
},
"js" : {
"type" : "jshint",
"include" : "(\.js$)",
"exclude" : "(^externals/)",
"bin" : "support/bin/jshint",
"interpreter" : "/usr/local/bin/node"
}
}
}
...which will provide a bunch of common options around lint severity, interpreter and binary locaitons, included and excluded files, etc.
This implements some basics, and very rough support in the Filename linter.
Test Plan:
Generated a `.arclint` file and saw it apply filename lint correctly. Used `debug` mode and tried invalid regexps.
{
"debug" : true,
"linters" : {
"filename" : {
"type" : "filename",
"exclude" : ["@^externals/@"]
}
}
}
Next steps include:
- Provide an external linter archetype (T3186) and expose a common set of configuration here ("bin", "interpreter", "flags", "severity").
- Provide a `.arcunit` file which works similarly (it can probably be simpler).
Reviewers: btrahan, Firehed
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2039
Differential Revision: https://secure.phabricator.com/D6797
2013-08-22 16:02:16 -07:00
|
|
|
public function getProjectPath($to_file) {
|
|
|
|
return $this->projectRoot.'/'.$to_file;
|
|
|
|
}
|
|
|
|
|
Fix working copy binding powers in weird edge cases
Summary:
Fixes T1277. The rules we use to figure out the root of the working copy get a bunch of edge cases wrong right now. A particularly troublesome one is when a user has a `/.arcconfig` or `/home/.arcconfig` or similar, which raises a completely useless and confusing error message (T1277).
Rewrite these rules to get all the edge cases correct and do reasonable things in the presence of stray `.arcconfig`. There are a bunch of comments, but basically the algorithm is:
- From the top, go down one directory at a time until we find ".svn", ".git", or ".hg".
- In Subversion, keep going down looking for ".arcconfig". In Git and Mercurial, look for ".arcconfig" only in the same directory.
- Now that we've figured out the VCS root (where the ".vcs" directory is) and the project root (where the ".arcconfig" file is, if it exists), build an identity.
This logic was also spread across three different places. Consolidate it into one and add some logging so we can figure out what's going wrong if users run into trouble.
Test Plan:
- Ran VCS (`arc list`) and non-VCS (`arc help`) commands in Git, Mercurial, and Subversions roots and subdirectories. Also ran them in non-VCS directories. Ran them with and without .arcconfig. All the outputs seemed completely reasonable.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1277
Differential Revision: https://secure.phabricator.com/D7686
2013-12-03 10:32:31 -08:00
|
|
|
public function getVCSType() {
|
|
|
|
return $this->vcsType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVCSRoot() {
|
|
|
|
return $this->vcsRoot;
|
|
|
|
}
|
|
|
|
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
|
|
|
/* -( Config )------------------------------------------------------------- */
|
|
|
|
|
2013-10-18 16:10:06 -07:00
|
|
|
public function readProjectConfig() {
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
return $this->projectConfig;
|
|
|
|
}
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a configuration directive from project configuration. This reads ONLY
|
|
|
|
* permanent project configuration (i.e., ".arcconfig"), not other
|
|
|
|
* configuration sources. See @{method:getConfigFromAnySource} to read from
|
|
|
|
* user configuration.
|
|
|
|
*
|
|
|
|
* @param key Key to read.
|
|
|
|
* @param wild Default value if key is not found.
|
|
|
|
* @return wild Value, or default value if not found.
|
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*/
|
2013-10-22 15:34:06 -07:00
|
|
|
public function getProjectConfig($key, $default = null) {
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
$settings = new ArcanistSettings();
|
|
|
|
|
|
|
|
$pval = idx($this->projectConfig, $key);
|
|
|
|
|
|
|
|
// Test for older names in the per-project config only, since
|
|
|
|
// they've only been used there.
|
|
|
|
if ($pval === null) {
|
|
|
|
$legacy = $settings->getLegacyName($key);
|
|
|
|
if ($legacy) {
|
2013-10-22 15:34:06 -07:00
|
|
|
$pval = $this->getProjectConfig($legacy);
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($pval === null) {
|
|
|
|
$pval = $default;
|
|
|
|
} else {
|
|
|
|
$pval = $settings->willReadValue($key, $pval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pval;
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
}
|
|
|
|
|
2012-06-13 16:02:29 -07:00
|
|
|
/**
|
2014-07-09 09:12:13 +10:00
|
|
|
* Read a configuration directive from local configuration. This
|
2012-06-13 16:02:29 -07:00
|
|
|
* reads ONLY the per-working copy configuration,
|
|
|
|
* i.e. .(git|hg|svn)/arc/config, and not other configuration
|
2014-07-09 09:12:13 +10:00
|
|
|
* sources. See @{method:getConfigFromAnySource} to read from any
|
2013-10-22 15:34:06 -07:00
|
|
|
* config source or @{method:getProjectConfig} to read permanent
|
2012-06-13 16:02:29 -07:00
|
|
|
* project-level config.
|
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*/
|
2014-06-24 09:24:41 +10:00
|
|
|
public function getLocalConfig($key, $default = null) {
|
2012-06-13 16:02:29 -07:00
|
|
|
return idx($this->localConfig, $key, $default);
|
|
|
|
}
|
|
|
|
|
2013-10-18 16:10:06 -07:00
|
|
|
public function readLocalArcConfig() {
|
|
|
|
if (strlen($this->localMetaDir)) {
|
2014-06-24 09:24:41 +10:00
|
|
|
$local_path = Filesystem::resolvePath('arc/config', $this->localMetaDir);
|
2014-05-20 11:34:28 -07:00
|
|
|
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
2013-10-18 16:10:06 -07:00
|
|
|
if (Filesystem::pathExists($local_path)) {
|
2014-05-20 11:34:28 -07:00
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
'Config: Reading local configuration file "%s"...',
|
|
|
|
$local_path));
|
|
|
|
|
2014-06-24 09:24:41 +10:00
|
|
|
try {
|
2014-06-24 11:40:04 +10:00
|
|
|
$json = Filesystem::readFile($local_path);
|
|
|
|
return phutil_json_decode($json);
|
2014-06-24 09:24:41 +10:00
|
|
|
} catch (PhutilJSONParserException $ex) {
|
|
|
|
throw new PhutilProxyException(
|
|
|
|
pht("Failed to parse '%s' as JSON.", $local_path),
|
|
|
|
$ex);
|
2013-10-18 16:10:06 -07:00
|
|
|
}
|
2014-05-20 11:34:28 -07:00
|
|
|
} else {
|
|
|
|
$console->writeLog(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
'Config: Did not find local configuration at "%s".',
|
|
|
|
$local_path));
|
2013-10-18 16:10:06 -07:00
|
|
|
}
|
2013-04-01 11:26:17 -07:00
|
|
|
}
|
2014-06-24 09:24:41 +10:00
|
|
|
|
2013-10-18 16:10:06 -07:00
|
|
|
return array();
|
|
|
|
}
|
2012-06-13 16:02:29 -07:00
|
|
|
|
2013-10-18 16:10:06 -07:00
|
|
|
public function writeLocalArcConfig(array $config) {
|
2013-12-11 08:29:19 +11:00
|
|
|
$json_encoder = new PhutilJSON();
|
|
|
|
$json = $json_encoder->encodeFormatted($config);
|
|
|
|
|
2013-10-18 16:10:06 -07:00
|
|
|
$dir = $this->localMetaDir;
|
|
|
|
if (!strlen($dir)) {
|
2013-12-11 08:29:19 +11:00
|
|
|
throw new Exception(pht('No working copy to write config into!'));
|
2012-06-13 16:02:29 -07:00
|
|
|
}
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
2013-12-11 08:29:19 +11:00
|
|
|
$local_dir = $dir.DIRECTORY_SEPARATOR.'arc';
|
|
|
|
if (!Filesystem::pathExists($local_dir)) {
|
|
|
|
Filesystem::createDirectory($local_dir, 0755);
|
2012-06-13 16:02:29 -07:00
|
|
|
}
|
|
|
|
|
2013-12-11 08:29:19 +11:00
|
|
|
$config_file = $local_dir.DIRECTORY_SEPARATOR.'config';
|
|
|
|
Filesystem::writeFile($config_file, $json);
|
2013-04-01 11:26:17 -07:00
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|