diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dfd572..90a9e46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Adds an _Autolinks_ section in the _GitLens Settings Editor_ to visually add and update autolink entries — closes [#1315](https://github.com/gitkraken/vscode-gitlens/issues/1315) - Adds improved support to _Autolinked Issues and Pull Requests_ within comparisons to list autolinked issues in commit messages - You can now see all autolinks found in the commits in the comparison regardless of whether its a provider-based autolink or a custom (user-provided) autolink +- Adds _Open Current Branch on Remote_ to the Command Palette — closes [#1718](https://github.com/gitkraken/vscode-gitlens/issues/1718) ## Changed diff --git a/README.md b/README.md index 5e98462..4b72fd8 100644 --- a/README.md +++ b/README.md @@ -628,6 +628,7 @@ Additionally, these integrations provide commands to copy the url of or open fil - _Open Commit on Remote_ command (`gitlens.openCommitOnRemote`) — opens a commit on the remote provider - _Copy Remote Commit Url_ command (`gitlens.copyRemoteCommitUrl`) — copies the url of a commit on the remote provider - _Open Branch on Remote_ command (`gitlens.openBranchOnRemote`) — opens the branch on the remote provider +- _Open Current Branch on Remote_ command (`gitlens.openCurrentBranchOnRemote`) — opens the current branch on the remote provider - _Copy Remote Branch Url_ command (`gitlens.copyRemoteBranchUrl`) — copies the url of a branch on the remote provider - _Open Branches on Remote_ command (`gitlens.openBranchesOnRemote`) — opens the branches on the remote provider - _Copy Remote Branches Url_ command (`gitlens.copyRemoteBranchesUrl`) — copies the url of the branches on the remote provider diff --git a/package.json b/package.json index bf95a32..cdd9ad4 100644 --- a/package.json +++ b/package.json @@ -166,6 +166,7 @@ "onCommand:gitlens.openBranchesOnRemote", "onCommand:gitlens.copyRemoteBranchesUrl", "onCommand:gitlens.openBranchOnRemote", + "onCommand:gitlens.openCurrentBranchOnRemote", "onCommand:gitlens.copyRemoteBranchUrl", "onCommand:gitlens.openCommitOnRemote", "onCommand:gitlens.copyRemoteCommitUrl", @@ -4405,6 +4406,12 @@ "icon": "$(globe)" }, { + "command": "gitlens.openCurrentBranchOnRemote", + "title": "Open Current Branch on Remote", + "category": "GitLens", + "icon": "$(globe)" + }, + { "command": "gitlens.copyRemoteBranchUrl", "title": "Copy Remote Branch Url", "category": "GitLens", @@ -6510,6 +6517,10 @@ "when": "gitlens:hasRemotes" }, { + "command": "gitlens.openCurrentBranchOnRemote", + "when": "gitlens:hasRemotes" + }, + { "command": "gitlens.copyRemoteBranchUrl", "when": "false" }, diff --git a/src/commands.ts b/src/commands.ts index 9c0049b..0c686b8 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -22,6 +22,7 @@ export * from './commands/logging'; export * from './commands/openAssociatedPullRequestOnRemote'; export * from './commands/openBranchesOnRemote'; export * from './commands/openBranchOnRemote'; +export * from './commands/openCurrentBranchOnRemote'; export * from './commands/openChangedFiles'; export * from './commands/openCommitOnRemote'; export * from './commands/openComparisonOnRemote'; diff --git a/src/commands/openCurrentBranchOnRemote.ts b/src/commands/openCurrentBranchOnRemote.ts new file mode 100644 index 0000000..8b970ed --- /dev/null +++ b/src/commands/openCurrentBranchOnRemote.ts @@ -0,0 +1,44 @@ +import { TextEditor, Uri, window } from 'vscode'; +import { Commands } from '../constants'; +import type { Container } from '../container'; +import { GitUri } from '../git/gitUri'; +import { RemoteResourceType } from '../git/remotes/provider'; +import { Logger } from '../logger'; +import { RepositoryPicker } from '../quickpicks/repositoryPicker'; +import { command, executeCommand } from '../system/command'; +import { ActiveEditorCommand, getCommandUri } from './base'; +import { OpenOnRemoteCommandArgs } from './openOnRemote'; + +@command() +export class OpenCurrentBranchOnRemoteCommand extends ActiveEditorCommand { + constructor(private readonly container: Container) { + super(Commands.OpenCurrentBranchOnRemote); + } + + async execute(editor?: TextEditor, uri?: Uri) { + uri = getCommandUri(uri, editor); + + const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined; + + const repository = await RepositoryPicker.getBestRepositoryOrShow(gitUri, editor, 'Open Current Branch Name'); + if (repository == null) return; + + try { + const branch = await repository.getBranch(); + if (branch?.name) { + void (await executeCommand(Commands.OpenOnRemote, { + resource: { + type: RemoteResourceType.Branch, + branch: branch.name || 'HEAD', + }, + repoPath: repository.path, + })); + } + } catch (ex) { + Logger.error(ex, 'OpenCurrentBranchOnRemoteCommand'); + void window.showErrorMessage( + 'Unable to open branch on remote provider. See output channel for more details', + ); + } + } +} diff --git a/src/constants.ts b/src/constants.ts index cce41a8..a9b5a0e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -105,6 +105,7 @@ export const enum Commands { OpenBlamePriorToChange = 'gitlens.openBlamePriorToChange', OpenBranchesOnRemote = 'gitlens.openBranchesOnRemote', OpenBranchOnRemote = 'gitlens.openBranchOnRemote', + OpenCurrentBranchOnRemote = 'gitlens.openCurrentBranchOnRemote', OpenChangedFiles = 'gitlens.openChangedFiles', OpenCommitOnRemote = 'gitlens.openCommitOnRemote', OpenComparisonOnRemote = 'gitlens.openComparisonOnRemote',