diff --git a/package.json b/package.json index 15aef6b..5fe4283 100644 --- a/package.json +++ b/package.json @@ -6611,6 +6611,16 @@ "group": "7_gitlens_cutcopypaste@2" }, { + "command": "gitlens.copyShaToClipboard", + "when": "viewItem =~ /gitlens:branch\\b/", + "group": "7_gitlens_cutcopypaste@2" + }, + { + "command": "gitlens.copyShaToClipboard", + "when": "viewItem =~ /gitlens:tag\\b/", + "group": "7_gitlens_cutcopypaste@2" + }, + { "command": "gitlens.copyMessageToClipboard", "when": "viewItem =~ /gitlens:(commit|stash|file\\b(?=.*?\\b\\+committed\\b))\\b/", "group": "7_gitlens_cutcopypaste@3" diff --git a/src/commands/common.ts b/src/commands/common.ts index 6a0ec42..d3c860e 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -17,7 +17,7 @@ import { } from 'vscode'; import { BuiltInCommands, DocumentSchemes, ImageMimetypes } from '../constants'; import { Container } from '../container'; -import { GitBranch, GitCommit, GitContributor, GitFile, GitRemote, Repository } from '../git/git'; +import { GitBranch, GitCommit, GitContributor, GitFile, GitRemote, GitTag, Repository } from '../git/git'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { CommandQuickPickItem, RepositoryPicker } from '../quickpicks'; @@ -333,6 +333,14 @@ export function isCommandViewContextWithRepoPath( return typeof (context.node as ViewNode & { repoPath?: string }).repoPath === 'string'; } +export function isCommandViewContextWithTag( + context: CommandContext, +): context is CommandViewItemContext & { node: ViewNode & { tag: GitTag } } { + if (context.type !== 'viewItem') return false; + + return GitTag.is((context.node as ViewNode & { tag: GitTag }).tag); +} + export type CommandContext = | CommandScmGroupsContext | CommandScmStatesContext diff --git a/src/commands/copyShaToClipboard.ts b/src/commands/copyShaToClipboard.ts index 41442f4..f4549a2 100644 --- a/src/commands/copyShaToClipboard.ts +++ b/src/commands/copyShaToClipboard.ts @@ -11,7 +11,9 @@ import { CommandContext, Commands, getCommandUri, + isCommandViewContextWithBranch, isCommandViewContextWithCommit, + isCommandViewContextWithTag, } from './common'; export interface CopyShaToClipboardCommandArgs { @@ -29,6 +31,14 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand { args = { ...args }; args.sha = context.node.commit.sha; return this.execute(context.editor, context.node.commit.uri, args); + } else if (isCommandViewContextWithBranch(context)) { + args = { ...args }; + args.sha = context.node.branch.sha; + return this.execute(context.editor, context.node.uri, args); + } else if (isCommandViewContextWithTag(context)) { + args = { ...args }; + args.sha = context.node.tag.sha; + return this.execute(context.editor, context.node.uri, args); } return this.execute(context.editor, context.uri, args);