Browse Source

Adds Copy SHA command to branches & tags

main
Eric Amodio 4 years ago
parent
commit
e50730b4d5
3 changed files with 29 additions and 1 deletions
  1. +10
    -0
      package.json
  2. +9
    -1
      src/commands/common.ts
  3. +10
    -0
      src/commands/copyShaToClipboard.ts

+ 10
- 0
package.json View File

@ -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"

+ 9
- 1
src/commands/common.ts View File

@ -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

+ 10
- 0
src/commands/copyShaToClipboard.ts View File

@ -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);

Loading…
Cancel
Save