Skip to content

Commit 773ac98

Browse files
committed
Extracts working uri helper
1 parent 51efd0c commit 773ac98

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/git/gitUri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,6 @@ export class GitUri extends (Uri as any as UriEx) {
332332

333333
export const unknownGitUri = Object.freeze(new GitUri());
334334

335-
export function isGitUri(uri: any): uri is GitUri {
335+
export function isGitUri(uri: unknown): uri is GitUri {
336336
return uri instanceof GitUri;
337337
}

src/git/gitUri.utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Uri } from 'vscode';
2+
import type { Container } from '../container';
3+
import { GitUri, isGitUri } from './gitUri';
4+
5+
export async function ensureWorkingUri(container: Container, uri: Uri | undefined): Promise<Uri | undefined> {
6+
if (uri == null) return undefined;
7+
8+
const gitUri = !isGitUri(uri) ? await GitUri.fromUri(uri) : uri;
9+
if (gitUri.sha != null) {
10+
// If we have a sha, normalize the history to the working file (so we get a full history all the time)
11+
const workingUri = await container.git.getWorkingUri(gitUri.repoPath!, gitUri);
12+
if (workingUri != null) {
13+
uri = workingUri;
14+
}
15+
}
16+
17+
return uri;
18+
}

src/views/nodes/fileHistoryTrackerNode.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { TextEditor } from 'vscode';
22
import { Disposable, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
33
import type { GitCommitish } from '../../git/gitUri';
44
import { GitUri, unknownGitUri } from '../../git/gitUri';
5+
import { ensureWorkingUri } from '../../git/gitUri.utils';
56
import { isBranchReference } from '../../git/utils/reference.utils';
67
import { isSha } from '../../git/utils/revision.utils';
78
import { showReferencePicker } from '../../quickpicks/referencePicker';
@@ -161,14 +162,8 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-
161162

162163
let gitUri = await GitUri.fromUri(editor.document.uri);
163164

164-
let uri;
165-
if (gitUri.sha != null) {
166-
// If we have a sha, normalize the history to the working file (so we get a full history all the time)
167-
const workingUri = await this.view.container.git.getWorkingUri(gitUri.repoPath!, gitUri);
168-
if (workingUri != null) {
169-
uri = workingUri;
170-
}
171-
}
165+
// If we have a sha, normalize the history to the working file (so we get a full history all the time)
166+
const uri = await ensureWorkingUri(this.view.container, gitUri);
172167

173168
if (this.hasUri && uriEquals(uri ?? gitUri, this.uri)) {
174169
return true;

0 commit comments

Comments
 (0)