Skip to content

Commit

Permalink
Fixes #677 - uses original symlink for repo path
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 18, 2019
1 parent eefb3ed commit 1fe3f79
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
37 changes: 35 additions & 2 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
import { GitUri } from './gitUri';
import { RemoteProviderFactory, RemoteProviders } from './remotes/factory';
import { GitReflogParser, GitShortLogParser } from './parsers/parsers';
import { isWindows } from './shell';

export * from './gitUri';
export * from './models/models';
Expand Down Expand Up @@ -2472,11 +2473,43 @@ export class GitService implements Disposable {
return rp;
}

@debug()
private async getRepoPathCore(filePath: string, isDirectory: boolean): Promise<string | undefined> {
const cc = Logger.getCorrelationContext();

try {
return await Git.rev_parse__show_toplevel(isDirectory ? filePath : paths.dirname(filePath));
const path = isDirectory ? filePath : paths.dirname(filePath);

let repoPath = await Git.rev_parse__show_toplevel(path);
if (repoPath === undefined || isWindows) return repoPath;

// If we are not on Windows (symlinks don't seem to have the same issue on Windows), check if we are a symlink and if so, use the symlink path (not its resolved path)
// This is because VS Code will provide document Uris using the symlinked path
return await new Promise<string>(resolve => {
fs.realpath(path, { encoding: 'utf8' }, (err, resolvedPath) => {
if (err != null) {
Logger.debug(cc, `fs.realpath failed; repoPath=${repoPath}`);
resolve(repoPath);
return;
}

if (path.toLowerCase() === resolvedPath.toLowerCase()) {
Logger.debug(cc, `No symlink detected; repoPath=${repoPath}`);
resolve(repoPath);
return;
}

const linkPath = Strings.normalizePath(resolvedPath, { stripTrailingSlash: true });
repoPath = repoPath!.replace(linkPath, path);
Logger.debug(
cc,
`Symlink detected; repoPath=${repoPath}, path=${path}, resolvedPath=${resolvedPath}`
);
resolve(repoPath);
});
});
} catch (ex) {
Logger.error(ex);
Logger.error(ex, cc);
return undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/git/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as paths from 'path';
import * as iconv from 'iconv-lite';
import { Logger } from '../logger';

const isWindows = process.platform === 'win32';
export const isWindows = process.platform === 'win32';

const slashesRegex = /[\\/]/;
const ps1Regex = /\.ps1$/i;
Expand Down

0 comments on commit 1fe3f79

Please sign in to comment.