Skip to content

Commit 5a42ce4

Browse files
committed
Adds remote tracking branch to custom view
Adds setting to show remote tracking branch in custom view
1 parent a5af318 commit 5a42ce4

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
128128
- Provides a context menu with `Open Repository in Remote`, and `Refresh` commands
129129

130130
- `Branches` node — provides a list of the local branches
131-
- Indicates which branch is the current branch
131+
- Indicates which branch is the current branch and [optionally](#gitlens-custom-view-settings) shows the remote tracking branch
132132
- Expand each branch to easily see its revision (commit) history
133133
- Expand each revision (commit) to quickly see the set of files changed, complete with status indicators for adds, changes, renames, and deletes
134134
- Provides a context menu on each changed file with `Open Changes`, `Open Changes with Working Tree`, `Open File`, `Open Revision`, `Open File in Remote`, `Open Revision in Remote`, `Apply Changes`, and `Show Commit File Details` commands
@@ -337,6 +337,7 @@ GitLens is highly customizable and provides many configuration settings to allow
337337
|Name | Description
338338
|-----|------------
339339
|`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view<br />`history` - shows the commit history of the active file<br />`repository` - shows a repository explorer"
340+
|`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` custom view"
340341
|`gitlens.gitExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens` custom view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
341342
|`gitlens.gitExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens` custom view<br />Available tokens<br /> ${file} - file name<br /> ${filePath} - file name and path<br /> ${path} - file path
342343
|`gitlens.gitExplorer.stashFormat`|Specifies the format of stashed changes in the `GitLens` custom view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,6 @@
413413
"default": null,
414414
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
415415
},
416-
"gitlens.gitExplorer.view": {
417-
"type": "string",
418-
"default": "repository",
419-
"enum": [
420-
"history",
421-
"repository"
422-
],
423-
"description": "Specifies the starting view (mode) of the `GitLens` custom view\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer"
424-
},
425416
"gitlens.gitExplorer.commitFormat": {
426417
"type": "string",
427418
"default": "${message} \u00a0\u2022\u00a0 ${authorAgo} \u00a0\u2022\u00a0 ${id}",
@@ -432,6 +423,11 @@
432423
"default": "${filePath}",
433424
"description": "Specifies the format of a committed file in the `GitLens` custom view\nAvailable tokens\n ${file} - file name\n ${filePath} - file name and path\n ${path} - file path"
434425
},
426+
"gitlens.gitExplorer.showTrackingBranch": {
427+
"type": "boolean",
428+
"default": true,
429+
"description": "Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` custom view"
430+
},
435431
"gitlens.gitExplorer.stashFormat": {
436432
"type": "string",
437433
"default": "${message}",
@@ -442,6 +438,15 @@
442438
"default": "${filePath}",
443439
"description": "Specifies the format of a stashed file in the `GitLens` custom view\nAvailable tokens\n ${file} - file name\n ${filePath} - file name and path\n ${path} - file path"
444440
},
441+
"gitlens.gitExplorer.view": {
442+
"type": "string",
443+
"default": "repository",
444+
"enum": [
445+
"history",
446+
"repository"
447+
],
448+
"description": "Specifies the starting view (mode) of the `GitLens` custom view\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer"
449+
},
445450
"gitlens.statusBar.enabled": {
446451
"type": "boolean",
447452
"default": true,

src/configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export interface IConfig {
299299

300300
gitExplorer: {
301301
view: GitExplorerView;
302+
showTrackingBranch: boolean;
302303
commitFormat: string;
303304
commitFileFormat: string;
304305
stashFormat: string;

src/views/branchHistoryNode.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
44
import { CommitNode } from './commitNode';
55
import { GlyphChars } from '../constants';
66
import { ExplorerNode, ResourceType } from './explorerNode';
7-
import { GitBranch, GitRemote, GitService, GitUri } from '../gitService';
7+
import { GitBranch, GitService, GitUri } from '../gitService';
88

99
export class BranchHistoryNode extends ExplorerNode {
1010

1111
readonly resourceType: ResourceType = 'gitlens:branch-history';
1212

13-
constructor(public readonly branch: GitBranch, private readonly remote: GitRemote | undefined, uri: GitUri, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
13+
constructor(public readonly branch: GitBranch, uri: GitUri, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
1414
super(uri);
1515
}
1616

@@ -22,10 +22,11 @@ export class BranchHistoryNode extends ExplorerNode {
2222
}
2323

2424
async getTreeItem(): Promise<TreeItem> {
25-
const name = this.remote !== undefined
26-
? this.branch.name.substring(this.remote.name.length + 1)
27-
: this.branch.name;
28-
const item = new TreeItem(`${name}${this.branch!.current ? ` ${GlyphChars.Space} ${GlyphChars.Check}` : ''}`, TreeItemCollapsibleState.Collapsed);
25+
let name = this.branch.getName();
26+
if (!this.branch.remote && this.branch.tracking !== undefined && this.git.config.gitExplorer.showTrackingBranch) {
27+
name += ` ${GlyphChars.Space}${GlyphChars.ArrowLeftRight}${GlyphChars.Space} ${this.branch.tracking}`;
28+
}
29+
const item = new TreeItem(`${this.branch!.current ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${name}`, TreeItemCollapsibleState.Collapsed);
2930
item.contextValue = this.resourceType;
3031

3132
item.iconPath = {

src/views/branchesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class BranchesNode extends ExplorerNode {
1818
if (branches === undefined) return [];
1919

2020
branches.sort((a, b) => (a.current ? -1 : 1) - (b.current ? -1 : 1) || a.name.localeCompare(b.name));
21-
return [...Iterables.filterMap(branches, b => b.remote ? undefined : new BranchHistoryNode(b, undefined, this.uri, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
21+
return [...Iterables.filterMap(branches, b => b.remote ? undefined : new BranchHistoryNode(b, this.uri, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
2222
}
2323

2424
getTreeItem(): TreeItem {

src/views/remoteNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class RemoteNode extends ExplorerNode {
1818
if (branches === undefined) return [];
1919

2020
branches.sort((a, b) => a.name.localeCompare(b.name));
21-
return [...Iterables.filterMap(branches, b => !b.remote || !b.name.startsWith(this.remote.name) ? undefined : new BranchHistoryNode(b, this.remote, this.uri, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
21+
return [...Iterables.filterMap(branches, b => !b.remote || !b.name.startsWith(this.remote.name) ? undefined : new BranchHistoryNode(b, this.uri, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
2222
}
2323

2424
getTreeItem(): TreeItem {

0 commit comments

Comments
 (0)