PR Base Branch (Merge-Base)
Deterministic branch-selection rules for PR context collection.
When to Use This Skill
Use this skill when:
- running
VS Code command:drm-copilot: Collect PR Context(command ID:drmCopilotExtension.collectPrContext), - 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 use repository default branch only as last-resort fallback.
- 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:
VS Code command:drm-copilot: Collect PR Context(command ID:drmCopilotExtension.collectPrContext) --base <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.