Skip to content

Commit d6c8406

Browse files
committed
Defaults stashes format to ${filePath}
Adds message when there are no stashes Cleans up the stash explorer
1 parent 208d549 commit d6c8406

File tree

6 files changed

+30
-36
lines changed

6 files changed

+30
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ GitLens is highly customizable and provides many configuration settings to allow
294294
|Name | Description
295295
|-----|------------
296296
|`gitlens.stashExplorer.stashFormat`|Specifies the format of stashed changes in the `Git Stashes` explorer <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
297-
|`gitlens.stashExplorer.stashFileFormat`|Specifies the format of a stashed file in the `Git Stashes` explorer <br />Available tokens<br /> ${file} - file name<br /> ${path} - file path
297+
|`gitlens.stashExplorer.stashFileFormat`|Specifies the format of a stashed file in the `Git Stashes` explorer <br />Available tokens<br /> ${file} - file name<br /> ${filePath} - file name and path<br /> ${path} - file path
298298

299299
### Status Bar Settings
300300

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@
420420
},
421421
"gitlens.stashExplorer.stashFileFormat": {
422422
"type": "string",
423-
"default": "${file} \u00a0\u2022\u00a0 ${path}",
424-
"description": "Specifies the format of a stashed file in the `Git Stashes` explorer\nAvailable tokens\n ${file} - file name\n ${path} - file path"
423+
"default": "${filePath}",
424+
"description": "Specifies the format of a stashed file in the `Git Stashes` explorer\nAvailable tokens\n ${file} - file name\n ${filePath} - file name and path\n ${path} - file path"
425425
},
426426
"gitlens.statusBar.enabled": {
427427
"type": "boolean",
@@ -1161,11 +1161,12 @@
11611161
},
11621162
{
11631163
"command": "gitlens.gitExplorer.refresh",
1164-
"when": "gitlens:enabled"
1164+
"when": "false"
1165+
},
11651166
},
11661167
{
11671168
"command": "gitlens.stashExplorer.refresh",
1168-
"when": "gitlens:enabled"
1169+
"when": "false"
11691170
},
11701171
{
11711172
"command": "gitlens.stashExplorer.openChanges",

src/commands/openFileInRemote.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import { GitService, GitUri } from '../gitService';
66
import { Logger } from '../logger';
77
import { OpenInRemoteCommandArgs } from './openInRemote';
88

9+
export interface OpenFileInRemoteCommandArgs {
10+
range?: boolean;
11+
}
12+
913
export class OpenFileInRemoteCommand extends ActiveEditorCommand {
1014

1115
constructor(private git: GitService) {
1216
super(Commands.OpenFileInRemote);
1317
}
1418

15-
async execute(editor?: TextEditor, uri?: Uri) {
19+
async execute(editor?: TextEditor, uri?: Uri, args: OpenFileInRemoteCommandArgs = { range: true }) {
1620
uri = getCommandUri(uri, editor);
1721
if (uri === undefined) return undefined;
1822

@@ -23,7 +27,9 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
2327

2428
try {
2529
const remotes = Arrays.uniqueBy(await this.git.getRemotes(gitUri.repoPath), _ => _.url, _ => !!_.provider);
26-
const range = editor === undefined ? undefined : new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 }));
30+
const range = (args.range && editor !== undefined)
31+
? new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 }))
32+
: undefined;
2733

2834
return commands.executeCommand(Commands.OpenInRemote, uri, {
2935
resource: {

src/configuration.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,12 @@ export interface IConfig {
297297
defaultDateFormat: string | null;
298298

299299
gitExplorer: {
300-
enabled: boolean;
301300
commitFormat: string;
302301
commitFileFormat: string;
303302
// dateFormat: string | null;
304303
};
305304

306305
stashExplorer: {
307-
enabled: boolean;
308306
stashFormat: string;
309307
stashFileFormat: string;
310308
// dateFormat: string | null;

src/views/stashExplorer.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
// import { Functions } from '../system';
33
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode';
4-
import { Commands, DiffWithPreviousCommandArgs, openEditor } from '../commands';
4+
import { Commands, DiffWithPreviousCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
55
import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes';
66
import { GitService, GitUri } from '../gitService';
77

@@ -10,7 +10,6 @@ export * from './explorerNodes';
1010
export class StashExplorer implements TreeDataProvider<ExplorerNode> {
1111

1212
private _node: ExplorerNode;
13-
// private _refreshDebounced: () => void;
1413

1514
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
1615
public get onDidChangeTreeData(): Event<ExplorerNode> {
@@ -24,28 +23,12 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
2423
commands.registerCommand('gitlens.stashExplorer.openStashedFile', this.openStashedFile, this);
2524
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', this.openFileInRemote, this);
2625

27-
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
28-
if (!reasons.includes('stash')) return;
26+
context.subscriptions.push(this.git.onDidChangeRepo(this.onRepoChanged, this));
2927

30-
this.refresh();
31-
}, this));
32-
33-
// this._refreshDebounced = Functions.debounce(this.refresh.bind(this), 250);
34-
35-
// const editor = window.activeTextEditor;
36-
37-
// const uri = (editor !== undefined && editor.document !== undefined)
38-
// ? new GitUri(editor.document.uri, { repoPath: git.repoPath, fileName: editor.document.uri.fsPath })
39-
// : new GitUri(Uri.file(git.repoPath), { repoPath: git.repoPath, fileName: git.repoPath });
40-
41-
const uri = new GitUri(Uri.file(git.repoPath), { repoPath: git.repoPath, fileName: git.repoPath });
42-
this._node = new StashNode(uri, this.context, this.git);
28+
this._node = this.getRootNode();
4329
}
4430

4531
async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
46-
// if (node.onDidChangeTreeData !== undefined) {
47-
// node.onDidChangeTreeData(() => setTimeout(this._refreshDebounced, 1));
48-
// }
4932
return node.getTreeItem();
5033
}
5134

@@ -54,10 +37,16 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
5437
return node.getChildren();
5538
}
5639

57-
// update(uri: GitUri) {
58-
// this._node = new StashNode(uri, this.context, this.git);
59-
// this.refresh();
60-
// }
40+
private getRootNode(): ExplorerNode {
41+
const uri = new GitUri(Uri.file(this.git.repoPath), { repoPath: this.git.repoPath, fileName: this.git.repoPath });
42+
return new StashNode(uri, this.context, this.git);
43+
}
44+
45+
private onRepoChanged(reasons: ('stash' | 'unknown')[]) {
46+
if (!reasons.includes('stash')) return;
47+
48+
this.refresh();
49+
}
6150

6251
refresh() {
6352
this._onDidChangeTreeData.fire();
@@ -81,6 +70,6 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
8170
}
8271

8372
private openFileInRemote(node: StashCommitNode) {
84-
return commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri);
73+
return commands.executeCommand(Commands.OpenFileInRemote, node.commit.uri, { range: false } as OpenFileInRemoteCommandArgs);
8574
}
8675
}

src/views/stashNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export class StashNode extends ExplorerNode {
1414
super(uri);
1515
}
1616

17-
async getChildren(): Promise<StashCommitNode[]> {
17+
async getChildren(): Promise<ExplorerNode[]> {
1818
const stash = await this.git.getStashList(this.uri.repoPath!);
19-
if (stash === undefined) return [];
19+
if (stash === undefined) return [new TextExplorerNode('No stashed changes')];
2020

2121
return [...Iterables.map(stash.commits.values(), c => new StashCommitNode(c, this.context, this.git))];
2222
}

0 commit comments

Comments
 (0)