diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 850dc6202..94bed92d1 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -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 + }); + } } } }); diff --git a/src/tokens.ts b/src/tokens.ts index 751f9e398..ebbd001af 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -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' } diff --git a/src/widgets/discardAllChanges.ts b/src/widgets/discardAllChanges.ts index 67cdbf156..2d0309f2c 100644 --- a/src/widgets/discardAllChanges.ts +++ b/src/widgets/discardAllChanges.ts @@ -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 { 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') })