@@ -10,6 +10,7 @@ import type {
10
10
RepositoryFileSystemChangeEvent ,
11
11
} from '../../../git/models/repository' ;
12
12
import { RepositoryChange , RepositoryChangeComparisonMode } from '../../../git/models/repository' ;
13
+ import { rootSha } from '../../../git/models/revision' ;
13
14
import { sendFeedbackEvent , showUnhelpfulFeedbackPicker } from '../../../plus/ai/aiFeedbackUtils' ;
14
15
import type { AIModelChangeEvent } from '../../../plus/ai/aiProviderService' ;
15
16
import { getRepositoryPickerTitleAndPlaceholder , showRepositoryPicker } from '../../../quickpicks/repositoryPicker' ;
@@ -311,30 +312,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
311
312
const { hunkMap, hunks } = createHunksFromDiffs ( staged ?. contents , unstaged ?. contents ) ;
312
313
313
314
const baseCommit = getSettledValue ( commitResult ) ;
314
- if ( baseCommit == null ) {
315
- const errorMessage = 'No base commit found to compose from.' ;
316
- this . sendTelemetryEvent ( isReload ? 'composer/reloaded' : 'composer/loaded' , {
317
- 'failure.reason' : 'error' ,
318
- 'failure.error.message' : errorMessage ,
319
- } ) ;
320
- return {
321
- ...this . initialState ,
322
- loadingError : errorMessage ,
323
- } ;
324
- }
325
-
326
315
const currentBranch = getSettledValue ( branchResult ) ;
327
- if ( currentBranch == null ) {
328
- const errorMessage = 'No current branch found to compose from.' ;
329
- this . sendTelemetryEvent ( isReload ? 'composer/reloaded' : 'composer/loaded' , {
330
- 'failure.reason' : 'error' ,
331
- 'failure.error.message' : errorMessage ,
332
- } ) ;
333
- return {
334
- ...this . initialState ,
335
- loadingError : errorMessage ,
336
- } ;
337
- }
338
316
339
317
// Create initial commit with empty message (user will add message later)
340
318
const hasStagedChanges = Boolean ( staged ?. contents ) ;
@@ -358,7 +336,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
358
336
} ;
359
337
360
338
// Create safety state snapshot for validation
361
- const safetyState = await createSafetyState ( repo , diffs , baseCommit . sha ) ;
339
+ const safetyState = await createSafetyState ( repo , diffs , baseCommit ? .sha ) ;
362
340
363
341
const aiEnabled = this . getAiEnabled ( ) ;
364
342
const aiModel = await this . container . ai . getModel (
@@ -396,12 +374,14 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
396
374
...this . initialState ,
397
375
hunks : hunks ,
398
376
hunkMap : hunkMap ,
399
- baseCommit : {
400
- sha : baseCommit . sha ,
401
- message : baseCommit . message ?? '' ,
402
- repoName : repo . name ,
403
- branchName : currentBranch . name ,
404
- } ,
377
+ baseCommit : baseCommit
378
+ ? {
379
+ sha : baseCommit . sha ,
380
+ message : baseCommit . message ?? '' ,
381
+ repoName : repo . name ,
382
+ branchName : currentBranch ?. name ?? 'main' ,
383
+ }
384
+ : null ,
405
385
commits : commits ,
406
386
safetyState : safetyState ,
407
387
aiEnabled : aiEnabled ,
@@ -1087,8 +1067,23 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
1087
1067
throw new Error ( errorMessage ) ;
1088
1068
}
1089
1069
1070
+ if ( params . baseCommit ?. sha == null ) {
1071
+ const initialCommitSha = await svc . patch ?. createEmptyInitialCommit ( ) ;
1072
+ if ( initialCommitSha == null ) {
1073
+ // error base we don't have an initial commit
1074
+ this . _context . errors . operation . count ++ ;
1075
+ this . _context . operations . finishAndCommit . errorCount ++ ;
1076
+ const errorMessage = 'Could not create base commit' ;
1077
+ this . sendTelemetryEvent ( 'composer/action/finishAndCommit/failed' , {
1078
+ 'failure.reason' : 'error' ,
1079
+ 'failure.error.message' : errorMessage ,
1080
+ } ) ;
1081
+ throw new Error ( errorMessage ) ;
1082
+ }
1083
+ }
1084
+
1090
1085
// Create unreachable commits from patches
1091
- const shas = await repo . git . patch ?. createUnreachableCommitsFromPatches ( params . baseCommit . sha , diffInfo ) ;
1086
+ const shas = await repo . git . patch ?. createUnreachableCommitsFromPatches ( params . baseCommit ? .sha , diffInfo ) ;
1092
1087
1093
1088
if ( ! shas ?. length ) {
1094
1089
this . _context . errors . operation . count ++ ;
@@ -1101,9 +1096,10 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
1101
1096
throw new Error ( errorMessage ) ;
1102
1097
}
1103
1098
1099
+ const baseRef = params . baseCommit ?. sha ?? ( ( await repo . git . commits . getCommit ( 'HEAD' ) ) ? 'HEAD' : rootSha ) ;
1104
1100
const resultingDiff = (
1105
- await repo . git . diff . getDiff ?.( shas [ shas . length - 1 ] , params . baseCommit . sha , {
1106
- notation : '...' ,
1101
+ await repo . git . diff . getDiff ?.( shas [ shas . length - 1 ] , baseRef , {
1102
+ notation : params . baseCommit ?. sha ? '...' : undefined ,
1107
1103
} )
1108
1104
) ?. contents ;
1109
1105
0 commit comments