Browse Source

Closes #1267 - notifies on improper folder casing

main
Eric Amodio 3 years ago
parent
commit
1a4dafe388
5 changed files with 55 additions and 5 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +5
    -0
      package.json
  3. +1
    -0
      src/config.ts
  4. +39
    -5
      src/git/gitService.ts
  5. +9
    -0
      src/messages.ts

+ 1
- 0
CHANGELOG.md View File

@ -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

+ 5
- 0
package.json View File

@ -2496,6 +2496,7 @@
"suppressFileNotUnderSourceControlWarning": false,
"suppressGitDisabledWarning": false,
"suppressGitVersionWarning": false,
"suppressImproperWorkspaceCasingWarning": false,
"suppressLineUncommittedWarning": false,
"suppressNoRepositoryWarning": false,
"suppressRebaseSwitchToTextWarning": false
@ -2525,6 +2526,10 @@
"type": "boolean",
"default": false
},
"suppressImproperWorkspaceCasingWarning": {
"type": "boolean",
"default": false
},
"suppressLineUncommittedWarning": {
"type": "boolean",
"default": false

+ 1
- 0
src/config.ts View File

@ -307,6 +307,7 @@ export interface AdvancedConfig {
suppressFileNotUnderSourceControlWarning: boolean;
suppressGitDisabledWarning: boolean;
suppressGitVersionWarning: boolean;
suppressImproperWorkspaceCasingWarning: boolean;
suppressLineUncommittedWarning: boolean;
suppressNoRepositoryWarning: boolean;
suppressRebaseSwitchToTextWarning: boolean;

+ 39
- 5
src/git/gitService.ts View File

@ -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) {
@ -3303,17 +3304,18 @@ 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;
@ -3321,7 +3323,7 @@ export class GitService implements Disposable {
// 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}`);
@ -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();
}
}
}

+ 9
- 0
src/messages.ts View File

@ -11,6 +11,7 @@ export enum SuppressedMessages {
FileNotUnderSourceControlWarning = 'suppressFileNotUnderSourceControlWarning',
GitDisabledWarning = 'suppressGitDisabledWarning',
GitVersionWarning = 'suppressGitVersionWarning',
IncorrectWorkspaceCasingWarning = 'suppressImproperWorkspaceCasingWarning',
LineUncommittedWarning = 'suppressLineUncommittedWarning',
NoRepositoryWarning = 'suppressNoRepositoryWarning',
RebaseSwitchToTextWarning = 'suppressRebaseSwitchToTextWarning',
@ -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',

Loading…
Cancel
Save