{"record":{"id":"23b7a70c2ffd2916","repo":"phacility/phabricator","slug":"to-search-for-commits-which-are-ancestors-of-parti","errorCode":null,"errorMessage":"To search for commits which are ancestors of particular refs, you must constrain the search to exactly one repository.","messagePattern":"To search for commits which are ancestors of particular refs, you must constrain the search to exactly one repository\\.","errorType":"validation","errorClass":"PhabricatorSearchConstraintException","httpStatus":null,"severity":"warning","filePath":"src/applications/diffusion/query/DiffusionCommitQuery.php","lineNumber":555,"sourceCode":"    if ($this->repositoryPHIDs !== null) {\n      $map_repositories = id(new PhabricatorRepositoryQuery())\n        ->setViewer($this->getViewer())\n        ->withPHIDs($this->repositoryPHIDs)\n        ->execute();\n\n      if (!$map_repositories) {\n        throw new PhabricatorEmptyQueryException();\n      }\n      $repository_ids = mpull($map_repositories, 'getID');\n      if ($this->repositoryIDs !== null) {\n        $repository_ids = array_merge($repository_ids, $this->repositoryIDs);\n      }\n      $this->withRepositoryIDs($repository_ids);\n    }\n\n    if ($this->ancestorsOf !== null) {\n      if (count($this->repositoryIDs) !== 1) {\n        throw new PhabricatorSearchConstraintException(\n          pht(\n            'To search for commits which are ancestors of particular refs, '.\n            'you must constrain the search to exactly one repository.'));\n      }\n\n      $repository_id = head($this->repositoryIDs);\n      $history_limit = $this->getRawResultLimit() * 32;\n      $viewer = $this->getViewer();\n\n      $repository = id(new PhabricatorRepositoryQuery())\n        ->setViewer($viewer)\n        ->withIDs(array($repository_id))\n        ->executeOne();\n\n      if (!$repository) {\n        throw new PhabricatorEmptyQueryException();\n      }\n","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/diffusion/query/DiffusionCommitQuery.php#L537-L573","documentation":"DiffusionCommitQuery implements the 'ancestors of refs' constraint by walking history inside a single repository, so the search must be constrained to exactly one repository. With zero or multiple repositories in scope it throws PhabricatorSearchConstraintException rather than return silently wrong results across repos.","triggerScenarios":"A commit search (UI or Conduit) sets the ancestors-of-refs constraint while the Repositories filter is unset ('All Repositories') or selects multiple repositories; also when a projects-based scope expands to more than one repository.","commonSituations":"Users adding the ancestor field to saved queries or dashboards while leaving the default global scope; API callers passing refs plus a multi-repository scope.","solutions":["Constrain the search to exactly one repository via the Repositories filter","Or remove the ancestors-of-refs constraint","Conduit/API callers: pass exactly one repositoryPHID (or a single-element ids/repositories parameter) together with ancestorsOf"],"exampleFix":"// before\n$conduit->executeMethod('diffusion.commit.search', array(\n  'ancestorsOf' => array('master'),\n  // repositories constraint left unset -> 'All Repositories'\n));\n\n// after\n$conduit->executeMethod('diffusion.commit.search', array(\n  'ancestorsOf' => array('master'),\n  'constraints' => array('repositories' => array('PHID-REPO-abcd')),\n));","handlingStrategy":"validation","validationCode":"// before applying the ancestors constraint, assert single-repository scope\nif (count($this->repositoryIDs ?: array()) !== 1) {\n  // do not add ancestorsOf; prompt the user to pick exactly one repository\n}","typeGuard":"function canApplyAncestorConstraint(array $repository_ids) {\n  return count($repository_ids) === 1;\n}","tryCatchPattern":"try {\n  $results = $query->execute();\n} catch (PhabricatorSearchConstraintException $ex) {\n  // surface the constraint message next to the offending filter in the UI\n}","preventionTips":["In shared queries, set the repository filter and the ancestor filter together","API wrappers should validate repositoryPHID count before sending ancestorsOf"],"tags":["search","query-constraint","diffusion","phabricator"],"backgroundTag":"query-constraint-conflict","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}