From 75b93f87c060ce67a5949dabeb231e9a669048fa Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 26 Aug 2020 02:01:08 -0400 Subject: [PATCH] Adds Switch to Another Branch command --- package.json | 38 +++++++++++++++++++++++++++++++++----- src/views/viewCommands.ts | 7 ++++++- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e2657b7..4294ad5 100644 --- a/package.json +++ b/package.json @@ -2991,6 +2991,15 @@ } }, { + "command": "gitlens.views.switchToAnotherBranch", + "title": "Switch to Another Branch", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-checkout.svg", + "light": "images/light/icon-checkout.svg" + } + }, + { "command": "gitlens.views.switchToBranch", "title": "Switch to Branch", "category": "GitLens", @@ -4372,6 +4381,10 @@ "when": "false" }, { + "command": "gitlens.views.switchToAnotherBranch", + "when": "false" + }, + { "command": "gitlens.views.switchToBranch", "when": "false" }, @@ -5393,19 +5406,24 @@ "group": "navigation@12" }, { + "command": "gitlens.views.switchToAnotherBranch", + "when": "!gitlens:readonly && view =~ /^gitlens\\.views\\.commits/", + "group": "navigation@13" + }, + { "command": "gitlens.views.repositories.setFilesLayoutToList", "when": "view =~ /^gitlens\\.views\\.repositories:/ && config.gitlens.views.repositories.files.layout == auto", - "group": "navigation@13" + "group": "navigation@14" }, { "command": "gitlens.views.repositories.setFilesLayoutToTree", "when": "view =~ /^gitlens\\.views\\.repositories:/ && config.gitlens.views.repositories.files.layout == list", - "group": "navigation@13" + "group": "navigation@14" }, { "command": "gitlens.views.repositories.setFilesLayoutToAuto", "when": "view =~ /^gitlens\\.views\\.repositories:/ && config.gitlens.views.repositories.files.layout == tree", - "group": "navigation@13" + "group": "navigation@14" }, { "command": "gitlens.views.repositories.refresh", @@ -5911,8 +5929,13 @@ "group": "inline@9" }, { + "command": "gitlens.views.switchToAnotherBranch", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+current\\b)/", + "group": "inline@10" + }, + { "command": "gitlens.views.switchToBranch", - "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/", "group": "inline@10" }, { @@ -5942,8 +5965,13 @@ "group": "inline@99" }, { + "command": "gitlens.views.switchToAnotherBranch", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+current\\b)/", + "group": "1_gitlens_actions@1" + }, + { "command": "gitlens.views.switchToBranch", - "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/", "group": "1_gitlens_actions@1" }, { diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 8f1a61d..c09ffbc 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -131,6 +131,7 @@ export class ViewCommands { commands.registerCommand('gitlens.views.highlightRevisionChanges', this.highlightRevisionChanges, this); commands.registerCommand('gitlens.views.restore', this.restore, this); commands.registerCommand('gitlens.views.switchToBranch', this.switch, this); + commands.registerCommand('gitlens.views.switchToAnotherBranch', this.switch, this); commands.registerCommand('gitlens.views.switchToCommit', this.switch, this); commands.registerCommand('gitlens.views.switchToTag', this.switch, this); commands.registerCommand('gitlens.views.addRemote', this.addRemote, this); @@ -477,7 +478,11 @@ export class ViewCommands { } @debug() - private switch(node: ViewRefNode) { + private switch(node?: ViewRefNode) { + if (node == null) { + return GitActions.switchTo(Container.git.getHighlanderRepoPath()); + } + if (!(node instanceof ViewRefNode)) return Promise.resolve(); return GitActions.switchTo(