Kaynağa Gözat

Adds Feature for Copy Current Branch Name

Related Issue: #1306
main
Ken Hom 4 yıl önce
işlemeyi yapan: Eric Amodio
ebeveyn
işleme
f7744edffb
5 değiştirilmiş dosya ile 43 ekleme ve 0 silme
  1. +2
    -0
      README.md
  2. +6
    -0
      package.json
  3. +1
    -0
      src/commands.ts
  4. +1
    -0
      src/commands/common.ts
  5. +33
    -0
      src/commands/copyCurrentBranch.ts

+ 2
- 0
README.md Dosyayı Görüntüle

@ -596,6 +596,8 @@ Additionally, these integrations provide commands to copy the url of or open, fi
- Adds a _Copy SHA_ command (`gitlens.copyShaToClipboard`) to copy the commit SHA of the current line to the clipboard or from the most recent commit to the current branch, if there is no current editor
- Adds a _Copy Message_ command (`gitlens.copyMessageToClipboard`) to copy the commit message of the current line to the clipboard or from the most recent commit to the current branch, if there is no current editor
- Adds a _Copy Current Branch_ command (`gitlens.copyCurrentBranch`) to copy the name of the current branch to the clipboard
- Adds a _Switch to Another Branch_ (`gitlens.views.switchToAnotherBranch`) command — to quickly switch the current branch
- Adds a _Compare References..._ command (`gitlens.compareWith`) to compare two selected references

+ 6
- 0
package.json Dosyayı Görüntüle

@ -185,6 +185,7 @@
"onCommand:gitlens.fetchRepositories",
"onCommand:gitlens.pullRepositories",
"onCommand:gitlens.pushRepositories",
"oncommand:gitlens.copyCurrentBranch",
"onStartupFinished"
],
"contributes": {
@ -4693,6 +4694,11 @@
"command": "gitlens.views.tags.setShowAvatarsOff",
"title": "Hide Avatars",
"category": "GitLens"
},
{
"command": "gitlens.copyCurrentBranch",
"title": "Copy Current Branch",
"category": "GitLens"
}
],
"menus": {

+ 1
- 0
src/commands.ts Dosyayı Görüntüle

@ -6,6 +6,7 @@ export * from './commands/closeUnchangedFiles';
export * from './commands/closeView';
export * from './commands/common';
export * from './commands/compareWith';
export * from './commands/copyCurrentBranch';
export * from './commands/copyMessageToClipboard';
export * from './commands/copyShaToClipboard';
export * from './commands/openDirectoryCompare';

+ 1
- 0
src/commands/common.ts Dosyayı Görüntüle

@ -41,6 +41,7 @@ export enum Commands {
CompareWorkingWith = 'gitlens.compareWorkingWith',
ComputingFileAnnotations = 'gitlens.computingFileAnnotations',
ConnectRemoteProvider = 'gitlens.connectRemoteProvider',
CopyCurrentBranch = 'gitlens.copyCurrentBranch',
CopyMessageToClipboard = 'gitlens.copyMessageToClipboard',
CopyRemoteBranchesUrl = 'gitlens.copyRemoteBranchesUrl',
CopyRemoteBranchUrl = 'gitlens.copyRemoteBranchUrl',

+ 33
- 0
src/commands/copyCurrentBranch.ts Dosyayı Görüntüle

@ -0,0 +1,33 @@
'use strict';
import { env , TextEditor , Uri , window } from 'vscode';
import { GitService } from '../git/gitService';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
@command()
export class CopyCurrentBranch extends ActiveEditorCommand {
constructor() {
super(Commands.CopyCurrentBranch);
}
async execute(editor?: TextEditor, uri?: Uri) {
uri = getCommandUri(uri, editor);
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Copy Current Branch');
if (!repoPath) return;
const service = new GitService();
try {
const gitBranch = await service.getBranch(repoPath);
if (gitBranch?.name) await env.clipboard.writeText(gitBranch?.name);
} catch (ex) {
Logger.error(ex, 'CopyCurrentBranch');
void window.showErrorMessage('Unable to copy current branch. See output channel for more details');
}
}
}

Yükleniyor…
İptal
Kaydet