Skip to content

feat(review): default --to to HEAD when only --from is provided #1935

Closed

Description

@lizhengfeng101

Description

Reviewing the current branch against a known base is a common workflow, but the CLI currently requires users to spell out --to HEAD:

ocr review --from main
# Error: --to is required when --from is specified

Support --from <ref> without --to as shorthand for targeting HEAD:

ocr review --from main
# Equivalent to:
ocr review --from main --to HEAD

This must retain the existing range semantics: compare merge-base(main, HEAD) with HEAD, as in git diff main...HEAD. It reviews committed changes, not staged, unstaged, or untracked working-tree changes.

Scope

  • cmd/opencodereview/shared_flags.go: normalize the missing target to HEAD in review-option handling before downstream validation and execution; update flag help. Do not set an unconditional flag default, which would change plain ocr review.
  • cmd/opencodereview/review_cmd.go: update command examples and ensure the shorthand uses the same range-review path as explicit --to HEAD.
  • cmd/opencodereview/flags_test.go and cmd/opencodereview/review_cmd_test.go: replace tests expecting a missing-target error and add regression coverage.
  • pages/src/content/docs/en/cli-reference.md: document the conditional default and its committed-changes-only scope. Keep affected localized documentation in sync; if README examples are updated, sync all localized READMEs as required by the repository.
  • Limit the behavior change to ocr review. Shared flag/validation helpers also serve ocr delegate; preserve that command's existing behavior. No changes to merge-base calculation, automatic fetching, or base-branch inference are needed.

Acceptance Criteria

  • ocr review --from main resolves its target to HEAD and behaves identically to ocr review --from main --to HEAD.
  • Plain ocr review remains workspace mode, including staged, unstaged, and untracked changes. --to is not globally defaulted to HEAD.
  • An explicit --to <ref> remains authoritative. Supplying --to without --from still fails with the existing missing-base error; the CLI does not guess a base branch.
  • --from main --commit <sha> still fails as conflicting review modes, and existing ref-validation safeguards remain intact.
  • A Git-backed preview test verifies shorthand/explicit equivalence on diverged branches: main-only commits and uncommitted changes are not included in the reviewed diff. No LLM request is needed for this test.
  • Preview and existing review metadata/reporting consistently reflect the effective target and resolved range, just as with explicit --to HEAD.
  • Help and documentation explain the shorthand, merge-base semantics, and the distinction from workspace review.
  • Tests cover the new default and unchanged modes, including the shared-helper boundary with ocr delegate.
  • Relevant tests and project checks pass using make test, make check, and make coverage (90% threshold).

Context

This arose while explaining how to review the current branch relative to main. The current rejection is explicit in validateDiffMode and covered by TestParseReviewFlags_FromWithoutTo and TestParseReviewFlagsRejectsFromWithoutTo. The existing diff provider already supports the desired behavior when --to HEAD is supplied; this is a CLI usability improvement, not a new diff mode.

AI/LLM disclosure: This issue was drafted with OpenAI Codex using the gpt-6-astra model.

Activity

  1. added
    enhancement
    good first issue
    help wanted
    on Nov 14, 2026
  2. Walternater commented on Nov 14, 2026

    @Walternater
    Contributor

    I'd like to take this one.

    Plan: normalize a missing --to to HEAD only in the review-option handling (validateReviewOptions), so ocr review --from main takes exactly the same range-review path as --to HEAD, while plain ocr review and delegate keep their current behavior. I'll update the flag help/examples, replace the two rejection tests, add a Git-backed preview test on diverged branches (shorthand ≡ explicit; main-only commits and uncommitted changes excluded), and sync the five cli-reference.md locales. PR to follow.

    AI-assisted: implemented with DeepSeek Harness (deepseek-v4.1-flash); the PR will carry the same disclosure.

  3. Walternater commented on Nov 14, 2026

    @Walternater
    Contributor

    PR opened: #1936 — normalize missing --to to HEAD in review-option validation only, plus a Git-backed preview e2e and 5-locale cli-reference sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions