From cbd5612740cccce4ebed12553152717b4940e0c3 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 23 May 2018 09:37:11 -0400 Subject: [PATCH] Closes #321 - re-adds support for single files --- CHANGELOG.md | 4 ++++ src/git/models/repository.ts | 12 +++++++++--- src/gitService.ts | 25 ++++++++++++++----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1adea1..e2b1bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] +### Added +- Adds (re-adds) support for handling single files — closes [#321](https://github.com/eamodio/vscode-gitlens/issues/321) + ## [8.3.2] - 2018-05-21 ### Fixed - Fixes [#366](https://github.com/eamodio/vscode-gitlens/issues/366) - Running a GitLens command from a keybinding fails (more cases) diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index c9292ab..5912de1 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -88,9 +88,15 @@ export class Repository extends Disposable { ) { super(() => this.dispose()); - this.formattedName = root - ? folder.name - : `${folder.name} (${_path.relative(folder.uri.fsPath, path)})`; + if (root) { + this.formattedName = folder.name; + } + else { + const relativePath = _path.relative(folder.uri.fsPath, path); + this.formattedName = relativePath + ? `${folder.name} (${relativePath})` + : folder.name; + } this.index = folder.index; this.name = folder.name; diff --git a/src/gitService.ts b/src/gitService.ts index a4ac71a..6453b21 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -1193,7 +1193,7 @@ export class GitService extends Disposable { if (filePathOrUri instanceof GitUri) return filePathOrUri.repoPath; // 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) - const repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true }); + let repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true }); if (repo !== undefined) return repo.path; if (typeof filePathOrUri !== 'string') { @@ -1209,21 +1209,24 @@ export class GitService extends Disposable { // If this new repo is inside one of our known roots and we we don't already know about, add it const root = this._repositoryTree.findSubstr(rp); - const folder = root === undefined + let folder = root === undefined ? workspace.getWorkspaceFolder(Uri.file(rp)) : root.folder; - if (folder !== undefined) { - const repo = new Repository(folder, rp, false, this.onAnyRepositoryChanged.bind(this), this._suspended); - this._repositoryTree.set(rp, repo); + if (folder === undefined) { + const parts = rp.split('/'); + folder = { uri: Uri.file(rp), name: parts[parts.length - 1], index: this._repositoryTree.count() }; + } - // Send a notification that the repositories changed - setImmediate(async () => { - await this.updateContext(this._repositoryTree); + repo = new Repository(folder, rp, false, this.onAnyRepositoryChanged.bind(this), this._suspended); + this._repositoryTree.set(rp, repo); - this.fireRepositoriesChanged(); - }); - } + // Send a notification that the repositories changed + setImmediate(async () => { + await this.updateContext(this._repositoryTree); + + this.fireRepositoriesChanged(); + }); return rp; }