{"record":{"id":"c09f9d79e4f362ba","repo":"phacility/phabricator","slug":"specify-a-commit-and-a-revision-to-attach-it-to","errorCode":null,"errorMessage":"Specify a commit and a revision to attach it to.","messagePattern":"Specify a commit and a revision to attach it to\\.","errorType":"console","errorClass":"PhutilArgumentUsageException","httpStatus":null,"severity":"warning","filePath":"src/applications/differential/management/PhabricatorDifferentialAttachCommitWorkflow.php","lineNumber":26,"sourceCode":"      ->setName('attach-commit')\n      ->setExamples('**attach-commit** __commit__ __revision__')\n      ->setSynopsis(pht('Forcefully attach a commit to a revision.'))\n      ->setArguments(\n        array(\n          array(\n            'name' => 'argv',\n            'wildcard' => true,\n            'help' => pht('Commit, and a revision to attach it to.'),\n          ),\n        ));\n  }\n\n  public function execute(PhutilArgumentParser $args) {\n    $viewer = $this->getViewer();\n\n    $argv = $args->getArg('argv');\n    if (count($argv) !== 2) {\n      throw new PhutilArgumentUsageException(\n        pht('Specify a commit and a revision to attach it to.'));\n    }\n\n    $commit_name = head($argv);\n    $revision_name = last($argv);\n\n    $commit = id(new DiffusionCommitQuery())\n      ->setViewer($viewer)\n      ->withIdentifiers(array($commit_name))\n      ->executeOne();\n    if (!$commit) {\n      throw new PhutilArgumentUsageException(\n        pht('Commit \"%s\" does not exist.', $commit_name));\n    }\n\n    $revision = id(new PhabricatorObjectQuery())\n      ->setViewer($viewer)\n      ->withNames(array($revision_name))","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/differential/management/PhabricatorDifferentialAttachCommitWorkflow.php#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run with exactly two arguments: ./bin/differential attach-commit <commit> <revision> (e.g., ./bin/differential attach-commit rPabcd1234 D456)","In scripts, assert count($argv_extra) === 2 before invoking the workflow","Quote each identifier so shell splitting yields exactly two words"],"exampleFix":"# before\nphabricator/ $ ./bin/differential attach-commit rPabcd1234\n\n# after\nphabricator/ $ ./bin/differential attach-commit rPabcd1234 D456","handlingStrategy":"validation","validationCode":"// Shell wrapper: enforce exactly two positional args\nif [ \"$#\" -ne 2 ]; then\n  echo \"usage: attach-commit <commit> <revision>\" >&2\n  exit 64\nfi\nphabricator/bin/differential attach-commit \"$1\" \"$2\"","typeGuard":null,"tryCatchPattern":"// PHP scripts driving PhutilArgumentParser programmatically:\ntry {\n  $workflow->execute($args);\n} catch (PhutilArgumentUsageException $ex) {\n  // user-input error: print $ex->getMessage() and show usage; do not retry\n}","preventionTips":["Always invoke with exactly two positional args: commit identifier then revision monogram","Quote arguments so identifiers never split into extra words","Wrap automated invocations and assert the argument count before running"],"tags":["phabricator","differential","cli","attach-commit","argument-count","usage-error"],"backgroundTag":"cli-usage-error","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}