Phabricator/Arcanist

From MediaWiki.org
Jump to navigation Jump to search
If you're not 100 % sure you need Arcanist, you're probably looking for Download from Git and Gerrit/Tutorial instead.

Arcanist is a command line tool that can be used to submit, review and land (commit) patches to git repositories that live (i.e. read/write) on Phabricator; if the clone line has an "eye"/read-only icon on diffusion, it means the repository lives elsewhere, probably on gerrit.

Installation[edit]

Warning Warning: Please install Arcanist using git (the first option below) as it will ensure API compatibility. Using pre-packaged alternatives (eg: Debian repositories, Homebrew or anything that's not on this page) will highly likely cause API compatibility issues.

Using git (recommended)[edit]

This applies to both Linux and OSX systems.

Chose an installation directory (for example ~/phabricator) and clone two repositories into it (libphutil and arcanist).

mkdir ~/phabricator
cd ~/phabricator
git clone -b wmf/stable https://phabricator.wikimedia.org/diffusion/PHUTIL/libphutil.git
git clone -b wmf/stable https://phabricator.wikimedia.org/diffusion/ARC/arcanist.git

You will get two subdirectories in the ~/phabricator directory: arcanist and libphutil. They will be tracking the wmf/stable branch, which is always in sync with our Phabricator installation.

Now add ~/phabricator/arcanist/bin/arc to your PATH (variable). The easiest way to do so on Unix is to add a symlink in a directory already in your PATH, pointing to the arc binary.

Updating
Updating Arcanist is as simple as typing arc upgrade

Debian / Ubuntu packages[edit]

Note Note: If you can, using the Git installation method above is still preferred.

Primarily used for our Continuous Integration servers and to avoid the API compatibility problem explained above, Wikimedia's APT repository provides packages for Debian Jessie and Ubuntu Trusty. We intend to keep these compatible with our Phabricator releases.

You can get our version of the arcanist and libphutil packages from apt.wikimedia.org by creating /etc/apt/sources.d/wikimedia.list with the following contents:

## Wikimedia APT repository
deb http://apt.wikimedia.org/wikimedia jessie-wikimedia main experimental backports 
deb-src http://apt.wikimedia.org/wikimedia jessie-wikimedia main universe

Once you've done that, update your apt cache:

sudo apt-get update

Then finally:

sudo apt-get install arcanist

For more information about the Wikimedia APT repositories, please see wikitech:APT_repository.

Updating
Updating Arcanist should be as simple as doing apt-get update followed by apt-get upgrade

Note Note: Installation on Debian and Ubuntu can be done without adding the Wikimedia APT repository because arcanist is available in the official Debian repositories. However, as above, we strongly recommend that you install either the Wikimedia-maintained package (or, even better, by the Git installation method) for use with phabricator.wikimedia.org to maintain API compatibility.

Arcanist on Mac OSX[edit]

  1. Volunteer developer user:paladox has published a free Arcanist installer for mac osx, and although it is it is not officially supported by either Phacility or the Wikimedia Foundation, it aims to simplify the process of installing Arcanist on mac osx.

Arcanist on Windows[edit]

Arcanist is notoriously difficult to use on Windows, due in large part to the reliance on git which in turn relies on a well behaved POSIX environment. There are various hacks and workarounds that aim to provide a reasonable approximation of a standard Unix environment on top of the Windows platform. The most promising choices that we are currently aware of for running Arcanist on Windows are the following:

  1. As of 2017, git-for-windows is the most well-established solution for using git on Windows.
  2. Microsoft has recently began rolling out first-class support for a POSIX environment as part of the Windows Subsystem for Linux. This is essentially a Unix emulator layer that runs on top of Windows and supports a fairly complete environment based on the GNU/Linux userspace from Ubuntu. This alternative only recently became available as a "beta" feature released with the Windows 10 Anniversary Update.
  3. Volunteer developer user:paladox has published a free Arcanist installer for windows, and although it is it is not officially supported by either Phacility or the Wikimedia Foundation, it aims to simplify the process of installing Arcanist on Windows. This could be especially helpful if you are using an older version of Windows and are unable to install the Windows 10 Anniversary update.

Setup[edit]

Tell Arcanist where your default Phabricator install is (presumably the phabricator.wikimedia.org one)

arc set-config default https://phabricator.wikimedia.org/

Which should respond with something like:

Tournesol.png Example:

Then you should install your personal Phabricator API token.

arc install-certificate

Arc will prompt you to login to Phabricator via the web browser and pick up the API token from the specified location:

Tournesol.png Example:

When clicking a link the following webpage is presented:

Grant Account Access
Copy-paste the API Token below to grant access to your account.

API Token: cli-01234567890abcdef012345678890

This will authorize the requesting script to act on your behalf permanently, like giving the script your account password.

If you change your mind, you can revoke this token later in Settings → Conduit API Tokens.

After the API Token is pasted into the arc window it should say:

Tournesol.png Example:

Using arcanist[edit]

Basics[edit]

Arcanist is a tool that allows you to interact with the code-review tool (aka "Differential") in Phabricator.

Diff[edit]

arc diff will submit your changes to review, example:

 # changes
 git commit -a
 arc diff

The outcome should be something like:

Tournesol.png Example:

Updating an existing Differential revision (which you initially created yourself) requires performing the same steps.

Landing[edit]

Once a change is approved, you can land it, given that you have push access to repository. In a traditional plain git workflow you would generally merge your feature branch manually and push it up to the remote.

Arcanist provides the arc land workflow to automate this process.

Once a revision is accepted in Differential, anyone with the ability to push to the corresponding repository can merge and land the change on Phabricator. The process is straightforward, simply run the command from inside your local clone of the repository as follows, run `arc land D#` where # represents the revision number of the patch you are landing.

Merging another author's change[edit]

In the past, arc land had issues when landing patches by an author other than yourself. This lead us to recommend other methods of landing a patch, however, the bugs have all been fixed and arc land is now recommended workflow regardless of whether it's your own patch or a contribution from some other author.

Example[edit]

Now you can clone an experimental respository using Git:

git clone ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/E3Experiments.git

Go to the repository and try fetching some code:

cd E3Experiments
arc patch D3

The system will ask you:

Tournesol.png Example:

Answer 'Y' and Arcanist should download the change:

Tournesol.png Example:

And you can see the patch in your local repository:

git branch -vv
Tournesol.png Example:

Further Reading[edit]

Now it's time to explore arc help and the User's Guide.

Another resource worth exploring is Khan Academy's "Using Phabricator" documentation. There you will find a really well written introduction to Arcanist and other related topics.