@@ -76,6 +76,7 @@ import {
76
76
ReloadComposerCommand ,
77
77
} from './protocol' ;
78
78
import type { ComposerWebviewShowingArgs } from './registration' ;
79
+ import type { WorkingTreeDiffs } from './utils' ;
79
80
import {
80
81
convertToComposerDiffInfo ,
81
82
createHunksFromDiffs ,
@@ -101,6 +102,9 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
101
102
// Telemetry context - tracks composer-specific data for getTelemetryContext
102
103
private _context : ComposerContext ;
103
104
105
+ // Flag to ignore index change tracking for when we need to stage untracked files
106
+ private _ignoreIndexChange = false ;
107
+
104
108
constructor (
105
109
protected readonly container : Container ,
106
110
protected readonly host : WebviewHost < 'gitlens.composer' > ,
@@ -283,13 +287,30 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
283
287
source ?: Sources ,
284
288
isReload ?: boolean ,
285
289
) : Promise < State > {
290
+ // Stop repo change subscription so we can deal with untracked files
291
+ this . _repositorySubscription ?. dispose ( ) ;
292
+ const status = await repo . git . status ?. getStatus ( ) ;
293
+ const untrackedPaths = status ?. untrackedChanges . map ( f => f . path ) ;
294
+ if ( untrackedPaths ?. length ) {
295
+ try {
296
+ await repo . git . staging ?. stageFiles ( untrackedPaths , { intentToAdd : true } ) ;
297
+ this . _ignoreIndexChange = true ;
298
+ } catch { }
299
+ }
300
+
286
301
const [ diffsResult , commitResult , branchResult ] = await Promise . allSettled ( [
287
302
// Handle baseCommit - could be string (old format) or ComposerBaseCommit (new format)
288
303
getWorkingTreeDiffs ( repo ) ,
289
304
repo . git . commits . getCommit ( 'HEAD' ) ,
290
305
repo . git . branches . getBranch ( ) ,
291
306
] ) ;
292
307
308
+ if ( untrackedPaths ?. length ) {
309
+ try {
310
+ await repo . git . staging ?. unstageFiles ( untrackedPaths ) ;
311
+ } catch { }
312
+ }
313
+
293
314
const diffs = getSettledValue ( diffsResult ) ! ;
294
315
295
316
this . _context . diff . unstagedIncluded = false ;
@@ -741,9 +762,13 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
741
762
742
763
private async onRepositoryChanged ( e : RepositoryChangeEvent ) : Promise < void > {
743
764
if ( e . repository . id !== this . _currentRepository ?. id ) return ;
744
-
765
+ const ignoreIndexChange = this . _ignoreIndexChange ;
766
+ this . _ignoreIndexChange = false ;
745
767
// Only care about index changes (staged/unstaged changes)
746
- if ( ! e . changed ( RepositoryChange . Index , RepositoryChangeComparisonMode . Any ) ) {
768
+ if (
769
+ ! e . changed ( RepositoryChange . Index , RepositoryChangeComparisonMode . Any ) ||
770
+ ( ignoreIndexChange && e . changed ( RepositoryChange . Index , RepositoryChangeComparisonMode . Exclusive ) )
771
+ ) {
747
772
return ;
748
773
}
749
774
@@ -1055,7 +1080,26 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
1055
1080
) ;
1056
1081
1057
1082
// Validate repository safety state before proceeding
1058
- const validation = await validateSafetyState ( repo , params . safetyState , hunksBeingCommitted ) ;
1083
+ // Stop repo change subscription so we can deal with untracked files
1084
+ let workingTreeDiffs : WorkingTreeDiffs | undefined ;
1085
+ if ( this . _context . diff . unstagedIncluded ) {
1086
+ this . _repositorySubscription ?. dispose ( ) ;
1087
+ const status = await repo . git . status ?. getStatus ( ) ;
1088
+ const untrackedPaths = status ?. untrackedChanges . map ( f => f . path ) ;
1089
+ if ( untrackedPaths ?. length ) {
1090
+ try {
1091
+ workingTreeDiffs = await getWorkingTreeDiffs ( repo ) ;
1092
+ await repo . git . staging ?. stageFiles ( untrackedPaths ) ;
1093
+ } catch { }
1094
+ }
1095
+ }
1096
+
1097
+ const validation = await validateSafetyState (
1098
+ repo ,
1099
+ params . safetyState ,
1100
+ hunksBeingCommitted ,
1101
+ workingTreeDiffs ,
1102
+ ) ;
1059
1103
if ( ! validation . isValid ) {
1060
1104
// Clear loading state and show safety error
1061
1105
await this . host . notify ( DidFinishCommittingNotification , undefined ) ;
@@ -1164,7 +1208,7 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
1164
1208
if (
1165
1209
stashCommit &&
1166
1210
stashCommit . ref !== previousStashCommit ?. ref &&
1167
- stashCommit . message === stashMessage
1211
+ stashCommit . message ?. includes ( stashMessage )
1168
1212
) {
1169
1213
stashedSuccessfully = true ;
1170
1214
}
0 commit comments