Add --base Flag to prdescribe Command for Custom Base Branch Comparison
#3
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/add_base_branch_to_prdescribe"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
This PR introduces a new
--base(or-b) flag to theprdescribecommand, allowing users to specify a custom base branch for generating Git diffs (e.g., comparing againstdevelopinstead of the defaultmaster). This enhances flexibility for repositories with non-standard branching strategies. The default remainsmasterfor backward compatibility.If the initial diff against the specified base is empty or fails, the command falls back to
origin/<base>. Related error messages and warnings have been updated to reflect the chosen base. Unit tests have been added/updated to cover the new behavior.Changes
cmd/prdescribe.go:
--base(short:-b) with default value"master".runPRDescribeto use the flag value ingit diffcommands: first"<base>..HEAD --no-color", then falling back to"origin/<base>..HEAD --no-color"if needed.cmd/run_test.go:
testCmdto register the new--baseflag.--base=developcorrectly passes"develop..HEAD"to the Git command and triggers the AI call."master..HEAD"is used when no flag is provided.No breaking changes; the command behaves as before if
--baseis not specified.Motivation
The existing
prdescribecommand hardcoded comparisons tomainororigin/main, which assumes a specific branching model (e.g., GitHub Flow withmainas the primary branch). Many repositories use alternative base branches likemaster,develop, or custom ones in Git Flow workflows. This flag provides users with the ability to customize the diff base without modifying the code, improving usability and adaptability for diverse project setups.This change was inspired by potential user feedback or issues where the hardcoded
mainled to incorrect diffs in non-standard repos. It aligns with Cobra's flag-based configuration philosophy for CLI tools.Testing Notes
Unit Tests:
cmd/run_test.gocover custom base usage (--base=develop), default behavior (master), and AI call triggering.go test ./cmdto verify. All tests pass locally.Manual Testing:
prdescribe --base=developin a repo with changes on a feature branch. Verify the diff is generated againstdevelop(ororigin/develop) and the AI description is produced.develop, ensure it triesorigin/develop.Dependencies/Impact: No new dependencies. This is a low-risk change affecting only the
prdescribecommand.If this looks good, please review and merge! Let me know if additional tests or adjustments are needed.