Skip to content

Commit 779b3e4

Browse files
committed
Fixes #261 & #262 - submodule handling regressed
1 parent 5ec0a0b commit 779b3e4

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
### Fixed
9+
- Fixes regression working with submodules
10+
- Fixes [#262](https://github.com/eamodio/vscode-gitlens/issues/262) - GitLens only available in SCM diff windows
11+
- Fixes [#261](https://github.com/eamodio/vscode-gitlens/issues/261) - Unable to open compare. The file is probably not under source control
12+
713
## [7.5.7] - 2018-01-25
814
### Added
915
- Adds a repository quick pick menu to the *Show Commit Search* command (`gitlens.showCommitSearch`) when there is no active repository

src/gitService.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ export class GitService extends Disposable {
988988
}
989989

990990
private async getLogForFileCore(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean }, document: TrackedDocument<GitDocumentState>, key: string): Promise<GitLog | undefined> {
991-
if (!(await this.isTracked(fileName, repoPath, options.ref))) {
991+
if (!(await this.isTracked(fileName, repoPath, { ref: options.ref }))) {
992992
Logger.log(`Skipping log; '${fileName}' is not tracked`);
993993
return GitService.emptyPromise as Promise<GitLog>;
994994
}
@@ -1089,13 +1089,14 @@ export class GitService extends Disposable {
10891089
}
10901090
}
10911091

1092-
async getRepoPath(filePath: string, options?: { ref?: string, skipTrackingCheck?: boolean }): Promise<string | undefined>;
1093-
async getRepoPath(uri: Uri | undefined, options?: { ref?: string, skipTrackingCheck?: boolean }): Promise<string | undefined>;
1094-
async getRepoPath(filePathOrUri: string | Uri | undefined, options: { ref?: string, skipTrackingCheck?: boolean } = {}): Promise<string | undefined> {
1092+
async getRepoPath(filePath: string, options?: { ref?: string }): Promise<string | undefined>;
1093+
async getRepoPath(uri: Uri | undefined, options?: { ref?: string }): Promise<string | undefined>;
1094+
async getRepoPath(filePathOrUri: string | Uri | undefined, options: { ref?: string } = {}): Promise<string | undefined> {
10951095
if (filePathOrUri === undefined) return await this.getActiveRepoPath();
10961096
if (filePathOrUri instanceof GitUri) return filePathOrUri.repoPath;
10971097

1098-
const repo = await this.getRepository(filePathOrUri, options);
1098+
// 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)
1099+
const repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true });
10991100
if (repo !== undefined) return repo.path;
11001101

11011102
const rp = await this.getRepoPathCore(typeof filePathOrUri === 'string' ? filePathOrUri : filePathOrUri.fsPath, false);
@@ -1149,10 +1150,10 @@ export class GitService extends Disposable {
11491150
return this._repositoryTree;
11501151
}
11511152

1152-
async getRepository(repoPath: string, options?: { ref?: string, skipTrackingCheck?: boolean }): Promise<Repository | undefined>;
1153-
async getRepository(uri: Uri, options?: { ref?: string, skipTrackingCheck?: boolean }): Promise<Repository | undefined>;
1154-
async getRepository(repoPathOrUri: string | Uri, options?: { ref?: string, skipTrackingCheck?: boolean }): Promise<Repository | undefined>;
1155-
async getRepository(repoPathOrUri: string | Uri, options: { ref?: string, skipTrackingCheck?: boolean } = {}): Promise<Repository | undefined> {
1153+
async getRepository(repoPath: string, options?: { ref?: string, skipCacheUpdate?: boolean }): Promise<Repository | undefined>;
1154+
async getRepository(uri: Uri, options?: { ref?: string, skipCacheUpdate?: boolean }): Promise<Repository | undefined>;
1155+
async getRepository(repoPathOrUri: string | Uri, options?: { ref?: string, skipCacheUpdate?: boolean }): Promise<Repository | undefined>;
1156+
async getRepository(repoPathOrUri: string | Uri, options: { ref?: string, skipCacheUpdate?: boolean } = {}): Promise<Repository | undefined> {
11561157
const repositoryTree = await this.getRepositoryTree();
11571158

11581159
let path: string;
@@ -1179,10 +1180,8 @@ export class GitService extends Disposable {
11791180
const repo = repositoryTree.findSubstr(path);
11801181
if (repo === undefined) return undefined;
11811182

1182-
if (!options.skipTrackingCheck) {
1183-
// Make sure the file is tracked in that repo, before returning
1184-
if (!await this.isTracked(path, repo.path, options.ref)) return undefined;
1185-
}
1183+
// Make sure the file is tracked in this repo before returning -- it could be from a submodule
1184+
if (!await this.isTracked(path, repo.path, options)) return undefined;
11861185
return repo;
11871186
}
11881187

@@ -1275,10 +1274,12 @@ export class GitService extends Disposable {
12751274
return scheme === DocumentSchemes.File || scheme === DocumentSchemes.Git || scheme === DocumentSchemes.GitLensGit;
12761275
}
12771276

1278-
async isTracked(fileName: string, repoPath?: string, sha?: string): Promise<boolean>;
1277+
async isTracked(fileName: string, repoPath?: string, options?: { ref?: string, skipCacheUpdate?: boolean }): Promise<boolean>;
12791278
async isTracked(uri: GitUri): Promise<boolean>;
1280-
async isTracked(fileNameOrUri: string | GitUri, repoPath?: string, sha?: string): Promise<boolean> {
1281-
if (sha === GitService.deletedSha) return false;
1279+
async isTracked(fileNameOrUri: string | GitUri, repoPath?: string, options: { ref?: string, skipCacheUpdate?: boolean } = {}): Promise<boolean> {
1280+
if (options.ref === GitService.deletedSha) return false;
1281+
1282+
let ref = options.ref;
12821283

12831284
let cacheKey: string;
12841285
let fileName: string;
@@ -1291,29 +1292,30 @@ export class GitService extends Disposable {
12911292

12921293
fileName = fileNameOrUri.fsPath;
12931294
repoPath = fileNameOrUri.repoPath;
1294-
sha = fileNameOrUri.sha;
1295+
ref = fileNameOrUri.sha;
12951296
cacheKey = GitUri.toKey(fileName);
12961297
}
12971298

1298-
if (sha !== undefined) {
1299-
cacheKey += `:${sha}`;
1299+
if (ref !== undefined) {
1300+
cacheKey += `:${ref}`;
13001301
}
13011302

1302-
Logger.log(`isTracked('${fileName}', '${repoPath}', '${sha}')`);
1303+
Logger.log(`isTracked('${fileName}', '${repoPath}', '${ref}')`);
13031304

13041305
let tracked = this._trackedCache.get(cacheKey);
13051306
if (tracked !== undefined) return await tracked;
13061307

1307-
tracked = this.isTrackedCore(repoPath === undefined ? '' : repoPath, fileName, sha);
1308-
this._trackedCache.set(cacheKey, tracked);
1308+
tracked = this.isTrackedCore(fileName, repoPath === undefined ? '' : repoPath, ref);
1309+
if (options.skipCacheUpdate) return tracked;
13091310

1311+
this._trackedCache.set(cacheKey, tracked);
13101312
tracked = await tracked;
13111313
this._trackedCache.set(cacheKey, tracked);
13121314

13131315
return tracked;
13141316
}
13151317

1316-
private async isTrackedCore(repoPath: string, fileName: string, ref?: string) {
1318+
private async isTrackedCore(fileName: string, repoPath: string, ref?: string) {
13171319
if (ref === GitService.deletedSha) return false;
13181320

13191321
try {

0 commit comments

Comments
 (0)