@@ -10,6 +10,7 @@ import type {
1010 RepositoryFileSystemChangeEvent ,
1111} from '../../../git/models/repository' ;
1212import { RepositoryChange , RepositoryChangeComparisonMode } from '../../../git/models/repository' ;
13+ import { rootSha } from '../../../git/models/revision' ;
1314import { sendFeedbackEvent , showUnhelpfulFeedbackPicker } from '../../../plus/ai/aiFeedbackUtils' ;
1415import type { AIModelChangeEvent } from '../../../plus/ai/aiProviderService' ;
1516import { getRepositoryPickerTitleAndPlaceholder , showRepositoryPicker } from '../../../quickpicks/repositoryPicker' ;
@@ -347,30 +348,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
347348 this . _hunks = hunks ;
348349
349350 const baseCommit = getSettledValue ( commitResult ) ;
350- if ( baseCommit == null ) {
351- const errorMessage = 'No base commit found to compose from.' ;
352- this . sendTelemetryEvent ( isReload ? 'composer/reloaded' : 'composer/loaded' , {
353- 'failure.reason' : 'error' ,
354- 'failure.error.message' : errorMessage ,
355- } ) ;
356- return {
357- ...this . initialState ,
358- loadingError : errorMessage ,
359- } ;
360- }
361-
362351 const currentBranch = getSettledValue ( branchResult ) ;
363- if ( currentBranch == null ) {
364- const errorMessage = 'No current branch found to compose from.' ;
365- this . sendTelemetryEvent ( isReload ? 'composer/reloaded' : 'composer/loaded' , {
366- 'failure.reason' : 'error' ,
367- 'failure.error.message' : errorMessage ,
368- } ) ;
369- return {
370- ...this . initialState ,
371- loadingError : errorMessage ,
372- } ;
373- }
374352
375353 // Create initial commit with empty message (user will add message later)
376354 const hasStagedChanges = Boolean ( staged ?. contents ) ;
@@ -394,7 +372,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
394372 } ;
395373
396374 // Create safety state snapshot for validation
397- const safetyState = await createSafetyState ( repo , diffs , baseCommit . sha ) ;
375+ const safetyState = await createSafetyState ( repo , diffs , baseCommit ? .sha ) ;
398376 this . _safetyState = safetyState ;
399377
400378 const aiEnabled = this . getAiEnabled ( ) ;
@@ -432,12 +410,14 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
432410 return {
433411 ...this . initialState ,
434412 hunks : hunks ,
435- baseCommit : {
436- sha : baseCommit . sha ,
437- message : baseCommit . message ?? '' ,
438- repoName : repo . name ,
439- branchName : currentBranch . name ,
440- } ,
413+ baseCommit : baseCommit
414+ ? {
415+ sha : baseCommit . sha ,
416+ message : baseCommit . message ?? '' ,
417+ repoName : repo . name ,
418+ branchName : currentBranch ?. name ?? 'main' ,
419+ }
420+ : null ,
441421 commits : commits ,
442422 aiEnabled : aiEnabled ,
443423 ai : {
@@ -1162,8 +1142,23 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
11621142 throw new Error ( errorMessage ) ;
11631143 }
11641144
1145+ if ( params . baseCommit ?. sha == null ) {
1146+ const initialCommitSha = await svc . patch ?. createEmptyInitialCommit ( ) ;
1147+ if ( initialCommitSha == null ) {
1148+ // error base we don't have an initial commit
1149+ this . _context . errors . operation . count ++ ;
1150+ this . _context . operations . finishAndCommit . errorCount ++ ;
1151+ const errorMessage = 'Could not create base commit' ;
1152+ this . sendTelemetryEvent ( 'composer/action/finishAndCommit/failed' , {
1153+ 'failure.reason' : 'error' ,
1154+ 'failure.error.message' : errorMessage ,
1155+ } ) ;
1156+ throw new Error ( errorMessage ) ;
1157+ }
1158+ }
1159+
11651160 // Create unreachable commits from patches
1166- const shas = await repo . git . patch ?. createUnreachableCommitsFromPatches ( params . baseCommit . sha , diffInfo ) ;
1161+ const shas = await repo . git . patch ?. createUnreachableCommitsFromPatches ( params . baseCommit ? .sha , diffInfo ) ;
11671162
11681163 if ( ! shas ?. length ) {
11691164 this . _context . errors . operation . count ++ ;
@@ -1176,9 +1171,10 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
11761171 throw new Error ( errorMessage ) ;
11771172 }
11781173
1174+ const baseRef = params . baseCommit ?. sha ?? ( ( await repo . git . commits . getCommit ( 'HEAD' ) ) ? 'HEAD' : rootSha ) ;
11791175 const resultingDiff = (
1180- await repo . git . diff . getDiff ?.( shas [ shas . length - 1 ] , params . baseCommit . sha , {
1181- notation : '...' ,
1176+ await repo . git . diff . getDiff ?.( shas [ shas . length - 1 ] , baseRef , {
1177+ notation : params . baseCommit ?. sha ? '...' : undefined ,
11821178 } )
11831179 ) ?. contents ;
11841180
0 commit comments