Phabricator CLI from Mozilla to support submission of a series of commits.

Installation

moz-phab can be installed with pip3 install MozPhab.

For detailed installation instructions please see:

moz-phab will periodically check for updates and seamlessly install the latest release when available. To force update moz-phab, run moz-phab self-update.

Changelog

https://wiki.mozilla.org/MozPhab#Changelog

Configuration

moz-phab has an INI style configuration file to control defaults: ~/.moz-phab-config

This file will be created if it doesn't exist.

[ui]
no_ansi = False

[vcs]
safe_mode = False

[git]
remote =
command_path =

[hg]
command_path =

[submit]
auto_submit = False
always_blocking = False
warn_untracked = True

[patch]
apply_to = base
create_bookmark = True
always_full_stack = False

[updater]
self_last_check = 0
arc_last_check = 0
self_auto_update = True

[error_reporting]
report_to_sentry = True

moz-phab can also be configured via the following environmental variables:

Execution

To get information about all available commands run

  $ moz-phab -h

All commands involving VCS (like submit and patch) might be used with a --safe-mode switch. It will run the VCS command with only chosen set of extensions.

Submitting commits to Phabricator

The simplest invocation is

  $ moz-phab [start_rev] [end_rev]

If no positional arguments (start_rev/end_rev) are given, the range of commits is automatically determined, starting with the first non-public, non-obsolete changeset (for Mercurial) or first unpublished commit (for Git) and ending with the currently checked-out changeset. If at least one argument is given moz-phab is following the underlying VCS's log behavior. The first argument is interpreted differently in Mercurial (as inclusive) and Git (exclusive). If only one argument is given the end of range is again interpreted as the currently checked-out changeset. If both arguments are given - the second one is interpreted as inclusive.

Bug IDs and reviewers are parsed out of commit messages by default. You can set a reviewer as blocking by appending an exclamation mark to the reviewer's nick, e.g. r=foo!. If submit.always_blocking is set to true (see above), reviewers will always be set to blocking regardless.

A bug ID can also be set for every revision in the series with the --bug option, which overrides any bug IDs in commit messages. Similarly, reviewers can be set for every revision in the series with --reviewer (regular reviewers) and/or --blocker (blocking reviewers), which again overrides any reviewers in commit messages.

Run moz-phab submit -h for more options for submitting revisions.

To submit updates to a commit series, run moz-phab in the same way with the same arguments, that is, specifying the full original range of commits. Note that, while inserting and amending commits should work fine, reordering commits is not yet supported, and deleting commits will leave the associated revisions open, which should be abandoned manually. See bug 1481539 for planned fixes. Also note that "fix-up" commits are not yet supported; see bug 1481542.

MozPhab is not using Arcanist to submit commits to Phabricator. If you wish to do so add the --arc switch. File a bug if you needed to use it because MozPhab failed to submit with default settings.

Downloading a patch from Phabricator

moz-phab patch allows patching an entire stack of revisions. The simplest invocation is

  $ moz-phab patch revision_id

To patch a stack ending with the revision D123 run moz-phab patch D123. Diffs will be downloaded from Phabricator and applied using the underlying VCS (import for Mercurial or apply for Git). A commit for each revision will be created in a new bookmark (Mercurial) or branch (Git).

This behavior can be modified with few options:

Reorganizing the stack

moz-phab reorg [start_rev] [end_rev] allows you to reorganize the stack in Phabricator.

If you've changed the local stack by adding, removing or moving the commits around, you need to change the parent/child relation of the revisions in Phabricator.

moz-phab reorg command will compare the stack, display what will be changed and ask for permission before taking any action.

Associating a commit to an existing phabricator revision

moz-phab tracks which revision is associated with a commit using a line in the commit message. If you want to work on an existing revision from a different machine or environment, we recommend you apply the existing revision from Phabricator using moz-phab patch.

If that isn't an option for whatever reason, you can associate a new commit to the same revision by adding a line similar to the following to the extended commit message:

Differential Revision: https://phabricator.services.mozilla.com/D[revision]

replacing [revision] with the identifier of your revision.

Running arc commands

moz-phab arc allows running Arcanist commands indirectly:

$ moz-phab arc ARG [ARG ...]

arc feature will become moz-phab arc feature.

Reporting Issues

We use Bugzilla to track development.

File bugs in Bugzilla under Conduit :: moz-phab.

Development

To install your code call pip3 install -e . from MozPhab project directory (review by default). Your code will be executed by calling moz-phab-dev.

Tests can be executed with pytest. Integration tests require to have access to git, hg with evolve extension.

All python code must be formatted with black using the default settings.

Submitting patches

Pull Requests are not accepted here; please submit changes to Phabricator using moz-phab.

  1. Follow the setup
  2. Once your patch is written and committed locally, run moz-phab to send it to Phabricator

Local environment

By using suite, you can run a local environment with its own instances of Phabricator, BMO, Hg, and other services.

This enables more thorough integration testing of moz-phab without affecting production data.

You can order the suite to use your local code by calling:

$ docker-compose -f docker-compose.yml -f docker-compose.review.yml run local-dev`