Skip to content

Commit

Permalink
Ensures workspace folder repos are always found
Browse files Browse the repository at this point in the history
Honors `git.repositoryScanMaxDepth` if not overridden
  • Loading branch information
eamodio committed Mar 17, 2022
1 parent e77dbbd commit 89010fa
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Expand Up @@ -364,7 +364,7 @@ export interface AdvancedConfig {
quickPick: {
closeOnFocusOut: boolean;
};
repositorySearchDepth: number;
repositorySearchDepth: number | null;
similarityThreshold: number | null;
}

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Expand Up @@ -303,6 +303,7 @@ export const enum CoreGitCommands {

export const enum CoreGitConfiguration {
AutoRepositoryDetection = 'git.autoRepositoryDetection',
RepositoryScanMaxDepth = 'git.repositoryScanMaxDepth',
FetchOnPull = 'git.fetchOnPull',
UseForcePushWithLease = 'git.useForcePushWithLease',
}
Expand Down
15 changes: 11 additions & 4 deletions src/env/node/git/localGitProvider.ts
Expand Up @@ -338,10 +338,14 @@ export class LocalGitProvider implements GitProvider, Disposable {
const autoRepositoryDetection =
configuration.getAny<boolean | 'subFolders' | 'openEditors'>(
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);
Expand Down Expand Up @@ -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<Repository[]> {
private async repositorySearch(folder: WorkspaceFolder, depth?: number): Promise<Repository[]> {
const cc = Logger.getCorrelationContext();
const depth = configuration.get('advanced.repositorySearchDepth', folder.uri);
depth =
depth ??
configuration.get('advanced.repositorySearchDepth', folder.uri) ??
configuration.getAny<number>(CoreGitConfiguration.RepositoryScanMaxDepth, folder.uri, 1);

Logger.log(cc, `searching (depth=${depth})...`);

Expand Down
25 changes: 7 additions & 18 deletions src/git/gitProviderService.ts
Expand Up @@ -246,13 +246,7 @@ export class GitProviderService implements Disposable {
})
private onWorkspaceFoldersChanged(e: WorkspaceFoldersChangeEvent) {
if (e.added.length) {
const autoRepositoryDetection =
configuration.getAny<boolean | 'subFolders' | 'openEditors'>(
CoreGitConfiguration.AutoRepositoryDetection,
) ?? true;
if (autoRepositoryDetection !== false && autoRepositoryDetection !== 'openEditors') {
void this.discoverRepositories(e.added);
}
void this.discoverRepositories(e.added);
}

if (e.removed.length) {
Expand Down Expand Up @@ -436,24 +430,19 @@ export class GitProviderService implements Disposable {

this._initializing = false;

const autoRepositoryDetection =
configuration.getAny<boolean | 'subFolders' | 'openEditors'>(
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<boolean | 'subFolders' | 'openEditors'>(
CoreGitConfiguration.AutoRepositoryDetection,
)}`;
}
}

Expand Down

0 comments on commit 89010fa

Please sign in to comment.