@@ -242,37 +242,33 @@ export class CheckpointService {
242242 * repository. Addionally, creates a hidden branch for storing checkpoints.
243243 */
244244 private static async initRepo ( { taskId, git, baseDir, log } : Required < CheckpointServiceOptions > ) {
245- if ( ! existsSync ( path . join ( baseDir , ".git" ) ) ) {
246- try {
247- await git . init ( )
248- log ( `[ensureGitRepo] Initialized new Git repository at ${ baseDir } ` )
249-
250- // We need at least one file to commit, otherwise the initial
251- // commit will fail, unless we use the `--allow-empty` flag.
252- // However, using an empty commit causes problems when restoring
253- // the checkpoint (i.e. the `git restore` command doesn't work
254- // for empty commits).
255- await fs . writeFile ( path . join ( baseDir , ".gitkeep" ) , "" )
256- await git . add ( "." )
257- const commit = await git . commit ( "Initial commit" )
258-
259- if ( ! commit . commit ) {
260- throw new Error ( "Failed to create initial commit" )
261- }
262-
263- log ( `[ensureGitRepo] Initial commit: ${ commit . commit } ` )
264- } catch ( err ) {
265- log (
266- `[ensureGitRepo] Failed to initialize repository: ${ err instanceof Error ? err . message : String ( err ) } ` ,
267- )
268-
269- throw err
270- }
245+ const isExistingRepo = existsSync ( path . join ( baseDir , ".git" ) )
246+
247+ if ( ! isExistingRepo ) {
248+ await git . init ( )
249+ log ( `[initRepo] Initialized new Git repository at ${ baseDir } ` )
271250 }
272251
273252 await git . addConfig ( "user.name" , "Roo Code" )
274253 await git . addConfig ( "user.email" , "[email protected] " ) 275254
255+ if ( ! isExistingRepo ) {
256+ // We need at least one file to commit, otherwise the initial
257+ // commit will fail, unless we use the `--allow-empty` flag.
258+ // However, using an empty commit causes problems when restoring
259+ // the checkpoint (i.e. the `git restore` command doesn't work
260+ // for empty commits).
261+ await fs . writeFile ( path . join ( baseDir , ".gitkeep" ) , "" )
262+ await git . add ( "." )
263+ const commit = await git . commit ( "Initial commit" )
264+
265+ if ( ! commit . commit ) {
266+ throw new Error ( "Failed to create initial commit" )
267+ }
268+
269+ log ( `[initRepo] Initial commit: ${ commit . commit } ` )
270+ }
271+
276272 const currentBranch = await git . revparse ( [ "--abbrev-ref" , "HEAD" ] )
277273 const currentSha = await git . revparse ( [ "HEAD" ] )
278274
0 commit comments