From 8a9caf323a75de847945d058a7b6c4c6ba98feb5 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:17:44 +0200 Subject: [PATCH] SCM Graph - Add "Create Tag" action to history item context menu (#228428) --- extensions/git/package.json | 9 +++++++-- extensions/git/package.nls.json | 2 +- extensions/git/src/api/api1.ts | 4 ++-- extensions/git/src/commands.ts | 4 ++-- extensions/git/src/git.ts | 12 ++++++++---- extensions/git/src/repository.ts | 4 ++-- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 04efdb8c06434..18bcce4ada1ef 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1943,15 +1943,20 @@ } ], "scm/historyItem/context": [ + { + "command": "git.createTag", + "when": "scmProvider == git", + "group": "1_create@1" + }, { "command": "git.copyCommitId", "when": "scmProvider == git && !listMultiSelection", - "group": "1_copy@1" + "group": "9_copy@1" }, { "command": "git.copyCommitMessage", "when": "scmProvider == git && !listMultiSelection", - "group": "1_copy@2" + "group": "9_copy@2" } ], "editor/title": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index c2f7c3d6cfbbd..be815cb8f91fb 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -70,7 +70,7 @@ "command.merge": "Merge...", "command.mergeAbort": "Abort Merge", "command.rebase": "Rebase Branch...", - "command.createTag": "Create Tag", + "command.createTag": "Create Tag...", "command.deleteTag": "Delete Tag...", "command.deleteRemoteTag": "Delete Remote Tag...", "command.fetch": "Fetch", diff --git a/extensions/git/src/api/api1.ts b/extensions/git/src/api/api1.ts index 332c328b2d119..63139af2447d6 100644 --- a/extensions/git/src/api/api1.ts +++ b/extensions/git/src/api/api1.ts @@ -201,8 +201,8 @@ export class ApiRepository implements Repository { return this.repository.getMergeBase(ref1, ref2); } - tag(name: string, upstream: string): Promise { - return this.repository.tag(name, upstream); + tag(name: string, message: string, ref?: string | undefined): Promise { + return this.repository.tag({ name, message, ref }); } deleteTag(name: string): Promise { diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 2b4e7d2dfaa49..1f68dcf5c9cde 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2907,7 +2907,7 @@ export class CommandCenter { } @command('git.createTag', { repository: true }) - async createTag(repository: Repository): Promise { + async createTag(repository: Repository, historyItem?: SourceControlHistoryItem): Promise { const inputTagName = await window.showInputBox({ placeHolder: l10n.t('Tag name'), prompt: l10n.t('Please provide a tag name'), @@ -2925,7 +2925,7 @@ export class CommandCenter { }); const name = inputTagName.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-'); - await repository.tag(name, inputMessage); + await repository.tag({ name, message: inputMessage, ref: historyItem?.id }); } @command('git.deleteTag', { repository: true }) diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 6a74dcaec2e87..b3a1a71aa5c5a 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1807,13 +1807,17 @@ export class Repository { await this.exec(['merge', '--abort']); } - async tag(name: string, message?: string): Promise { + async tag(options: { name: string; message?: string; ref?: string }): Promise { let args = ['tag']; - if (message) { - args = [...args, '-a', name, '-m', message]; + if (options.message) { + args = [...args, '-a', options.name, '-m', options.message]; } else { - args = [...args, name]; + args = [...args, options.name]; + } + + if (options.ref) { + args.push(options.ref); } await this.exec(args); diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 704c549f5ac6f..ef39cddb4a4bb 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -1563,8 +1563,8 @@ export class Repository implements Disposable { await this.run(Operation.Rebase, () => this.repository.rebase(branch)); } - async tag(name: string, message?: string): Promise { - await this.run(Operation.Tag, () => this.repository.tag(name, message)); + async tag(options: { name: string; message?: string; ref?: string }): Promise { + await this.run(Operation.Tag, () => this.repository.tag(options)); } async deleteTag(name: string): Promise {