refactor(prdescribe): prefer remote base for diff calculation

Update the git diff command to first attempt using the remote origin/base branch, as it is more likely to be up-to-date for pull requests. Fall back to the local base branch if the remote diff fails or is empty.
This commit is contained in:
Gregory Gauthier 2026-03-31 11:31:03 +01:00
parent e0e1100396
commit 029621b916

View File

@ -26,10 +26,10 @@ func init() {
func runPRDescribe(cmd *cobra.Command, _ []string) { func runPRDescribe(cmd *cobra.Command, _ []string) {
base, _ := cmd.Flags().GetString("base") base, _ := cmd.Flags().GetString("base")
// Prefer local base, fallback to origin/<base>. // Prefer remote (more likely up-to-date for PRs), fallback to local.
diff, err := gitDiff([]string{"diff", fmt.Sprintf("%s..HEAD", base), "--no-color"}) diff, err := gitDiff([]string{"diff", fmt.Sprintf("origin/%s..HEAD", base), "--no-color"})
if err != nil || strings.TrimSpace(diff) == "" { if err != nil || strings.TrimSpace(diff) == "" {
diff, err = gitDiff([]string{"diff", fmt.Sprintf("origin/%s..HEAD", base), "--no-color"}) diff, err = gitDiff([]string{"diff", fmt.Sprintf("%s..HEAD", base), "--no-color"})
if err != nil { if err != nil {
color.Red("Failed to get branch diff: %v", err) color.Red("Failed to get branch diff: %v", err)
return return