From 89010faed41443cc5bb56ebfa5e4c29f0b673b6c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 17 Mar 2022 01:57:08 -0400 Subject: [PATCH] Ensures workspace folder repos are always found Honors `git.repositoryScanMaxDepth` if not overridden --- CHANGELOG.md | 2 ++ README.md | 2 +- package.json | 4 ++-- src/config.ts | 2 +- src/constants.ts | 1 + src/env/node/git/localGitProvider.ts | 15 +++++++++++---- src/git/gitProviderService.ts | 25 +++++++------------------ 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 682bad4..3587f99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Changes the current line blame hover to show at the cursor, rather than the start of the line, when showing the hover over the whole line (e.g. line & annotation) - Changes the default of showing PR information in the current line blame annotation to reduce overhead (e.g. GitHub queries) - Changes [**_Gutter Changes_**](https://github.com/gitkraken/vscode-gitlens#gutter-changes-) file annotations to be theme-aware +- Changes to honor the new(ish) `git.repositoryScanMaxDepth` setting if the `gitlens.advanced.repositorySearchDepth` setting isn't specified ### Fixed +- Fixes [#1909](https://github.com/gitkraken/vscode-gitlens/issues/1909) - Should still "detect" repos directly in the workspace folder(s) even if `git.autoRepositoryDetection` is `false` - Fixes [#1829](https://github.com/gitkraken/vscode-gitlens/issues/1829) - Reduce re-rendering by disabling animation in blame info in the status bar - Fixes [#1864](https://github.com/gitkraken/vscode-gitlens/issues/1864) - Worktrees fail to load in working path with spaces - Fixes [#1881](https://github.com/gitkraken/vscode-gitlens/issues/1881) - Worktrees icon is very small diff --git a/README.md b/README.md index 21b62ab..26dc001 100644 --- a/README.md +++ b/README.md @@ -1067,7 +1067,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings') | `gitlens.advanced.maxSearchItems` | Specifies the maximum number of items to show in a search. Use 0 to specify no maximum | | `gitlens.advanced.messages` | Specifies which messages should be suppressed | | `gitlens.advanced.quickPick.closeOnFocusOut` | Specifies whether to dismiss quick pick menus when focus is lost (if not, press `ESC` to dismiss) | -| `gitlens.advanced.repositorySearchDepth` | Specifies how many folders deep to search for repositories | +| `gitlens.advanced.repositorySearchDepth` | Specifies how many folders deep to search for repositories. Defaults to `git.repositoryScanMaxDepth` | | `gitlens.advanced.similarityThreshold` | Specifies the amount (percent) of similarity a deleted and added file pair must have to be considered a rename | | `gitlens.strings.codeLens.unsavedChanges.recentChangeAndAuthors` | Specifies the string to be shown in place of both the _recent change_ and _authors_ CodeLens when there are unsaved changes | | `gitlens.strings.codeLens.unsavedChanges.recentChangeOnly` | Specifies the string to be shown in place of the _recent change_ CodeLens when there are unsaved changes | diff --git a/package.json b/package.json index 1a80956..c44b55f 100644 --- a/package.json +++ b/package.json @@ -3032,8 +3032,8 @@ }, "gitlens.advanced.repositorySearchDepth": { "type": "number", - "default": 1, - "markdownDescription": "Specifies how many folders deep to search for repositories", + "default": null, + "markdownDescription": "Specifies how many folders deep to search for repositories. Defaults to `#git.repositoryScanMaxDepth#`", "scope": "resource", "order": 10 }, diff --git a/src/config.ts b/src/config.ts index 8584a70..cc60506 100644 --- a/src/config.ts +++ b/src/config.ts @@ -364,7 +364,7 @@ export interface AdvancedConfig { quickPick: { closeOnFocusOut: boolean; }; - repositorySearchDepth: number; + repositorySearchDepth: number | null; similarityThreshold: number | null; } diff --git a/src/constants.ts b/src/constants.ts index 09f7e55..463909b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -303,6 +303,7 @@ export const enum CoreGitCommands { export const enum CoreGitConfiguration { AutoRepositoryDetection = 'git.autoRepositoryDetection', + RepositoryScanMaxDepth = 'git.repositoryScanMaxDepth', FetchOnPull = 'git.fetchOnPull', UseForcePushWithLease = 'git.useForcePushWithLease', } diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 8f9735d..3737ea0 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -338,10 +338,14 @@ export class LocalGitProvider implements GitProvider, Disposable { const autoRepositoryDetection = configuration.getAny( CoreGitConfiguration.AutoRepositoryDetection, + uri, ) ?? true; - if (autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors') return []; - const repositories = await this.repositorySearch(workspace.getWorkspaceFolder(uri)!); + const repositories = await this.repositorySearch( + workspace.getWorkspaceFolder(uri)!, + autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors' ? 0 : undefined, + ); + if (autoRepositoryDetection === true || autoRepositoryDetection === 'subFolders') { for (const repository of repositories) { void this.openScmRepository(repository.uri); @@ -504,9 +508,12 @@ export class LocalGitProvider implements GitProvider, Disposable { result.length !== 0 ? ` (${result.map(r => r.path).join(', ')})` : '' }`, }) - private async repositorySearch(folder: WorkspaceFolder): Promise { + private async repositorySearch(folder: WorkspaceFolder, depth?: number): Promise { const cc = Logger.getCorrelationContext(); - const depth = configuration.get('advanced.repositorySearchDepth', folder.uri); + depth = + depth ?? + configuration.get('advanced.repositorySearchDepth', folder.uri) ?? + configuration.getAny(CoreGitConfiguration.RepositoryScanMaxDepth, folder.uri, 1); Logger.log(cc, `searching (depth=${depth})...`); diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index f6d9176..3fe42a2 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -246,13 +246,7 @@ export class GitProviderService implements Disposable { }) private onWorkspaceFoldersChanged(e: WorkspaceFoldersChangeEvent) { if (e.added.length) { - const autoRepositoryDetection = - configuration.getAny( - CoreGitConfiguration.AutoRepositoryDetection, - ) ?? true; - if (autoRepositoryDetection !== false && autoRepositoryDetection !== 'openEditors') { - void this.discoverRepositories(e.added); - } + void this.discoverRepositories(e.added); } if (e.removed.length) { @@ -436,24 +430,19 @@ export class GitProviderService implements Disposable { this._initializing = false; - const autoRepositoryDetection = - configuration.getAny( - CoreGitConfiguration.AutoRepositoryDetection, - ) ?? true; - const { workspaceFolders } = workspace; - if ( - workspaceFolders?.length && - autoRepositoryDetection !== false && - autoRepositoryDetection !== 'openEditors' - ) { + if (workspaceFolders?.length) { void this.discoverRepositories(workspaceFolders); } else { this.updateContext(); } if (cc != null) { - cc.exitDetails = ` ${GlyphChars.Dot} workspaceFolders=${workspaceFolders?.length}, git.autoRepositoryDetection=${autoRepositoryDetection}`; + cc.exitDetails = ` ${GlyphChars.Dot} workspaceFolders=${ + workspaceFolders?.length + }, git.autoRepositoryDetection=${configuration.getAny( + CoreGitConfiguration.AutoRepositoryDetection, + )}`; } }