Skip to content

Commit cbd5612

Browse files
committed
Closes #321 - re-adds support for single files
1 parent 4453260 commit cbd5612

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Added
9+
- Adds (re-adds) support for handling single files — closes [#321](https://github.com/eamodio/vscode-gitlens/issues/321)
10+
711
## [8.3.2] - 2018-05-21
812
### Fixed
913
- Fixes [#366](https://github.com/eamodio/vscode-gitlens/issues/366) - Running a GitLens command from a keybinding fails (more cases)

src/git/models/repository.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ export class Repository extends Disposable {
8888
) {
8989
super(() => this.dispose());
9090

91-
this.formattedName = root
92-
? folder.name
93-
: `${folder.name} (${_path.relative(folder.uri.fsPath, path)})`;
91+
if (root) {
92+
this.formattedName = folder.name;
93+
}
94+
else {
95+
const relativePath = _path.relative(folder.uri.fsPath, path);
96+
this.formattedName = relativePath
97+
? `${folder.name} (${relativePath})`
98+
: folder.name;
99+
}
94100
this.index = folder.index;
95101
this.name = folder.name;
96102

src/gitService.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ export class GitService extends Disposable {
11931193
if (filePathOrUri instanceof GitUri) return filePathOrUri.repoPath;
11941194

11951195
// Don't save the tracking info to the cache, because we could be looking in the wrong place (e.g. looking in the root when the file is in a submodule)
1196-
const repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true });
1196+
let repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true });
11971197
if (repo !== undefined) return repo.path;
11981198

11991199
if (typeof filePathOrUri !== 'string') {
@@ -1209,21 +1209,24 @@ export class GitService extends Disposable {
12091209

12101210
// If this new repo is inside one of our known roots and we we don't already know about, add it
12111211
const root = this._repositoryTree.findSubstr(rp);
1212-
const folder = root === undefined
1212+
let folder = root === undefined
12131213
? workspace.getWorkspaceFolder(Uri.file(rp))
12141214
: root.folder;
12151215

1216-
if (folder !== undefined) {
1217-
const repo = new Repository(folder, rp, false, this.onAnyRepositoryChanged.bind(this), this._suspended);
1218-
this._repositoryTree.set(rp, repo);
1216+
if (folder === undefined) {
1217+
const parts = rp.split('/');
1218+
folder = { uri: Uri.file(rp), name: parts[parts.length - 1], index: this._repositoryTree.count() };
1219+
}
12191220

1220-
// Send a notification that the repositories changed
1221-
setImmediate(async () => {
1222-
await this.updateContext(this._repositoryTree);
1221+
repo = new Repository(folder, rp, false, this.onAnyRepositoryChanged.bind(this), this._suspended);
1222+
this._repositoryTree.set(rp, repo);
12231223

1224-
this.fireRepositoriesChanged();
1225-
});
1226-
}
1224+
// Send a notification that the repositories changed
1225+
setImmediate(async () => {
1226+
await this.updateContext(this._repositoryTree);
1227+
1228+
this.fireRepositoriesChanged();
1229+
});
12271230

12281231
return rp;
12291232
}

0 commit comments

Comments
 (0)