From 44d05b9dfa6c6231b2ab3eaa651e2b8ed1fa8274 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:07:16 +0200 Subject: [PATCH] Git - cheery-pick now handles the case where the changes are already present on the current branch (#229731) --- extensions/git/src/api/git.d.ts | 3 ++- extensions/git/src/commands.ts | 6 ++++++ extensions/git/src/git.ts | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 3c5aad1c4a0..2a54c52f20c 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -409,5 +409,6 @@ export const enum GitErrorCodes { EmptyCommitMessage = 'EmptyCommitMessage', BranchFastForwardRejected = 'BranchFastForwardRejected', BranchNotYetBorn = 'BranchNotYetBorn', - TagConflict = 'TagConflict' + TagConflict = 'TagConflict', + CherryPickEmpty = 'CherryPickEmpty' } diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 38c1db541bb..3b1a848adcf 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -4403,6 +4403,12 @@ export class CommandCenter { type = 'information'; options.modal = false; break; + case GitErrorCodes.CherryPickEmpty: + message = l10n.t('The changes are already present in the current branch.'); + choices.clear(); + type = 'information'; + options.modal = false; + break; default: { const hint = (err.stderr || err.message || String(err)) .replace(/^error: /mi, '') diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index dea09733420..3de9f74b1e8 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -2102,8 +2102,18 @@ export class Repository { } async cherryPick(commitHash: string): Promise { - const args = ['cherry-pick', commitHash]; - await this.exec(args); + try { + await this.exec(['cherry-pick', commitHash]); + } catch (err) { + if (/The previous cherry-pick is now empty, possibly due to conflict resolution./.test(err.stderr ?? '')) { + // Abort the cherry-pick operation + await this.exec(['cherry-pick', '--abort']); + + err.gitErrorCode = GitErrorCodes.CherryPickEmpty; + } + + throw err; + } } async blame(path: string): Promise {