Skip to content

Commit 97d35ea

Browse files
committed
CRITICAL FIX: Reset to clean main state before generating file updates to prevent cross-contamination between PRs
1 parent d318923 commit 97d35ea

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/buddy.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,31 @@ export class Buddy {
200200
// Create branch
201201
await gitProvider.createBranch(branchName, this.config.repository.baseBranch || 'main')
202202

203+
// Ensure we're on a clean main branch before generating updates
204+
// This prevents reading modified files from previous PR generations
205+
try {
206+
const { spawn } = await import('node:child_process')
207+
const runGitCommand = (command: string, args: string[]): Promise<void> => {
208+
return new Promise((resolve, reject) => {
209+
const child = spawn(command, args, { stdio: 'pipe' })
210+
child.on('close', (code) => {
211+
if (code === 0) resolve()
212+
else reject(new Error(`Git command failed with code ${code}`))
213+
})
214+
child.on('error', reject)
215+
})
216+
}
217+
218+
// Reset to clean main state before generating file updates
219+
await runGitCommand('git', ['checkout', 'main'])
220+
await runGitCommand('git', ['reset', '--hard', 'HEAD'])
221+
await runGitCommand('git', ['clean', '-fd'])
222+
console.log(`🧹 Reset to clean main state before generating updates for ${group.name}`)
223+
}
224+
catch (error) {
225+
console.warn(`⚠️ Failed to reset to clean state, continuing anyway:`, error)
226+
}
227+
203228
// Update package.json with new versions
204229
const packageJsonUpdates = await this.generateAllFileUpdates(group.updates)
205230

src/utils/composer-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export async function generateComposerUpdates(updates: Array<{ name: string, new
211211
for (const [filePath, fileUpdates_] of updatesByFile) {
212212
try {
213213
console.log(`🐛 COMPOSER PARSER DEBUG: Processing file ${filePath} with ${fileUpdates_.length} updates`)
214-
214+
215215
// Read current composer.json content
216216
const fs = await import('node:fs')
217217
let composerContent = fs.readFileSync(filePath, 'utf-8')

0 commit comments

Comments
 (0)