Skip to content

Commit 510bc23

Browse files
committed
Adds switch & create branch to Branches
1 parent 93e0055 commit 510bc23

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

package.json

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6670,26 +6670,46 @@
66706670
}
66716671
],
66726672
"view/item/context": [
6673+
{
6674+
"command": "gitlens.views.switchToAnotherBranch",
6675+
"when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/",
6676+
"group": "inline@10"
6677+
},
6678+
{
6679+
"command": "gitlens.views.createBranch",
6680+
"when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/",
6681+
"group": "inline@11"
6682+
},
66736683
{
66746684
"command": "gitlens.views.repositories.setBranchesLayoutToList",
66756685
"when": "viewItem =~ /gitlens:branches\\b/ && config.gitlens.views.repositories.branches.layout == tree",
6676-
"group": "inline@1"
6686+
"group": "inline@50"
66776687
},
66786688
{
66796689
"command": "gitlens.views.repositories.setBranchesLayoutToTree",
66806690
"when": "viewItem =~ /gitlens:branches\\b/ && config.gitlens.views.repositories.branches.layout == list",
6681-
"group": "inline@1"
6691+
"group": "inline@50"
66826692
},
66836693
{
66846694
"command": "gitlens.openBranchesOnRemote",
66856695
"when": "viewItem =~ /gitlens:branches\\b(?=.*?\\b\\+remotes\\b)/",
66866696
"group": "inline@98",
66876697
"alt": "gitlens.copyRemoteBranchesUrl"
66886698
},
6699+
{
6700+
"command": "gitlens.views.switchToAnotherBranch",
6701+
"when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/",
6702+
"group": "1_gitlens_actions@1"
6703+
},
6704+
{
6705+
"command": "gitlens.views.createBranch",
6706+
"when": "!gitlens:readonly && viewItem =~ /gitlens:branches\\b/",
6707+
"group": "1_gitlens_actions@2"
6708+
},
66896709
{
66906710
"command": "gitlens.openBranchesOnRemote",
66916711
"when": "viewItem =~ /gitlens:branches\\b(?=.*?\\b\\+remotes\\b)/",
6692-
"group": "1_gitlens@1",
6712+
"group": "2_gitlens_quickopen@1",
66936713
"alt": "gitlens.copyRemoteBranchesUrl"
66946714
},
66956715
{

src/views/nodes/branchesNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class BranchesNode extends ViewNode<BranchesView | RepositoriesView> {
3333
return BranchesNode.getId(this.repo.path);
3434
}
3535

36+
get repoPath(): string {
37+
return this.repo.path;
38+
}
39+
3640
async getChildren(): Promise<ViewNode[]> {
3741
if (this._children == null) {
3842
const branches = await this.repo.getBranches({

src/views/viewCommands.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Container } from '../container';
1818
import { GitReference, GitRevision } from '../git/git';
1919
import { GitUri } from '../git/gitUri';
2020
import {
21+
BranchesNode,
2122
BranchNode,
2223
BranchTrackingStatusNode,
2324
CommitFileNode,
@@ -258,10 +259,8 @@ export class ViewCommands {
258259
}
259260

260261
@debug()
261-
private createBranch(node?: ViewRefNode) {
262-
if (node != null && !(node instanceof ViewRefNode)) return Promise.resolve();
263-
264-
return GitActions.Branch.create(node?.repoPath, node?.ref);
262+
private createBranch(node?: ViewRefNode | BranchesNode) {
263+
return GitActions.Branch.create(node?.repoPath, node instanceof ViewRefNode ? node?.ref : undefined);
265264
}
266265

267266
@debug()
@@ -562,16 +561,16 @@ export class ViewCommands {
562561
}
563562

564563
@debug()
565-
private switch(node?: ViewRefNode) {
564+
private switch(node?: ViewRefNode | BranchesNode) {
566565
if (node == null) {
567566
return GitActions.switchTo(Container.git.getHighlanderRepoPath());
568567
}
569568

570-
if (!(node instanceof ViewRefNode)) return Promise.resolve();
569+
if (!(node instanceof ViewRefNode) && !(node instanceof BranchesNode)) return Promise.resolve();
571570

572571
return GitActions.switchTo(
573572
node.repoPath,
574-
node instanceof BranchNode && node.branch.current ? undefined : node.ref,
573+
node instanceof BranchesNode || (node instanceof BranchNode && node.branch.current) ? undefined : node.ref,
575574
);
576575
}
577576

0 commit comments

Comments
 (0)