From 510bc2334c63fd0abe320b6550c1096b655581da Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 22 Dec 2020 23:46:55 -0500 Subject: [PATCH] Adds switch & create branch to Branches --- package.json | 26 +++++++++++++++++++++++--- src/views/nodes/branchesNode.ts | 4 ++++ src/views/viewCommands.ts | 13 ++++++------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6809f9d..4b50ad9 100644 --- a/package.json +++ b/package.json @@ -6671,14 +6671,24 @@ ], "view/item/context": [ { + "command": "gitlens.views.switchToAnotherBranch", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/", + "group": "inline@10" + }, + { + "command": "gitlens.views.createBranch", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/", + "group": "inline@11" + }, + { "command": "gitlens.views.repositories.setBranchesLayoutToList", "when": "viewItem =~ /gitlens:branches\\b/ && config.gitlens.views.repositories.branches.layout == tree", - "group": "inline@1" + "group": "inline@50" }, { "command": "gitlens.views.repositories.setBranchesLayoutToTree", "when": "viewItem =~ /gitlens:branches\\b/ && config.gitlens.views.repositories.branches.layout == list", - "group": "inline@1" + "group": "inline@50" }, { "command": "gitlens.openBranchesOnRemote", @@ -6687,9 +6697,19 @@ "alt": "gitlens.copyRemoteBranchesUrl" }, { + "command": "gitlens.views.switchToAnotherBranch", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/", + "group": "1_gitlens_actions@1" + }, + { + "command": "gitlens.views.createBranch", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/", + "group": "1_gitlens_actions@2" + }, + { "command": "gitlens.openBranchesOnRemote", "when": "viewItem =~ /gitlens:branches\\b(?=.*?\\b\\+remotes\\b)/", - "group": "1_gitlens@1", + "group": "2_gitlens_quickopen@1", "alt": "gitlens.copyRemoteBranchesUrl" }, { diff --git a/src/views/nodes/branchesNode.ts b/src/views/nodes/branchesNode.ts index b4fe380..62cbada 100644 --- a/src/views/nodes/branchesNode.ts +++ b/src/views/nodes/branchesNode.ts @@ -33,6 +33,10 @@ export class BranchesNode extends ViewNode { return BranchesNode.getId(this.repo.path); } + get repoPath(): string { + return this.repo.path; + } + async getChildren(): Promise { if (this._children == null) { const branches = await this.repo.getBranches({ diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 2f24607..c2a3ea4 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -18,6 +18,7 @@ import { Container } from '../container'; import { GitReference, GitRevision } from '../git/git'; import { GitUri } from '../git/gitUri'; import { + BranchesNode, BranchNode, BranchTrackingStatusNode, CommitFileNode, @@ -258,10 +259,8 @@ export class ViewCommands { } @debug() - private createBranch(node?: ViewRefNode) { - if (node != null && !(node instanceof ViewRefNode)) return Promise.resolve(); - - return GitActions.Branch.create(node?.repoPath, node?.ref); + private createBranch(node?: ViewRefNode | BranchesNode) { + return GitActions.Branch.create(node?.repoPath, node instanceof ViewRefNode ? node?.ref : undefined); } @debug() @@ -562,16 +561,16 @@ export class ViewCommands { } @debug() - private switch(node?: ViewRefNode) { + private switch(node?: ViewRefNode | BranchesNode) { if (node == null) { return GitActions.switchTo(Container.git.getHighlanderRepoPath()); } - if (!(node instanceof ViewRefNode)) return Promise.resolve(); + if (!(node instanceof ViewRefNode) && !(node instanceof BranchesNode)) return Promise.resolve(); return GitActions.switchTo( node.repoPath, - node instanceof BranchNode && node.branch.current ? undefined : node.ref, + node instanceof BranchesNode || (node instanceof BranchNode && node.branch.current) ? undefined : node.ref, ); }