From ff8d4feeb4361da1942f02ac040d92e42ecd8dc3 Mon Sep 17 00:00:00 2001 From: "sneakyfish5.sneaky@gmail.com" Date: Sun, 9 Aug 2020 16:48:22 -0500 Subject: [PATCH] Git: Add cherryPick command --- extensions/git/package.json | 9 +++++++++ extensions/git/package.nls.json | 1 + extensions/git/src/commands.ts | 15 +++++++++++++++ extensions/git/src/git.ts | 5 +++++ extensions/git/src/repository.ts | 5 +++++ 5 files changed, 35 insertions(+) diff --git a/extensions/git/package.json b/extensions/git/package.json index 748868778dd..767a70a5a68 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -326,6 +326,11 @@ "title": "%command.pushFollowTagsForce%", "category": "Git" }, + { + "command": "git.cherryPick", + "title": "%command.cherryPick%", + "category": "Git" + }, { "command": "git.addRemote", "title": "%command.addRemote%", @@ -673,6 +678,10 @@ "command": "git.pushWithTagsForce", "when": "config.git.enabled && !git.missing && config.git.allowForcePush && gitOpenRepositoryCount != 0" }, + { + "command": "git.cherryPick", + "when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0" + }, { "command": "git.addRemote", "when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0" diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 0e8ea1c649e..0780ac89b8d 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -56,6 +56,7 @@ "command.pushToForce": "Push to... (Force)", "command.pushFollowTags": "Push (Follow Tags)", "command.pushFollowTagsForce": "Push (Follow Tags, Force)", + "command.cherryPick": "Cherry Pick...", "command.addRemote": "Add Remote...", "command.removeRemote": "Remove Remote", "command.sync": "Sync", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index f618a8669c2..a862568e22d 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2027,6 +2027,21 @@ export class CommandCenter { await this._push(repository, { pushType: PushType.PushFollowTags, forcePush: true }); } + @command('git.cherryPick', { repository: true }) + async cherryPick(repository: Repository): Promise { + const inputCommitHash = await window.showInputBox({ + placeHolder: localize('commit hash', "Commit Hash"), + prompt: localize('provide commit hash', "Please provide the commit hash"), + ignoreFocusOut: true + }); + + if (!inputCommitHash) { + return; + } + + await repository.cherryPick(inputCommitHash); + } + @command('git.pushTo', { repository: true }) async pushTo(repository: Repository): Promise { await this._push(repository, { pushType: PushType.PushTo }); diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index d974c7bf1ca..9019a8e4772 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1635,6 +1635,11 @@ export class Repository { } } + async cherryPick(commitHash: string): Promise { + const args = ['cherry-pick', commitHash]; + await this.run(args); + } + async blame(path: string): Promise { try { const args = ['blame', sanitizePath(path)]; diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index edebe7e54c1..124b34caf7a 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -294,6 +294,7 @@ export const enum Operation { Fetch = 'Fetch', Pull = 'Pull', Push = 'Push', + CherryPick = 'CherryPick', Sync = 'Sync', Show = 'Show', Stage = 'Stage', @@ -1195,6 +1196,10 @@ export class Repository implements Disposable { await this.run(Operation.Push, () => this._push(remote, undefined, false, true, forcePushMode)); } + async cherryPick(commitHash: string): Promise { + await this.run(Operation.CherryPick, () => this.repository.cherryPick(commitHash)); + } + async blame(path: string): Promise { return await this.run(Operation.Blame, () => this.repository.blame(path)); } -- GitLab