Skip to content

Commit

Permalink
Add discard fallback to pull operation
Browse files Browse the repository at this point in the history
* Remove unused command ids
  • Loading branch information
navn-r committed Sep 11, 2021
1 parent adf7276 commit 1b08af6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
23 changes: 18 additions & 5 deletions src/commandsAndMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,24 @@ export function addCommands(
'Encountered an error when pulling changes. Error: ',
error
);
logger.log({
message: trans.__('Failed to pull'),
level: Level.ERROR,
error
});

// Discard changes then retry pull
if (
(error as string)
.toLowerCase()
.includes(
'your local changes to the following files would be overwritten by merge'
)
) {
await discardAllChanges(gitModel, trans, true);
await commands.execute(CommandIDs.gitPull, {} as any);
} else {
logger.log({
message: trans.__('Failed to pull'),
level: Level.ERROR,
error
});
}
}
}
});
Expand Down
2 changes: 0 additions & 2 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,7 @@ export enum CommandIDs {
gitClone = 'git:clone',
gitOpenGitignore = 'git:open-gitignore',
gitPush = 'git:push',
gitForcePush = 'git:force-push',
gitPull = 'git:pull',
gitDiscardPull = 'git:discard-pull',
gitSubmitCommand = 'git:submit-commit',
gitShowDiff = 'git:show-diff'
}
15 changes: 11 additions & 4 deletions src/widgets/discardAllChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ 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
trans: TranslationBundle,
isFallback?: boolean
): Promise<void> {
const result = await showDialog({
title: trans.__('Discard all changes'),
body: trans.__(
'Are you sure you want to permanently discard changes to all files? This action cannot be undone.'
),
body: isFallback
? trans.__(
'Do you want to permanently discard changes to all files and pull? 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') })
Expand Down

0 comments on commit 1b08af6

Please sign in to comment.