@@ -20,6 +20,7 @@ export abstract class ShadowCheckpointService extends EventEmitter {
20
20
21
21
protected _checkpoints : string [ ] = [ ]
22
22
protected _baseHash ?: string
23
+ protected _hasFirstCheckpoint : boolean = false
23
24
24
25
protected readonly dotGitDir : string
25
26
protected git ?: SimpleGit
@@ -93,6 +94,11 @@ export abstract class ShadowCheckpointService extends EventEmitter {
93
94
94
95
await this . writeExcludeFile ( )
95
96
this . baseHash = await git . revparse ( [ "HEAD" ] )
97
+ // Check if there are any commits beyond the initial commit
98
+ const commits = await git . log ( )
99
+ if ( commits . total > 0 ) {
100
+ this . _hasFirstCheckpoint = true
101
+ }
96
102
} else {
97
103
this . log ( `[${ this . constructor . name } #initShadowGit] creating shadow git repo at ${ this . checkpointsDir } ` )
98
104
await git . init ( )
@@ -211,14 +217,17 @@ export abstract class ShadowCheckpointService extends EventEmitter {
211
217
await this . stageAll ( this . git )
212
218
const commitArgs = options ?. allowEmpty ? { "--allow-empty" : null } : undefined
213
219
const result = await this . git . commit ( message , commitArgs )
214
- const isFirst = this . _checkpoints . length === 0
220
+ const isFirst = ! this . _hasFirstCheckpoint
215
221
const fromHash = this . _checkpoints [ this . _checkpoints . length - 1 ] ?? this . baseHash !
216
222
const toHash = result . commit || fromHash
217
223
this . _checkpoints . push ( toHash )
218
224
const duration = Date . now ( ) - startTime
219
225
220
226
if ( isFirst || result . commit ) {
221
227
this . emit ( "checkpoint" , { type : "checkpoint" , isFirst, fromHash, toHash, duration } )
228
+ if ( isFirst ) {
229
+ this . _hasFirstCheckpoint = true
230
+ }
222
231
}
223
232
224
233
if ( result . commit ) {
0 commit comments