-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Discard All and Pull' button (#1020)
* Add discard and pull menu item * Apply suggestions from code review Co-authored-by: Frédéric Collonval <[email protected]> * Add missing entry menu in settings description * Add discard fallback to pull operation * Remove unused command ids * Apply suggestions from code review Co-authored-by: Frédéric Collonval <[email protected]> * Apply suggestions from code review * Rename `discard` to `force` to align with `push` * Hide toast if action cancelled by user Co-authored-by: Frédéric Collonval <[email protected]> Co-authored-by: Frédéric Collonval <[email protected]>
- Loading branch information
1 parent
b268a40
commit 7707fc2
Showing
5 changed files
with
108 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { showDialog, Dialog, showErrorMessage } from '@jupyterlab/apputils'; | ||
import { TranslationBundle } from '@jupyterlab/translation'; | ||
import { IGitExtension } from '../tokens'; | ||
|
||
/** | ||
* Discard changes in all unstaged and staged files | ||
* | ||
* @param isFallback If dialog is called when the classical pull operation fails | ||
*/ | ||
export async function discardAllChanges( | ||
model: IGitExtension, | ||
trans: TranslationBundle, | ||
isFallback?: boolean | ||
): Promise<void> { | ||
const result = await showDialog({ | ||
title: trans.__('Discard all changes'), | ||
body: isFallback | ||
? trans.__( | ||
'Your current changes forbid pulling the latest changes. Do you want to permanently discard those changes? This action cannot be undone.' | ||
) | ||
: trans.__( | ||
'Are you sure you want to permanently discard changes to all files? This action cannot be undone.' | ||
), | ||
buttons: [ | ||
Dialog.cancelButton({ label: trans.__('Cancel') }), | ||
Dialog.warnButton({ label: trans.__('Discard') }) | ||
] | ||
}); | ||
|
||
if (result.button.accept) { | ||
try { | ||
return model.resetToCommit('HEAD'); | ||
} catch (reason) { | ||
showErrorMessage(trans.__('Discard all changes failed.'), reason); | ||
return Promise.reject(reason); | ||
} | ||
} | ||
|
||
return Promise.reject({ | ||
cancelled: true, | ||
message: 'The user refused to discard all changes' | ||
}); | ||
} |