From 958a48f23da378b06e64a079d4fb574671a6355f Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Wed, 15 Oct 2025 00:47:31 -0500 Subject: [PATCH] Fix patch generation to compare against remote tracking branch Fixed the issue where patch creation failed with "branches are identical" error. The problem was comparing the head branch against local main/master instead of the remote tracking branch (origin/main). For Nostr git repos, users typically have local changes that differ from the remote, so we need to compare against origin/baseBranch to find the unique commits. Changes: - Try to resolve origin/ first (e.g., origin/main) - Fall back to local branch if remote tracking branch doesn't exist - Log which reference is being used for comparison - Update error message to show which branches were compared This ensures patches include all commits that differ from the remote, not just commits that differ from local main (which might be synced with the feature branch). --- src/components/git/PullRequestDialog.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/git/PullRequestDialog.tsx b/src/components/git/PullRequestDialog.tsx index 9e86b98d..8e0d8730 100644 --- a/src/components/git/PullRequestDialog.tsx +++ b/src/components/git/PullRequestDialog.tsx @@ -814,20 +814,35 @@ export function PullRequestDialog({ ref: headBranch, }); + // For remote comparisons, use origin/baseBranch + let baseRef = baseBranch; + try { + // Try to resolve the remote tracking branch first + await git.resolveRef({ + dir: projectPath, + ref: `origin/${baseBranch}`, + }); + baseRef = `origin/${baseBranch}`; + console.log(`Using remote tracking branch: ${baseRef}`); + } catch (err) { + // Fall back to local branch if remote doesn't exist + console.log(`Remote tracking branch origin/${baseBranch} not found, using local ${baseBranch}`); + } + const baseCommits = await git.log({ dir: projectPath, - ref: baseBranch, + ref: baseRef, }); // Find commits unique to head branch const baseCommitIds = new Set(baseCommits.map(c => c.oid)); const uniqueCommits = headCommits.filter(c => !baseCommitIds.has(c.oid)); - console.log(`Found ${uniqueCommits.length} unique commits in ${headBranch}`); + console.log(`Found ${uniqueCommits.length} unique commits in ${headBranch} compared to ${baseRef}`); // Generate patch in git format-patch style if (uniqueCommits.length === 0) { - throw new Error('No commits to create patch from - branches are identical'); + throw new Error(`No commits to create patch from - ${headBranch} and ${baseRef} are identical`); } // Build patch content following git format-patch format