@@ -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' ;
@@ -311,30 +312,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
311312 const { hunkMap, hunks } = createHunksFromDiffs ( staged ?. contents , unstaged ?. contents ) ;
312313
313314 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-
326315 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- }
338316
339317 // Create initial commit with empty message (user will add message later)
340318 const hasStagedChanges = Boolean ( staged ?. contents ) ;
@@ -358,7 +336,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
358336 } ;
359337
360338 // Create safety state snapshot for validation
361- const safetyState = await createSafetyState ( repo , diffs , baseCommit . sha ) ;
339+ const safetyState = await createSafetyState ( repo , diffs , baseCommit ? .sha ) ;
362340
363341 const aiEnabled = this . getAiEnabled ( ) ;
364342 const aiModel = await this . container . ai . getModel (
@@ -396,12 +374,14 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
396374 ...this . initialState ,
397375 hunks : hunks ,
398376 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 ,
405385 commits : commits ,
406386 safetyState : safetyState ,
407387 aiEnabled : aiEnabled ,
@@ -1087,8 +1067,23 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
10871067 throw new Error ( errorMessage ) ;
10881068 }
10891069
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+
10901085 // 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 ) ;
10921087
10931088 if ( ! shas ?. length ) {
10941089 this . _context . errors . operation . count ++ ;
@@ -1101,9 +1096,10 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
11011096 throw new Error ( errorMessage ) ;
11021097 }
11031098
1099+ const baseRef = params . baseCommit ?. sha ?? ( ( await repo . git . commits . getCommit ( 'HEAD' ) ) ? 'HEAD' : rootSha ) ;
11041100 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 ,
11071103 } )
11081104 ) ?. contents ;
11091105
0 commit comments