@@ -78,6 +78,7 @@ import {
7878 ReloadComposerCommand ,
7979} from './protocol' ;
8080import type { ComposerWebviewShowingArgs } from './registration' ;
81+ import type { WorkingTreeDiffs } from './utils' ;
8182import {
8283 convertToComposerDiffInfo ,
8384 createCombinedDiffForCommit ,
@@ -108,6 +109,9 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
108109 // Telemetry context - tracks composer-specific data for getTelemetryContext
109110 private _context : ComposerContext ;
110111
112+ // Flag to ignore index change tracking for when we need to stage untracked files
113+ private _ignoreIndexChange = false ;
114+
111115 constructor (
112116 protected readonly container : Container ,
113117 protected readonly host : WebviewHost < 'gitlens.composer' > ,
@@ -299,13 +303,28 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
299303 source ?: Sources ,
300304 isReload ?: boolean ,
301305 ) : Promise < State > {
306+ // Stop repo change subscription so we can deal with untracked files
307+ this . _repositorySubscription ?. dispose ( ) ;
308+ const status = await repo . git . status ?. getStatus ( ) ;
309+ const untrackedPaths = status ?. untrackedChanges . map ( f => f . path ) ;
310+ if ( untrackedPaths ?. length ) {
311+ try {
312+ await repo . git . staging ?. stageFiles ( untrackedPaths , { intentToAdd : true } ) ;
313+ this . _ignoreIndexChange = true ;
314+ } catch { }
315+ }
316+
302317 const [ diffsResult , commitResult , branchResult ] = await Promise . allSettled ( [
303318 // Handle baseCommit - could be string (old format) or ComposerBaseCommit (new format)
304319 getWorkingTreeDiffs ( repo ) ,
305320 repo . git . commits . getCommit ( 'HEAD' ) ,
306321 repo . git . branches . getBranch ( ) ,
307322 ] ) ;
308323
324+ if ( untrackedPaths ?. length ) {
325+ await repo . git . staging ?. unstageFiles ( untrackedPaths ) . catch ( ) ;
326+ }
327+
309328 const diffs = getSettledValue ( diffsResult ) ! ;
310329
311330 this . _context . diff . unstagedIncluded = false ;
@@ -755,9 +774,13 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
755774
756775 private async onRepositoryChanged ( e : RepositoryChangeEvent ) : Promise < void > {
757776 if ( e . repository . id !== this . _currentRepository ?. id ) return ;
758-
777+ const ignoreIndexChange = this . _ignoreIndexChange ;
778+ this . _ignoreIndexChange = false ;
759779 // Only care about index changes (staged/unstaged changes)
760- if ( ! e . changed ( RepositoryChange . Index , RepositoryChangeComparisonMode . Any ) ) {
780+ if (
781+ ! e . changed ( RepositoryChange . Index , RepositoryChangeComparisonMode . Any ) ||
782+ ( ignoreIndexChange && e . changed ( RepositoryChange . Index , RepositoryChangeComparisonMode . Exclusive ) )
783+ ) {
761784 return ;
762785 }
763786
@@ -1089,7 +1112,26 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
10891112 ) ;
10901113
10911114 // Validate repository safety state before proceeding
1092- const validation = await validateSafetyState ( repo , this . _safetyState , hunksBeingCommitted ) ;
1115+ // Stop repo change subscription so we can deal with untracked files
1116+ let workingTreeDiffs : WorkingTreeDiffs | undefined ;
1117+ if ( this . _context . diff . unstagedIncluded ) {
1118+ this . _repositorySubscription ?. dispose ( ) ;
1119+ const status = await repo . git . status ?. getStatus ( ) ;
1120+ const untrackedPaths = status ?. untrackedChanges . map ( f => f . path ) ;
1121+ if ( untrackedPaths ?. length ) {
1122+ try {
1123+ workingTreeDiffs = await getWorkingTreeDiffs ( repo ) ;
1124+ await repo . git . staging ?. stageFiles ( untrackedPaths ) ;
1125+ } catch { }
1126+ }
1127+ }
1128+
1129+ const validation = await validateSafetyState (
1130+ repo ,
1131+ this . _safetyState ,
1132+ hunksBeingCommitted ,
1133+ workingTreeDiffs ,
1134+ ) ;
10931135 if ( ! validation . isValid ) {
10941136 // Clear loading state and show safety error
10951137 await this . host . notify ( DidFinishCommittingNotification , undefined ) ;
@@ -1197,7 +1239,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
11971239 if (
11981240 stashCommit &&
11991241 stashCommit . ref !== previousStashCommit ?. ref &&
1200- stashCommit . message === stashMessage
1242+ stashCommit . message ?. includes ( stashMessage )
12011243 ) {
12021244 stashedSuccessfully = true ;
12031245 }
0 commit comments