Skip to content

refactor(add): replace #N PR syntax with --pr flag#9

Merged
sQVe merged 1 commit into
mainfrom
refactor/add-pr-flag
Jan 3, 2026
Merged

refactor(add): replace #N PR syntax with --pr flag#9
sQVe merged 1 commit into
mainfrom
refactor/add-pr-flag

Conversation

@sQVe

@sQVe sQVe commented Jan 3, 2026

Copy link
Copy Markdown
Owner

Replace grove add #123 syntax with grove add --pr 123 flag.

The #N syntax was problematic because shells interpret # as a comment character, requiring users to quote it (grove add '#123'). The --pr flag is explicit and doesn't require shell escaping.

Changes

  • Replaced grove add #123 with grove add --pr 123 flag
  • Added helpful error message when users try old #N syntax
  • Added validation for negative PR numbers (--pr -5 now errors clearly)
  • Updated README documentation to reflect new syntax

Test plan

  • grove add --pr 7 creates worktree for PR test: integration test PR (DO NOT MERGE) #7
  • grove add '#123' shows: '#123' syntax no longer supported, use: grove add --pr 123
  • grove add --pr -5 shows: --pr must be a positive number
  • grove add --pr 123 feature shows: --pr flag cannot be combined with positional argument

The #N syntax was problematic because shells interpret # as a comment.
Users had to quote it ('grove add "#123"') which was unintuitive.

The --pr flag is explicit and doesn't require shell escaping.
@sQVe sQVe marked this pull request as ready for review January 3, 2026 20:17
Copilot AI review requested due to automatic review settings January 3, 2026 20:17
@sQVe sQVe merged commit af253cd into main Jan 3, 2026
9 checks passed
@sQVe sQVe deleted the refactor/add-pr-flag branch January 3, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the grove add command to replace the problematic #N syntax with an explicit --pr flag, eliminating the need for shell escaping when referencing pull requests by number.

Key Changes:

  • Replaced grove add #123 with grove add --pr 123 syntax
  • Added validation and helpful error messages for the old syntax and edge cases
  • Updated all tests and documentation to reflect the new flag-based approach

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/grove/commands/add.go Implements the new --pr flag, adds validation logic for PR numbers, detects and provides migration guidance for old #N syntax
cmd/grove/commands/add_test.go Updates all unit tests to use the new --pr flag syntax and adds tests for new validation cases
cmd/grove/testdata/script/add_validation.txt Updates validation tests to verify the new --pr flag behavior and error messages
cmd/grove/testdata/script/add_pr_integration.txt Updates integration tests to use --pr flag instead of #N syntax
README.md Updates documentation and examples to show the new --pr flag usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/grove/commands/add.go
Comment on lines +70 to +72
if prNumber < 0 {
return fmt.Errorf("--pr must be a positive number")
}

Copilot AI Jan 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation for zero PR numbers produces a confusing error message. When a user runs grove add --pr 0, the check at line 70 passes (since 0 is not less than 0), but line 75 treats it as if the flag wasn't provided (prFlag = false). This causes line 85 to return "requires branch, PR URL, or --pr flag" even though the user did provide --pr. The validation at line 70 should check prNumber <= 0 to catch this case explicitly and provide a clear error message.

Copilot uses AI. Check for mistakes.
Comment thread cmd/grove/commands/add.go
Comment on lines +95 to +96
return fmt.Errorf("'%s' syntax no longer supported, use: grove add --pr %s",
branchOrPR, strings.TrimPrefix(branchOrPR, "#"))

Copilot AI Jan 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message for the old #N syntax is incomplete when handling edge cases. If a user enters just # without a number, the error message will be malformed: '#' syntax no longer supported, use: grove add --pr (with nothing after --pr). The code should validate that there's actually a number after the # before suggesting the migration, or check against the old regex pattern that required digits.

Suggested change
return fmt.Errorf("'%s' syntax no longer supported, use: grove add --pr %s",
branchOrPR, strings.TrimPrefix(branchOrPR, "#"))
prStr := strings.TrimPrefix(branchOrPR, "#")
if prStr != "" {
allDigits := true
for _, ch := range prStr {
if ch < '0' || ch > '9' {
allDigits = false
break
}
}
if allDigits {
return fmt.Errorf("'%s' syntax no longer supported, use: grove add --pr %s",
branchOrPR, prStr)
}
}

Copilot uses AI. Check for mistakes.
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.

2 participants