Skip to content

Commit

Permalink
Closes #1267 - notifies on improper folder casing
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Feb 2, 2021
1 parent 66de915 commit 1a4dafe
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- Fixes [#1267](https://github.com/eamodio/vscode-gitlens/issues/1267) - File history fails on Git for Windows 2.27 ("There are no editors open that can provide file history information.")
- Fixes [#1006](https://github.com/eamodio/vscode-gitlens/issues/1006) - "GitLens: Open File on Remote" opens wrong Bitbucket URL
- Fixes [#901](https://github.com/eamodio/vscode-gitlens/issues/901) - Bitbucket Server fails when url = https://DOMAIN/stash/scm/PROJECT/REPO.git
- Fixes [#1354](https://github.com/eamodio/vscode-gitlens/issues/1354) - Stuck after merge a branch with a single quote in the name
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,7 @@
"suppressFileNotUnderSourceControlWarning": false,
"suppressGitDisabledWarning": false,
"suppressGitVersionWarning": false,
"suppressImproperWorkspaceCasingWarning": false,
"suppressLineUncommittedWarning": false,
"suppressNoRepositoryWarning": false,
"suppressRebaseSwitchToTextWarning": false
Expand Down Expand Up @@ -2525,6 +2526,10 @@
"type": "boolean",
"default": false
},
"suppressImproperWorkspaceCasingWarning": {
"type": "boolean",
"default": false
},
"suppressLineUncommittedWarning": {
"type": "boolean",
"default": false
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export interface AdvancedConfig {
suppressFileNotUnderSourceControlWarning: boolean;
suppressGitDisabledWarning: boolean;
suppressGitVersionWarning: boolean;
suppressImproperWorkspaceCasingWarning: boolean;
suppressLineUncommittedWarning: boolean;
suppressNoRepositoryWarning: boolean;
suppressRebaseSwitchToTextWarning: boolean;
Expand Down
44 changes: 39 additions & 5 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3279,10 +3279,11 @@ export class GitService implements Disposable {
private async getRepoPathCore(filePath: string, isDirectory: boolean): Promise<string | undefined> {
const cc = Logger.getCorrelationContext();

let repoPath: string | undefined;
try {
const path = isDirectory ? filePath : paths.dirname(filePath);

let repoPath = await Git.rev_parse__show_toplevel(path);
repoPath = await Git.rev_parse__show_toplevel(path);
if (repoPath == null) return repoPath;

if (isWindows) {
Expand All @@ -3303,25 +3304,26 @@ export class GitService implements Disposable {
),
);
if (networkPath != null) {
return Strings.normalizePath(
repoPath = Strings.normalizePath(
repoUri.fsPath.replace(
networkPath,
`${letter.toLowerCase()}:${networkPath.endsWith('\\') ? '\\' : ''}`,
),
);
return repoPath;
}
} catch {}
}

return Strings.normalizePath(pathUri.fsPath);
repoPath = Strings.normalizePath(pathUri.fsPath);
}

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 | undefined>(resolve => {
repoPath = await new Promise<string | undefined>(resolve => {
fs.realpath(path, { encoding: 'utf8' }, (err, resolvedPath) => {
if (err != null) {
Logger.debug(cc, `fs.realpath failed; repoPath=${repoPath}`);
Expand All @@ -3344,9 +3346,41 @@ export class GitService implements Disposable {
resolve(repoPath);
});
});

return repoPath;
} catch (ex) {
Logger.error(ex, cc);
return undefined;
repoPath = undefined;
return repoPath;
} finally {
if (repoPath) {
void this.ensureProperWorkspaceCasing(repoPath, filePath);
}
}
}

@gate(() => '')
private async ensureProperWorkspaceCasing(repoPath: string, filePath: string) {
if (Container.config.advanced.messages.suppressImproperWorkspaceCasingWarning) return;

filePath = filePath.replace(/\\/g, '/');

let regexPath;
let testPath;
if (filePath > repoPath) {
regexPath = filePath;
testPath = repoPath;
} else {
testPath = filePath;
regexPath = repoPath;
}

let pathRegex = new RegExp(`^${regexPath}`);
if (!pathRegex.test(testPath)) {
pathRegex = new RegExp(pathRegex, 'i');
if (pathRegex.test(testPath)) {
await Messages.showIncorrectWorkspaceCasingWarningMessage();
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum SuppressedMessages {
FileNotUnderSourceControlWarning = 'suppressFileNotUnderSourceControlWarning',
GitDisabledWarning = 'suppressGitDisabledWarning',
GitVersionWarning = 'suppressGitVersionWarning',
IncorrectWorkspaceCasingWarning = 'suppressImproperWorkspaceCasingWarning',
LineUncommittedWarning = 'suppressLineUncommittedWarning',
NoRepositoryWarning = 'suppressNoRepositoryWarning',
RebaseSwitchToTextWarning = 'suppressRebaseSwitchToTextWarning',
Expand Down Expand Up @@ -92,6 +93,14 @@ export class Messages {
);
}

static async showIncorrectWorkspaceCasingWarningMessage(): Promise<void> {
void (await Messages.showMessage(
'warn',
'This workspace was opened with a different casing than what exists on disk. Please re-open this workspace with the exact casing as it exists on disk, otherwise you may experience issues with certain Git features, such as missing blame or history.',
SuppressedMessages.IncorrectWorkspaceCasingWarning,
));
}

static showInsidersErrorMessage() {
return Messages.showMessage(
'error',
Expand Down

0 comments on commit 1a4dafe

Please sign in to comment.