mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
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/<baseBranch> 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).
This commit is contained in:
1 parent
496f687d85
commit
958a48f23d
1 file changed
+18
-3
@@ -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
|
||||
|
||||
Reference in new issue
Block a user