PR Base Branch (Merge-Base)
Deterministic branch-selection rules for PR context collection.
When to Use This Skill
Use this skill when:
- running
mcp__drm-copilot__collect_pr_context, - delegating post-implementation review that depends on
PRBaseBranch, - constructing PR context artifacts where the base must not be hard-coded.
Selection Contract
PRBaseBranch MUST be resolved from git ancestry, not guessed.
Definition of correct base:
- choose the candidate branch whose merge-base with
HEADhas the most recent commit timestamp, - this implements “find the branch with the most recent commit in common.”
Deterministic Procedure
- Enumerate candidate branches from local and remotes, excluding
HEADand detached refs. - For each candidate
B, compute merge-base commitM = git merge-base HEAD B. - Compute
merge_base_epoch(B)fromgit show -s --format=%ct M. - Select branch with maximum
merge_base_epoch(B). - Tie-breakers (in order):
developmentmainmaster- lexical ascending branch name
Guardrails
- Do not default to
mainunless merge-base resolution fails for all candidates. - If all candidates fail, surface explicit error context and stop unless repository metadata directly identifies the default branch.
- Persist chosen
PRBaseBranchin orchestration state and reuse it within the same run.
Collector Invocation Rule
When invoking PR context collection, pass the resolved base explicitly:
mcp__drm-copilot__collect_pr_contextwithbase=<resolved-PRBaseBranch>
Evidence Recommendation
For auditability, include in logs/checkpoint:
- selected branch name,
- selected merge-base SHA,
- selected merge-base timestamp,
- top competing candidates with timestamps when available.