Skip to content

Commit 4cd6271

Browse files
committed
Adds 'realpath' option to resolve symbolic links when determining file paths for Git operations (#1330)
1 parent c00c630 commit 4cd6271

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5558,6 +5558,13 @@
55585558
"scope": "window",
55595559
"order": 70
55605560
},
5561+
"gitlens.realpath": {
5562+
"type": "boolean",
5563+
"default": false,
5564+
"markdownDescription": "[Experimental] Specifies whether to resolve symbolic links when determining file paths for Git operations",
5565+
"scope": "window",
5566+
"order": 80
5567+
},
55615568
"gitlens.insiders": {
55625569
"deprecationMessage": "Deprecated. Use the pre-release edition of GitLens instead",
55635570
"markdownDeprecationMessage": "Deprecated. Use the pre-release of GitLens instead"

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface Config {
4343
readonly proxy: ProxyConfig | null;
4444
readonly rebaseEditor: RebaseEditorConfig;
4545
readonly remotes: RemotesConfig[] | null;
46+
readonly realpath: boolean;
4647
readonly showWhatsNewAfterUpgrades: boolean;
4748
readonly sortBranchesBy: BranchSorting;
4849
readonly sortContributorsBy: ContributorSorting;

src/git/gitUri.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Uri } from 'vscode';
2+
import { isWeb } from '@env/platform';
23
import { getQueryDataFromScmGitUri } from '../@types/vscode.git.uri';
34
import { Schemes } from '../constants';
45
import { Container } from '../container';
56
import type { GitHubAuthorityMetadata } from '../plus/remotehub';
7+
import { configuration } from '../system/-webview/configuration';
68
import { formatPath } from '../system/-webview/formatPath';
79
import { getBestPath, relativeDir, splitPath } from '../system/-webview/path';
810
import { isVirtualUri } from '../system/-webview/vscode/uris';
@@ -248,6 +250,21 @@ export class GitUri extends (Uri as any as UriEx) {
248250
@debug({ exit: true })
249251
static async fromUri(uri: Uri): Promise<GitUri> {
250252
if (isGitUri(uri)) return uri;
253+
254+
// Check for symbolic links (Node.js only)
255+
if (configuration.get('realpath') && !isWeb && uri.scheme === 'file') {
256+
try {
257+
const { realpathSync } = await import('fs');
258+
const realPath = realpathSync(uri.fsPath);
259+
if (uri.fsPath !== realPath) {
260+
const newUri = Uri.file(realPath);
261+
return await this.fromUri(newUri);
262+
}
263+
} catch {
264+
// Ignore errors (e.g., if path doesn't exist)
265+
}
266+
}
267+
251268
if (!Container.instance.git.isTrackable(uri)) return new GitUri(uri);
252269
if (uri.scheme === Schemes.GitLens) return new GitUri(uri);
253270

0 commit comments

Comments
 (0)