Skip to content

Commit 98601ce

Browse files
committed
careful with path comparisons on windows
related to microsoft#50760
1 parent d492467 commit 98601ce

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

extensions/git/src/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Ref, RefType, Git, GitErrorCodes, Branch } from './git';
1010
import { Repository, Resource, Status, CommitOptions, ResourceGroupType } from './repository';
1111
import { Model } from './model';
1212
import { toGitUri, fromGitUri } from './uri';
13-
import { grep, isDescendant } from './util';
13+
import { grep, isDescendant, pathEquals } from './util';
1414
import { applyLineChanges, intersectDiffWithRange, toLineRanges, invertLineChange, getModifiedRange } from './staging';
1515
import * as path from 'path';
1616
import { lstat, Stats } from 'fs';
@@ -1737,7 +1737,7 @@ export class CommandCenter {
17371737
}
17381738

17391739
// Could it be a submodule?
1740-
if (resource.fsPath === repository.root) {
1740+
if (pathEquals(resource.fsPath, repository.root)) {
17411741
repository = this.model.getRepositoryForSubmodule(resource) || repository;
17421742
}
17431743

extensions/git/src/contentProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { workspace, Uri, Disposable, Event, EventEmitter, window } from 'vscode'
99
import { debounce, throttle } from './decorators';
1010
import { fromGitUri, toGitUri } from './uri';
1111
import { Model, ModelChangeEvent, OriginalResourceChangeEvent } from './model';
12-
import { filterEvent, eventToPromise, isDescendant } from './util';
12+
import { filterEvent, eventToPromise, isDescendant, pathEquals } from './util';
1313

1414
interface CacheRow {
1515
uri: Uri;
@@ -130,7 +130,7 @@ export class GitContentProvider {
130130
const { path } = fromGitUri(row.uri);
131131
const isOpen = workspace.textDocuments
132132
.filter(d => d.uri.scheme === 'file')
133-
.some(d => d.uri.fsPath === path);
133+
.some(d => pathEquals(d.uri.fsPath, path));
134134

135135
if (isOpen || now - row.timestamp < THREE_MINUTES) {
136136
cache[row.uri.toString()] = row;

extensions/git/src/util.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,13 @@ export function isDescendant(parent: string, descendant: string): boolean {
324324

325325
return descendant.startsWith(parent);
326326
}
327+
328+
export function pathEquals(a: string, b: string): boolean {
329+
// Windows is case insensitive
330+
if (isWindowsPath(a)) {
331+
a = a.toLowerCase();
332+
b = b.toLowerCase();
333+
}
334+
335+
return a === b;
336+
}

0 commit comments

Comments
 (0)