3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Disposable , Event , EventEmitter , SourceControlActionButton , Uri , workspace } from 'vscode' ;
7
6
import * as nls from 'vscode-nls' ;
7
+ import { Disposable , Event , EventEmitter , SourceControlActionButton , Uri , workspace } from 'vscode' ;
8
+ import { Branch , Status } from './api/git' ;
8
9
import { Repository , Operation } from './repository' ;
9
10
import { dispose } from './util' ;
10
- import { Branch } from './api/git' ;
11
11
12
12
const localize = nls . loadMessageBundle ( ) ;
13
13
@@ -16,7 +16,7 @@ interface ActionButtonState {
16
16
readonly isCommitInProgress : boolean ;
17
17
readonly isMergeInProgress : boolean ;
18
18
readonly isSyncInProgress : boolean ;
19
- readonly repositoryHasChanges : boolean ;
19
+ readonly repositoryHasChangesToCommit : boolean ;
20
20
}
21
21
22
22
export class ActionButtonCommand {
@@ -40,19 +40,24 @@ export class ActionButtonCommand {
40
40
isCommitInProgress : false ,
41
41
isMergeInProgress : false ,
42
42
isSyncInProgress : false ,
43
- repositoryHasChanges : false
43
+ repositoryHasChangesToCommit : false
44
44
} ;
45
45
46
46
repository . onDidRunGitStatus ( this . onDidRunGitStatus , this , this . disposables ) ;
47
47
repository . onDidChangeOperations ( this . onDidChangeOperations , this , this . disposables ) ;
48
48
49
49
const root = Uri . file ( repository . root ) ;
50
50
this . disposables . push ( workspace . onDidChangeConfiguration ( e => {
51
+ if ( e . affectsConfiguration ( 'git.enableSmartCommit' , root ) ||
52
+ e . affectsConfiguration ( 'git.smartCommitChanges' , root ) ||
53
+ e . affectsConfiguration ( 'git.suggestSmartCommit' , root ) ) {
54
+ this . onDidChangeSmartCommitSettings ( ) ;
55
+ }
56
+
51
57
if ( e . affectsConfiguration ( 'git.branchProtection' , root ) ||
52
58
e . affectsConfiguration ( 'git.branchProtectionPrompt' , root ) ||
53
59
e . affectsConfiguration ( 'git.postCommitCommand' , root ) ||
54
- e . affectsConfiguration ( 'git.showActionButton' , root )
55
- ) {
60
+ e . affectsConfiguration ( 'git.showActionButton' , root ) ) {
56
61
this . _onDidChange . fire ( ) ;
57
62
}
58
63
} ) ) ;
@@ -63,7 +68,7 @@ export class ActionButtonCommand {
63
68
64
69
let actionButton : SourceControlActionButton | undefined ;
65
70
66
- if ( this . state . repositoryHasChanges ) {
71
+ if ( this . state . repositoryHasChangesToCommit ) {
67
72
// Commit Changes (enabled)
68
73
actionButton = this . getCommitActionButton ( ) ;
69
74
}
@@ -160,7 +165,7 @@ export class ActionButtonCommand {
160
165
} ,
161
166
]
162
167
] ,
163
- enabled : this . state . repositoryHasChanges && ! this . state . isCommitInProgress && ! this . state . isMergeInProgress
168
+ enabled : this . state . repositoryHasChangesToCommit && ! this . state . isCommitInProgress && ! this . state . isMergeInProgress
164
169
} ;
165
170
}
166
171
@@ -223,19 +228,47 @@ export class ActionButtonCommand {
223
228
this . state = { ...this . state , isCommitInProgress, isSyncInProgress } ;
224
229
}
225
230
231
+ private onDidChangeSmartCommitSettings ( ) : void {
232
+ this . state = {
233
+ ...this . state ,
234
+ repositoryHasChangesToCommit : this . repositoryHasChangesToCommit ( )
235
+ } ;
236
+ }
237
+
226
238
private onDidRunGitStatus ( ) : void {
227
239
this . state = {
228
240
...this . state ,
229
241
HEAD : this . repository . HEAD ,
230
- isMergeInProgress :
231
- this . repository . mergeGroup . resourceStates . length !== 0 ,
232
- repositoryHasChanges :
233
- this . repository . indexGroup . resourceStates . length !== 0 ||
234
- this . repository . untrackedGroup . resourceStates . length !== 0 ||
235
- this . repository . workingTreeGroup . resourceStates . length !== 0
242
+ isMergeInProgress : this . repository . mergeGroup . resourceStates . length !== 0 ,
243
+ repositoryHasChangesToCommit : this . repositoryHasChangesToCommit ( )
236
244
} ;
237
245
}
238
246
247
+ private repositoryHasChangesToCommit ( ) : boolean {
248
+ const config = workspace . getConfiguration ( 'git' , Uri . file ( this . repository . root ) ) ;
249
+ const enableSmartCommit = config . get < boolean > ( 'enableSmartCommit' ) === true ;
250
+ const suggestSmartCommit = config . get < boolean > ( 'suggestSmartCommit' ) === true ;
251
+ const smartCommitChanges = config . get < 'all' | 'tracked' > ( 'smartCommitChanges' , 'all' ) ;
252
+
253
+ const resources = [ ...this . repository . indexGroup . resourceStates ] ;
254
+
255
+ if (
256
+ // Smart commit enabled (all)
257
+ ( enableSmartCommit && smartCommitChanges === 'all' ) ||
258
+ // Smart commit disabled, smart suggestion enabled
259
+ ( ! enableSmartCommit && suggestSmartCommit )
260
+ ) {
261
+ resources . push ( ...this . repository . workingTreeGroup . resourceStates ) ;
262
+ }
263
+
264
+ // Smart commit enabled (tracked only)
265
+ if ( enableSmartCommit && smartCommitChanges === 'tracked' ) {
266
+ resources . push ( ...this . repository . workingTreeGroup . resourceStates . filter ( r => r . type !== Status . UNTRACKED ) ) ;
267
+ }
268
+
269
+ return resources . length !== 0 ;
270
+ }
271
+
239
272
dispose ( ) : void {
240
273
this . disposables = dispose ( this . disposables ) ;
241
274
}
0 commit comments