phacility/phabricator · warning · PhutilArgumentUsageException

Specify a commit and a revision to attach it to.

Error message

Specify a commit and a revision to attach it to.

What it means

PhabricatorDifferentialAttachCommitWorkflow (./bin/differential attach-commit) requires exactly two positional arguments: a commit identifier and the Differential revision to attach it to. Any other argument count raises PhutilArgumentUsageException before any database access, so it is pure argument-count validation in the CLI entry point.

Source

Thrown at src/applications/differential/management/PhabricatorDifferentialAttachCommitWorkflow.php:26

      ->setName('attach-commit')
      ->setExamples('**attach-commit** __commit__ __revision__')
      ->setSynopsis(pht('Forcefully attach a commit to a revision.'))
      ->setArguments(
        array(
          array(
            'name' => 'argv',
            'wildcard' => true,
            'help' => pht('Commit, and a revision to attach it to.'),
          ),
        ));
  }

  public function execute(PhutilArgumentParser $args) {
    $viewer = $this->getViewer();

    $argv = $args->getArg('argv');
    if (count($argv) !== 2) {
      throw new PhutilArgumentUsageException(
        pht('Specify a commit and a revision to attach it to.'));
    }

    $commit_name = head($argv);
    $revision_name = last($argv);

    $commit = id(new DiffusionCommitQuery())
      ->setViewer($viewer)
      ->withIdentifiers(array($commit_name))
      ->executeOne();
    if (!$commit) {
      throw new PhutilArgumentUsageException(
        pht('Commit "%s" does not exist.', $commit_name));
    }

    $revision = id(new PhabricatorObjectQuery())
      ->setViewer($viewer)
      ->withNames(array($revision_name))

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Re-run with exactly two arguments: ./bin/differential attach-commit <commit> <revision> (e.g., ./bin/differential attach-commit rPabcd1234 D456)
  2. In scripts, assert count($argv_extra) === 2 before invoking the workflow
  3. Quote each identifier so shell splitting yields exactly two words

Example fix

# before
phabricator/ $ ./bin/differential attach-commit rPabcd1234

# after
phabricator/ $ ./bin/differential attach-commit rPabcd1234 D456
Defensive patterns

Strategy: validation

Validate before calling

// Shell wrapper: enforce exactly two positional args
if [ "$#" -ne 2 ]; then
  echo "usage: attach-commit <commit> <revision>" >&2
  exit 64
fi
phabricator/bin/differential attach-commit "$1" "$2"

Try / catch

// PHP scripts driving PhutilArgumentParser programmatically:
try {
  $workflow->execute($args);
} catch (PhutilArgumentUsageException $ex) {
  // user-input error: print $ex->getMessage() and show usage; do not retry
}

Prevention

When it happens

Trigger: Running './bin/differential attach-commit rPabc123' with only the commit; supplying three arguments; quoting mistakes that split one identifier into several shell words; passing flags after '--' that consume the wrong position.

Common situations: Operators scripting attach-commit in deploy scripts with variable arguments; copy-paste from docs that omit one argument; monograms containing spaces or newlines breaking word splitting.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/c09f9d79e4f362ba. Report an issue: GitHub.