Skip to content

Add codiff base to review against a branch's PR/MR base#92

Draft
KATT wants to merge 6 commits into
nkzw-tech:mainfrom
KATT:add-base-review-command
Draft

Add codiff base to review against a branch's PR/MR base#92
KATT wants to merge 6 commits into
nkzw-tech:mainfrom
KATT:add-base-review-command

Conversation

@KATT

@KATT KATT commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Adds a codiff base convenience command that reviews the current branch against the branch its open pull/merge request targets. This is useful for stacked changes where the base is another branch in the stack rather than main.

This ports the idea from Alex's cdf helper into Codiff:

cdf() {
  local base=$(gh pr view --json baseRefName -q .baseRefName 2>/dev/null || echo main)
  git fetch origin "$base" --quiet &
  codiff "origin/$base"
}

Behavior

codiff base:

  • Chooses the repository's primary review remote using the same remote priority as PR/MR URL resolution.
  • Resolves the current branch's review base:
    • GitHub: gh pr view --json baseRefName --jq .baseRefName
    • GitLab: glab mr view --output json --jq .target_branch
  • Falls back to the remote default branch (<remote>/HEAD, then main) when there is no open request or the provider CLI is unavailable.
  • Fetches that branch from the remote, then reuses the existing branch review path by opening <remote>/<base>.

The packaged terminal helper delegates codiff base to the Node CLI, so the GitHub/GitLab resolution logic stays in one place instead of being duplicated in shell.

Changes

  • Adds base as a positional CLI keyword in bin/arguments.js.
  • Adds provider-aware base branch resolution in electron/review-source.cjs.
  • Opens the resolved remote branch from bin/codiff.js after a best-effort fetch.
  • Routes packaged codiff base through the bundled Node entry point, like --share.
  • Documents the command in README.md.
  • Covers the new resolver and packaged helper behavior in codiff-cli.test.ts, using explicit resource management for newly added temp resources.

Test plan

  • vp check --fix
  • vp test core/__tests__/codiff-cli.test.ts
  • vp build
  • Manual: run codiff base on a stacked GitHub branch
  • Manual: run codiff base on a GitLab branch

KATT and others added 6 commits June 26, 2026 09:58
Adds a convenience command that diffs the current branch against the
branch its open pull/merge request targets, which is handy for stacked
changes where the base is not `main`. It resolves the base through `gh`
(GitHub) or `glab` (GitLab), chosen from the repository's remote, refreshes
that branch, and reuses the existing branch review path. Falls back to the
remote's default branch when there is no request or the CLI is unavailable.

Based on the `cdf` shell helper from https://x.com/alexdotjs/status/2070398507513495610.

Co-authored-by: Cursor <cursoragent@cursor.com>
Delegate packaged helper handling to the Node CLI and remove duplicated shell-side PR/MR base resolution, keeping the command behavior easier to follow.

Co-authored-by: Cursor <cursoragent@cursor.com>
Handle the `base` convenience keyword during source resolution instead of using a large guard in the positional scanner.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the `codiff base` example on one line like the surrounding usage examples.

Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid adding a helper for bundled Node delegation; keep the packaged helper close to the existing --share handling.

Co-authored-by: Cursor <cursoragent@cursor.com>
Convert the added base-command tests to explicit resource management so temporary directories, PATH overrides, and fake command loggers clean up without large try/finally blocks.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant