@@ -13,7 +13,7 @@ const localize = nls.loadMessageBundle();
13
13
14
14
interface ActionButtonState {
15
15
readonly HEAD : Branch | undefined ;
16
- readonly isSyncRunning : boolean ;
16
+ readonly isActionRunning : boolean ;
17
17
readonly repositoryHasNoChanges : boolean ;
18
18
}
19
19
@@ -33,7 +33,7 @@ export class ActionButtonCommand {
33
33
private disposables : Disposable [ ] = [ ] ;
34
34
35
35
constructor ( readonly repository : Repository ) {
36
- this . _state = { HEAD : undefined , isSyncRunning : false , repositoryHasNoChanges : false } ;
36
+ this . _state = { HEAD : undefined , isActionRunning : false , repositoryHasNoChanges : false } ;
37
37
38
38
repository . onDidRunGitStatus ( this . onDidRunGitStatus , this , this . disposables ) ;
39
39
repository . onDidChangeOperations ( this . onDidChangeOperations , this , this . disposables ) ;
@@ -50,49 +50,63 @@ export class ActionButtonCommand {
50
50
let actionButton : SourceControlActionButton | undefined ;
51
51
if ( showActionButton === 'always' || ( showActionButton === 'whenEmpty' && this . state . repositoryHasNoChanges && noPostCommitCommand ) ) {
52
52
if ( this . state . HEAD . upstream ) {
53
- if ( this . state . HEAD . ahead ) {
54
- const config = workspace . getConfiguration ( 'git' , Uri . file ( this . repository . root ) ) ;
55
- const rebaseWhenSync = config . get < string > ( 'rebaseWhenSync' ) ;
56
-
57
- const ahead = `${ this . state . HEAD . ahead } $(arrow-up)` ;
58
- const behind = this . state . HEAD . behind ? `${ this . state . HEAD . behind } $(arrow-down) ` : '' ;
59
- const icon = this . state . isSyncRunning ? '$(sync~spin)' : '$(sync)' ;
60
-
61
- actionButton = {
62
- command : {
63
- command : this . state . isSyncRunning ? '' : rebaseWhenSync ? 'git.syncRebase' : 'git.sync' ,
64
- title : localize ( 'scm button sync title' , "{0} {1}{2}" , icon , behind , ahead ) ,
65
- tooltip : this . state . isSyncRunning ?
66
- localize ( 'syncing changes' , "Synchronizing Changes..." )
67
- : this . repository . syncTooltip ,
68
- arguments : [ this . repository . sourceControl ] ,
69
- } ,
70
- description : localize ( 'scm button sync description' , "{0} Sync Changes {1}{2}" , icon , behind , ahead )
71
- } ;
72
- }
53
+ // Sync Changes
54
+ actionButton = this . getSyncChangesActionButton ( ) ;
73
55
} else {
74
- actionButton = {
75
- command : {
76
- command : this . state . isSyncRunning ? '' : 'git.publish' ,
77
- title : localize ( 'scm button publish title' , "$(cloud-upload) Publish Branch" ) ,
78
- tooltip : this . state . isSyncRunning ?
79
- localize ( 'scm button publish branch running' , "Publishing Branch..." ) :
80
- localize ( 'scm button publish branch' , "Publish Branch" ) ,
81
- arguments : [ this . repository . sourceControl ] ,
82
- }
83
- } ;
56
+ // Publish Branch
57
+ actionButton = this . getPublishBranchActionButton ( ) ;
84
58
}
85
59
}
86
60
87
61
return actionButton ;
88
62
}
89
63
64
+ private getPublishBranchActionButton ( ) : SourceControlActionButton {
65
+ return {
66
+ command : {
67
+ command : 'git.publish' ,
68
+ title : localize ( 'scm button publish title' , "$(cloud-upload) Publish Branch" ) ,
69
+ tooltip : this . state . isActionRunning ?
70
+ localize ( 'scm button publish branch running' , "Publishing Branch..." ) :
71
+ localize ( 'scm button publish branch' , "Publish Branch" ) ,
72
+ arguments : [ this . repository . sourceControl ] ,
73
+ } ,
74
+ enabled : ! this . state . isActionRunning
75
+ } ;
76
+ }
77
+
78
+ private getSyncChangesActionButton ( ) : SourceControlActionButton | undefined {
79
+ if ( this . state . HEAD ?. ahead ) {
80
+ const config = workspace . getConfiguration ( 'git' , Uri . file ( this . repository . root ) ) ;
81
+ const rebaseWhenSync = config . get < string > ( 'rebaseWhenSync' ) ;
82
+
83
+ const ahead = `${ this . state . HEAD . ahead } $(arrow-up)` ;
84
+ const behind = this . state . HEAD . behind ? `${ this . state . HEAD . behind } $(arrow-down) ` : '' ;
85
+ const icon = this . state . isActionRunning ? '$(sync~spin)' : '$(sync)' ;
86
+
87
+ return {
88
+ command : {
89
+ command : rebaseWhenSync ? 'git.syncRebase' : 'git.sync' ,
90
+ title : localize ( 'scm button sync title' , "{0} {1}{2}" , icon , behind , ahead ) ,
91
+ tooltip : this . state . isActionRunning ?
92
+ localize ( 'syncing changes' , "Synchronizing Changes..." )
93
+ : this . repository . syncTooltip ,
94
+ arguments : [ this . repository . sourceControl ] ,
95
+ } ,
96
+ description : localize ( 'scm button sync description' , "{0} Sync Changes {1}{2}" , icon , behind , ahead ) ,
97
+ enabled : ! this . state . isActionRunning
98
+ } ;
99
+ }
100
+
101
+ return undefined ;
102
+ }
103
+
90
104
private onDidChangeOperations ( ) : void {
91
- const isSyncRunning = this . repository . operations . isRunning ( Operation . Sync ) ||
105
+ const isActionRunning = this . repository . operations . isRunning ( Operation . Sync ) ||
92
106
this . repository . operations . isRunning ( Operation . Push ) ||
93
107
this . repository . operations . isRunning ( Operation . Pull ) ;
94
108
95
- this . state = { ...this . state , isSyncRunning } ;
109
+ this . state = { ...this . state , isActionRunning : isActionRunning } ;
96
110
}
97
111
98
112
private onDidRunGitStatus ( ) : void {
0 commit comments