@@ -6,30 +6,30 @@ import {
6
6
} from '@jupyterlab/apputils' ;
7
7
import { TranslationBundle } from '@jupyterlab/translation' ;
8
8
import { CommandRegistry } from '@lumino/commands' ;
9
+ import ClearIcon from '@mui/icons-material/Clear' ;
9
10
import List from '@mui/material/List' ;
10
11
import ListItem from '@mui/material/ListItem' ;
11
- import ClearIcon from '@mui/icons-material/Clear' ;
12
12
import * as React from 'react' ;
13
13
import { FixedSizeList , ListChildComponentProps } from 'react-window' ;
14
14
import { classes } from 'typestyle' ;
15
+ import { showError } from '../notifications' ;
15
16
import { hiddenButtonStyle } from '../style/ActionButtonStyle' ;
16
17
import {
17
18
activeListItemClass ,
18
- nameClass ,
19
19
filterClass ,
20
20
filterClearClass ,
21
21
filterInputClass ,
22
22
filterWrapperClass ,
23
23
listItemClass ,
24
24
listItemIconClass ,
25
+ nameClass ,
25
26
newBranchButtonClass ,
26
27
wrapperClass
27
28
} from '../style/BranchMenu' ;
28
29
import { branchIcon , mergeIcon , trashIcon } from '../style/icons' ;
29
30
import { CommandIDs , Git , IGitExtension } from '../tokens' ;
30
31
import { ActionButton } from './ActionButton' ;
31
32
import { NewBranchDialog } from './NewBranchDialog' ;
32
- import { showError } from '../notifications' ;
33
33
34
34
const ITEM_HEIGHT = 24.8 ; // HTML element height for a single branch
35
35
const MIN_HEIGHT = 150 ; // Minimal HTML element height for the branches list
@@ -274,7 +274,10 @@ export class BranchMenu extends React.Component<
274
274
listItemClass ,
275
275
isActive ? activeListItemClass : null
276
276
) }
277
- onClick = { this . _onBranchClickFactory ( branch . name ) }
277
+ onClick = { this . _onBranchClickFactory (
278
+ branch . name ,
279
+ branch . is_remote_branch
280
+ ) }
278
281
role = "listitem"
279
282
style = { style }
280
283
>
@@ -425,7 +428,7 @@ export class BranchMenu extends React.Component<
425
428
* @param branch - branch name
426
429
* @returns callback
427
430
*/
428
- private _onBranchClickFactory ( branch : string ) {
431
+ private _onBranchClickFactory ( branch : string , isRemote : boolean ) {
429
432
/**
430
433
* Callback invoked upon clicking a branch name.
431
434
*
@@ -441,6 +444,9 @@ export class BranchMenu extends React.Component<
441
444
) ;
442
445
return ;
443
446
}
447
+
448
+ let message = 'Switched branch.' ;
449
+ let type : Notification . TypeOptions = 'success' ;
444
450
const opts = {
445
451
branchname : branch
446
452
} ;
@@ -452,15 +458,42 @@ export class BranchMenu extends React.Component<
452
458
) ;
453
459
454
460
try {
455
- await this . props . model . checkout ( opts ) ;
461
+ let shouldCheckout = true ;
462
+ const localBranchname = branch . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
463
+ const localBranchExists = this . props . model . branches . find (
464
+ branch => branch . name === localBranchname
465
+ ) ;
466
+
467
+ if ( localBranchExists && isRemote ) {
468
+ const result = await showDialog ( {
469
+ title : this . props . trans . __ ( 'Confirm Checkout' ) ,
470
+ body : this . props . trans . __ (
471
+ 'Checking out this branch will reset your local copy to the remote. Any changes not pushed to the remote will be lost. Are you sure you want to continue?'
472
+ ) ,
473
+ buttons : [
474
+ Dialog . cancelButton ( { label : this . props . trans . __ ( 'Cancel' ) } ) ,
475
+ Dialog . warnButton ( { label : this . props . trans . __ ( 'Continue' ) } )
476
+ ]
477
+ } ) ;
478
+
479
+ if ( ! result . button . accept ) {
480
+ shouldCheckout = false ;
481
+ message = 'Checkout cancelled.' ;
482
+ type = 'warning' ;
483
+ }
484
+ }
485
+
486
+ if ( shouldCheckout ) {
487
+ await this . props . model . checkout ( opts ) ;
488
+ }
456
489
} catch ( err ) {
457
490
return onBranchError ( err , id , this . props . trans ) ;
458
491
}
459
492
460
493
Notification . update ( {
461
494
id,
462
- message : this . props . trans . __ ( 'Switched branch.' ) ,
463
- type : 'success' ,
495
+ message : this . props . trans . __ ( message ) ,
496
+ type,
464
497
autoClose : 5000
465
498
} ) ;
466
499
} ;
0 commit comments