5
5
6
6
import * as nls from 'vscode-nls' ;
7
7
import { Command , Disposable , Event , EventEmitter , SourceControlActionButton , Uri , workspace } from 'vscode' ;
8
- import { ApiRepository } from './api/api1' ;
9
- import { Branch , Status } from './api/git' ;
10
- import { IPostCommitCommandsProviderRegistry } from './postCommitCommands' ;
8
+ import { Branch , CommitCommand , Status } from './api/git' ;
9
+ import { CommitCommandsCenter } from './postCommitCommands' ;
11
10
import { Repository , Operation } from './repository' ;
12
11
import { dispose } from './util' ;
13
12
@@ -39,7 +38,7 @@ export class ActionButtonCommand {
39
38
40
39
constructor (
41
40
readonly repository : Repository ,
42
- readonly postCommitCommandsProviderRegistry : IPostCommitCommandsProviderRegistry ) {
41
+ readonly postCommitCommandCenter : CommitCommandsCenter ) {
43
42
this . _state = {
44
43
HEAD : undefined ,
45
44
isCommitInProgress : false ,
@@ -52,7 +51,7 @@ export class ActionButtonCommand {
52
51
repository . onDidRunGitStatus ( this . onDidRunGitStatus , this , this . disposables ) ;
53
52
repository . onDidChangeOperations ( this . onDidChangeOperations , this , this . disposables ) ;
54
53
55
- this . disposables . push ( postCommitCommandsProviderRegistry . onDidChangePostCommitCommandsProviders ( ( ) => this . _onDidChange . fire ( ) ) ) ;
54
+ this . disposables . push ( postCommitCommandCenter . onDidChange ( ( ) => this . _onDidChange . fire ( ) ) ) ;
56
55
57
56
const root = Uri . file ( repository . root ) ;
58
57
this . disposables . push ( workspace . onDidChangeConfiguration ( e => {
@@ -65,6 +64,7 @@ export class ActionButtonCommand {
65
64
if ( e . affectsConfiguration ( 'git.branchProtection' , root ) ||
66
65
e . affectsConfiguration ( 'git.branchProtectionPrompt' , root ) ||
67
66
e . affectsConfiguration ( 'git.postCommitCommand' , root ) ||
67
+ e . affectsConfiguration ( 'git.rememberPostCommitCommand' , root ) ||
68
68
e . affectsConfiguration ( 'git.showActionButton' , root ) ) {
69
69
this . _onDidChange . fire ( ) ;
70
70
}
@@ -92,14 +92,17 @@ export class ActionButtonCommand {
92
92
// The button is disabled
93
93
if ( ! showActionButton . commit ) { return undefined ; }
94
94
95
+ const primaryCommand = this . getCommitActionButtonPrimaryCommand ( ) ;
96
+
95
97
return {
96
- command : this . getCommitActionButtonPrimaryCommand ( ) ,
98
+ command : primaryCommand ,
97
99
secondaryCommands : this . getCommitActionButtonSecondaryCommands ( ) ,
100
+ description : primaryCommand . description ?? primaryCommand . title ,
98
101
enabled : ( this . state . repositoryHasChangesToCommit || this . state . isRebaseInProgress ) && ! this . state . isCommitInProgress && ! this . state . isMergeInProgress
99
102
} ;
100
103
}
101
104
102
- private getCommitActionButtonPrimaryCommand ( ) : Command {
105
+ private getCommitActionButtonPrimaryCommand ( ) : CommitCommand {
103
106
// Rebase Continue
104
107
if ( this . state . isRebaseInProgress ) {
105
108
return {
@@ -111,87 +114,22 @@ export class ActionButtonCommand {
111
114
}
112
115
113
116
// Commit
114
- const config = workspace . getConfiguration ( 'git' , Uri . file ( this . repository . root ) ) ;
115
- const postCommitCommand = config . get < string > ( 'postCommitCommand' ) ;
116
-
117
- // Branch protection
118
- const isBranchProtected = this . repository . isBranchProtected ( ) ;
119
- const branchProtectionPrompt = config . get < 'alwaysCommit' | 'alwaysCommitToNewBranch' | 'alwaysPrompt' > ( 'branchProtectionPrompt' ) ! ;
120
- const alwaysPrompt = isBranchProtected && branchProtectionPrompt === 'alwaysPrompt' ;
121
- const alwaysCommitToNewBranch = isBranchProtected && branchProtectionPrompt === 'alwaysCommitToNewBranch' ;
122
-
123
- // Icon
124
- const icon = alwaysPrompt ? '$(lock)' : alwaysCommitToNewBranch ? '$(git-branch)' : undefined ;
125
-
126
- let commandArg = '' ;
127
- let title = localize ( 'scm button commit title' , "{0} Commit" , icon ?? '$(check)' ) ;
128
- let tooltip = this . state . isCommitInProgress ? localize ( 'scm button committing tooltip' , "Committing Changes..." ) : localize ( 'scm button commit tooltip' , "Commit Changes" ) ;
129
-
130
- // Title, tooltip
131
- switch ( postCommitCommand ) {
132
- case 'push' : {
133
- commandArg = 'git.push' ;
134
- title = localize ( 'scm button commit and push title' , "{0} Commit & Push" , icon ?? '$(arrow-up)' ) ;
135
- if ( alwaysCommitToNewBranch ) {
136
- tooltip = this . state . isCommitInProgress ?
137
- localize ( 'scm button committing to new branch and pushing tooltip' , "Committing to New Branch & Pushing Changes..." ) :
138
- localize ( 'scm button commit to new branch and push tooltip' , "Commit to New Branch & Push Changes" ) ;
139
- } else {
140
- tooltip = this . state . isCommitInProgress ?
141
- localize ( 'scm button committing and pushing tooltip' , "Committing & Pushing Changes..." ) :
142
- localize ( 'scm button commit and push tooltip' , "Commit & Push Changes" ) ;
143
- }
144
- break ;
145
- }
146
- case 'sync' : {
147
- commandArg = 'git.sync' ;
148
- title = localize ( 'scm button commit and sync title' , "{0} Commit & Sync" , icon ?? '$(sync)' ) ;
149
- if ( alwaysCommitToNewBranch ) {
150
- tooltip = this . state . isCommitInProgress ?
151
- localize ( 'scm button committing to new branch and synching tooltip' , "Committing to New Branch & Synching Changes..." ) :
152
- localize ( 'scm button commit to new branch and sync tooltip' , "Commit to New Branch & Sync Changes" ) ;
153
- } else {
154
- tooltip = this . state . isCommitInProgress ?
155
- localize ( 'scm button committing and synching tooltip' , "Committing & Synching Changes..." ) :
156
- localize ( 'scm button commit and sync tooltip' , "Commit & Sync Changes" ) ;
157
- }
158
- break ;
159
- }
160
- default : {
161
- if ( alwaysCommitToNewBranch ) {
162
- tooltip = this . state . isCommitInProgress ?
163
- localize ( 'scm button committing to new branch tooltip' , "Committing Changes to New Branch..." ) :
164
- localize ( 'scm button commit to new branch tooltip' , "Commit Changes to New Branch" ) ;
165
- }
166
- break ;
167
- }
168
- }
169
-
170
- return { command : 'git.commit' , title, tooltip, arguments : [ this . repository . sourceControl , commandArg ] } ;
117
+ return this . postCommitCommandCenter . getPrimaryCommand ( ) ;
171
118
}
172
119
173
120
private getCommitActionButtonSecondaryCommands ( ) : Command [ ] [ ] {
174
- const commandGroups : Command [ ] [ ] = [ ] ;
175
-
176
- if ( ! this . state . isRebaseInProgress ) {
177
- for ( const provider of this . postCommitCommandsProviderRegistry . getPostCommitCommandsProviders ( ) ) {
178
- const commands = provider . getCommands ( new ApiRepository ( this . repository ) ) ;
179
- commandGroups . push ( ( commands ?? [ ] ) . map ( c => {
180
- return {
181
- command : 'git.commit' ,
182
- title : c . title ,
183
- arguments : [ this . repository . sourceControl , c . command ]
184
- } ;
185
- } ) ) ;
186
- }
121
+ // Rebase Continue
122
+ if ( this . state . isRebaseInProgress ) {
123
+ return [ ] ;
124
+ }
187
125
188
- if ( commandGroups . length > 0 ) {
189
- commandGroups [ 0 ] . splice ( 0 , 0 , {
190
- command : 'git.commit' ,
191
- title : localize ( 'scm secondary button commit' , "Commit" ) ,
192
- arguments : [ this . repository . sourceControl , '' ]
193
- } ) ;
194
- }
126
+ // Commit
127
+ const commandGroups : Command [ ] [ ] = [ ] ;
128
+ for ( const commands of this . postCommitCommandCenter . getSecondaryCommands ( ) ) {
129
+ commandGroups . push ( commands . map ( c => {
130
+ // Use the description as title if present
131
+ return { command : 'git.commit' , title : c . description ?? c . title , tooltip : c . tooltip , arguments : c . arguments } ;
132
+ } ) ) ;
195
133
}
196
134
197
135
return commandGroups ;
0 commit comments