@@ -11,6 +11,8 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
11
11
import { ITerminal } from '@jupyterlab/terminal' ;
12
12
import { IGitExtension } from './tokens' ;
13
13
import { doGitClone } from './widgets/gitClone' ;
14
+ import { GitPullPushDialog , Operation } from './widgets/gitPushPull' ;
15
+ import { GitCredentialsForm } from './widgets/CredentialsBox' ;
14
16
15
17
/**
16
18
* The command IDs used by the git plugin.
@@ -24,6 +26,8 @@ export namespace CommandIDs {
24
26
export const gitToggleDoubleClickDiff = 'git:toggle-double-click-diff' ;
25
27
export const gitAddRemote = 'git:add-remote' ;
26
28
export const gitClone = 'git:clone' ;
29
+ export const gitPush = 'git:push' ;
30
+ export const gitPull = 'git:pull' ;
27
31
}
28
32
29
33
/**
@@ -82,8 +86,8 @@ export function addCommands(
82
86
83
87
/** Add git init command */
84
88
commands . addCommand ( CommandIDs . gitInit , {
85
- label : 'Init ' ,
86
- caption : ' Create an empty Git repository or reinitialize an existing one' ,
89
+ label : 'Initialize a Repository ' ,
90
+ caption : 'Create an empty Git repository or reinitialize an existing one' ,
87
91
execute : async ( ) => {
88
92
const currentPath = fileBrowser . model . path ;
89
93
const result = await showDialog ( {
@@ -164,7 +168,7 @@ export function addCommands(
164
168
165
169
/** Add git clone command */
166
170
commands . addCommand ( CommandIDs . gitClone , {
167
- label : 'Clone' ,
171
+ label : 'Clone a Repository ' ,
168
172
caption : 'Clone a repository from a URL' ,
169
173
isEnabled : ( ) => model . pathRepository === null ,
170
174
execute : async ( ) => {
@@ -173,4 +177,74 @@ export function addCommands(
173
177
} ,
174
178
isVisible : ( ) => model . pathRepository === null
175
179
} ) ;
180
+
181
+ /**
182
+ * Displays an error dialog when a Git operation fails.
183
+ *
184
+ * @private
185
+ * @param model - Git extension model
186
+ * @param operation - Git operation name
187
+ * @returns Promise for displaying a dialog
188
+ */
189
+ async function showGitOperationDialog (
190
+ model : IGitExtension ,
191
+ operation : Operation
192
+ ) : Promise < void > {
193
+ const title = `Git ${ operation } ` ;
194
+ let result = await showDialog ( {
195
+ title : title ,
196
+ body : new GitPullPushDialog ( model , operation ) ,
197
+ buttons : [ Dialog . okButton ( { label : 'DISMISS' } ) ]
198
+ } ) ;
199
+ let retry = false ;
200
+ while ( ! result . button . accept ) {
201
+ const credentials = await showDialog ( {
202
+ title : 'Git credentials required' ,
203
+ body : new GitCredentialsForm (
204
+ 'Enter credentials for remote repository' ,
205
+ retry ? 'Incorrect username or password.' : ''
206
+ ) ,
207
+ buttons : [ Dialog . cancelButton ( ) , Dialog . okButton ( { label : 'OK' } ) ]
208
+ } ) ;
209
+
210
+ if ( ! credentials . button . accept ) {
211
+ break ;
212
+ }
213
+
214
+ result = await showDialog ( {
215
+ title : title ,
216
+ body : new GitPullPushDialog ( model , operation , credentials . value ) ,
217
+ buttons : [ Dialog . okButton ( { label : 'DISMISS' } ) ]
218
+ } ) ;
219
+ retry = true ;
220
+ }
221
+ }
222
+
223
+ /** Add git push command */
224
+ commands . addCommand ( CommandIDs . gitPush , {
225
+ label : 'Push to Remote' ,
226
+ caption : 'Push code to remote repository' ,
227
+ isVisible : ( ) => model . pathRepository !== null ,
228
+ execute : async ( ) => {
229
+ await showGitOperationDialog ( model , Operation . Push ) . catch ( reason => {
230
+ console . error (
231
+ `Encountered an error when pushing changes. Error: ${ reason } `
232
+ ) ;
233
+ } ) ;
234
+ }
235
+ } ) ;
236
+
237
+ /** Add git pull command */
238
+ commands . addCommand ( CommandIDs . gitPull , {
239
+ label : 'Pull from Remote' ,
240
+ caption : 'Pull latest code from remote repository' ,
241
+ isVisible : ( ) => model . pathRepository !== null ,
242
+ execute : async ( ) => {
243
+ await showGitOperationDialog ( model , Operation . Pull ) . catch ( reason => {
244
+ console . error (
245
+ `Encountered an error when pulling changes. Error: ${ reason } `
246
+ ) ;
247
+ } ) ;
248
+ }
249
+ } ) ;
176
250
}
0 commit comments