@@ -200,6 +200,31 @@ export class Buddy {
200
200
// Create branch
201
201
await gitProvider . createBranch ( branchName , this . config . repository . baseBranch || 'main' )
202
202
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
+
203
228
// Update package.json with new versions
204
229
const packageJsonUpdates = await this . generateAllFileUpdates ( group . updates )
205
230
0 commit comments