From 3345f67f7cc21d15519013dbf0fecd019a993b29 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 8 Jan 2021 03:30:55 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20&=20minor=20fixes=20Adds=20@kh0m?= =?UTF-8?q?=20contribution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + README.md | 1 + package.json | 20 ++++++++++++++------ src/commands/copyCurrentBranch.ts | 23 +++++++++++------------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6b875e..e765306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Adds the _Add Remote_ command to the branch status in the _Branches_, _Commits_, and _Repositories_ views when there are no Git remotes configured - Adds a new _Browse Repository from Before Here_ (`gitlens.browseRepoBeforeRevision`) and _Browse Repository from Before Here in New Window_ (`gitlens.browseRepoBeforeRevisionInNewWindow`) commands - Adds _Repository from Before Here_ and _Repository from Before Here in New Window_ to the _Browse_ submenu of commits in the views +- Adds a new _Copy Current Branch Name_ (`gitlens.copyCurrentBranch`) command to copy the current branch name to the clipboard — closes [#1306](https://github.com/eamodio/vscode-gitlens/issues/1306) — thanks to [PR #1307](https://github.com/eamodio/vscode-gitlens/pull/1307) by Ken Hom ([@kh0m](https://github.com/kh0m)) ### Changed diff --git a/README.md b/README.md index 3a79f3e..47e412c 100644 --- a/README.md +++ b/README.md @@ -1013,6 +1013,7 @@ A big thanks to the people that have contributed to this project: - Geoffrey ([@g3offrey](https://github.com/g3offrey)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=g3offrey) - grozan ([@grozan](https://github.com/grozan)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=grozan) - Guillem ([@guillemglez](https://github.com/guillemglez)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=guillemglez) +- Ken Hom ([@kh0m](https://github.com/kh0m)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=kh0m) - Yukai Huang ([@Yukaii](https://github.com/Yukaii)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Yukaii) - Justin Hutchings ([@jhutchings1](https://github.com/jhutchings1)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=jhutchings1) - Roy Ivy III ([@rivy](https://github.com/rivy)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=rivy) diff --git a/package.json b/package.json index b7d90aa..295d0f3 100644 --- a/package.json +++ b/package.json @@ -141,6 +141,7 @@ "onCommand:gitlens.addAuthors", "onCommand:gitlens.connectRemoteProvider", "onCommand:gitlens.disconnectRemoteProvider", + "oncommand:gitlens.copyCurrentBranch", "onCommand:gitlens.copyMessageToClipboard", "onCommand:gitlens.copyShaToClipboard", "onCommand:gitlens.closeUnchangedFiles", @@ -185,7 +186,6 @@ "onCommand:gitlens.fetchRepositories", "onCommand:gitlens.pullRepositories", "onCommand:gitlens.pushRepositories", - "oncommand:gitlens.copyCurrentBranch", "onStartupFinished" ], "contributes": { @@ -3186,6 +3186,15 @@ "category": "GitLens" }, { + "command": "gitlens.copyCurrentBranch", + "title": "Copy Current Branch Name", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-copy.svg", + "light": "images/light/icon-copy.svg" + } + }, + { "command": "gitlens.copyMessageToClipboard", "title": "Copy Message", "category": "GitLens", @@ -4694,11 +4703,6 @@ "command": "gitlens.views.tags.setShowAvatarsOff", "title": "Hide Avatars", "category": "GitLens" - }, - { - "command": "gitlens.copyCurrentBranch", - "title": "Copy Current Branch", - "category": "GitLens" } ], "menus": { @@ -5036,6 +5040,10 @@ "when": "config.gitlens.integrations.enabled && gitlens:hasRichRemotes" }, { + "command": "gitlens.copyCurrentBranch", + "when": "gitlens:enabled" + }, + { "command": "gitlens.copyMessageToClipboard", "when": "gitlens:activeFileStatus =~ /blameable/" }, diff --git a/src/commands/copyCurrentBranch.ts b/src/commands/copyCurrentBranch.ts index 8fee349..8963452 100644 --- a/src/commands/copyCurrentBranch.ts +++ b/src/commands/copyCurrentBranch.ts @@ -1,13 +1,12 @@ 'use strict'; - -import { env , TextEditor , Uri , window } from 'vscode'; -import { GitService } from '../git/gitService'; +import { env, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common'; +import { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; -import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common'; @command() -export class CopyCurrentBranch extends ActiveEditorCommand { +export class CopyCurrentBranchCommand extends ActiveEditorCommand { constructor() { super(Commands.CopyCurrentBranch); } @@ -17,17 +16,17 @@ export class CopyCurrentBranch extends ActiveEditorCommand { const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined; - const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Copy Current Branch'); + const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Copy Current Branch Name'); if (!repoPath) return; - const service = new GitService(); - try { - const gitBranch = await service.getBranch(repoPath); - if (gitBranch?.name) await env.clipboard.writeText(gitBranch?.name); + const branch = await Container.git.getBranch(repoPath); + if (branch?.name) { + await env.clipboard.writeText(branch.name); + } } catch (ex) { - Logger.error(ex, 'CopyCurrentBranch'); - void window.showErrorMessage('Unable to copy current branch. See output channel for more details'); + Logger.error(ex, 'CopyCurrentBranchCommand'); + void window.showErrorMessage('Unable to copy current branch name. See output channel for more details'); } } }