diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 913627c8922..b8ec3382b63 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -14,7 +14,7 @@ import { Model } from './model'; import { Repository, Resource, ResourceGroupType } from './repository'; import { applyLineChanges, getModifiedRange, intersectDiffWithRange, invertLineChange, toLineRanges } from './staging'; import { fromGitUri, toGitUri, isGitUri } from './uri'; -import { grep, isDescendant, logTimestamp, pathEquals, relativePath } from './util'; +import { grep, isDescendant, logTimestamp, pathEquals } from './util'; import { Log, LogLevel } from './log'; import { GitTimelineItem } from './timelineProvider'; import { ApiRepository } from './api/api1'; @@ -803,7 +803,7 @@ export class CommandCenter { return; } - const from = relativePath(repository.root, fromUri.fsPath); + const from = path.relative(repository.root, fromUri.fsPath); let to = await window.showInputBox({ value: from, valueSelection: [from.length - path.basename(from).length, from.length] diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 4fb9cb459ee..ed7096ad474 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -14,7 +14,7 @@ import { debounce, memoize, throttle } from './decorators'; import { Commit, GitError, Repository as BaseRepository, Stash, Submodule, LogFileOptions } from './git'; import { StatusBarCommands } from './statusbar'; import { toGitUri } from './uri'; -import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, IDisposable, isDescendant, logTimestamp, onceEvent, relativePath } from './util'; +import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, IDisposable, isDescendant, logTimestamp, onceEvent } from './util'; import { IFileWatcher, watch } from './watch'; import { Log, LogLevel } from './log'; import { IPushErrorHandlerRegistry } from './pushError'; @@ -1161,8 +1161,8 @@ export class Repository implements Disposable { } async stage(resource: Uri, contents: string): Promise { - const path = relativePath(this.repository.root, resource.fsPath).replace(/\\/g, '/'); - await this.run(Operation.Stage, () => this.repository.stage(path, contents)); + const relativePath = path.relative(this.repository.root, resource.fsPath).replace(/\\/g, '/'); + await this.run(Operation.Stage, () => this.repository.stage(relativePath, contents)); this._onDidChangeOriginalResource.fire(resource); } @@ -1545,16 +1545,16 @@ export class Repository implements Disposable { async show(ref: string, filePath: string): Promise { return await this.run(Operation.Show, async () => { - const path = relativePath(this.repository.root, filePath).replace(/\\/g, '/'); + const relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/'); const configFiles = workspace.getConfiguration('files', Uri.file(filePath)); const defaultEncoding = configFiles.get('encoding'); const autoGuessEncoding = configFiles.get('autoGuessEncoding'); try { - return await this.repository.bufferString(`${ref}:${path}`, defaultEncoding, autoGuessEncoding); + return await this.repository.bufferString(`${ref}:${relativePath}`, defaultEncoding, autoGuessEncoding); } catch (err) { if (err.gitErrorCode === GitErrorCodes.WrongCase) { - const gitRelativePath = await this.repository.getGitRelativePath(ref, path); + const gitRelativePath = await this.repository.getGitRelativePath(ref, relativePath); return await this.repository.bufferString(`${ref}:${gitRelativePath}`, defaultEncoding, autoGuessEncoding); } @@ -1565,8 +1565,8 @@ export class Repository implements Disposable { async buffer(ref: string, filePath: string): Promise { return this.run(Operation.Show, () => { - const path = relativePath(this.repository.root, filePath).replace(/\\/g, '/'); - return this.repository.buffer(`${ref}:${path}`); + const relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/'); + return this.repository.buffer(`${ref}:${relativePath}`); }); } @@ -1610,7 +1610,7 @@ export class Repository implements Disposable { return await this.run(Operation.Ignore, async () => { const ignoreFile = `${this.repository.root}${path.sep}.gitignore`; const textToAppend = files - .map(uri => relativePath(this.repository.root, uri.fsPath).replace(/\\/g, '/')) + .map(uri => path.relative(this.repository.root, uri.fsPath).replace(/\\/g, '/')) .join('\n'); const document = await new Promise(c => fs.exists(ignoreFile, c)) diff --git a/extensions/git/src/util.ts b/extensions/git/src/util.ts index f55da05ddf8..7631dbe4727 100644 --- a/extensions/git/src/util.ts +++ b/extensions/git/src/util.ts @@ -8,7 +8,6 @@ import { dirname, sep } from 'path'; import { Readable } from 'stream'; import { promises as fs, createReadStream } from 'fs'; import * as byline from 'byline'; -import path = require('path'); export const isMacintosh = process.platform === 'darwin'; export const isWindows = process.platform === 'win32'; @@ -288,16 +287,6 @@ export function detectUnicodeEncoding(buffer: Buffer): Encoding | null { return null; } -function normalizePath(path: string): string { - // Windows & Mac are currently being handled - // as case insensitive file systems in VS Code. - if (isWindows || isMacintosh) { - return path.toLowerCase(); - } - - return path; -} - export function isDescendant(parent: string, descendant: string): boolean { if (parent === descendant) { return true; @@ -307,15 +296,25 @@ export function isDescendant(parent: string, descendant: string): boolean { parent += sep; } - return normalizePath(descendant).startsWith(normalizePath(parent)); + // Windows & Mac are currently being handled + // as case insensitive file systems in VS Code. + if (isWindows || isMacintosh) { + parent = parent.toLowerCase(); + descendant = descendant.toLowerCase(); + } + + return descendant.startsWith(parent); } export function pathEquals(a: string, b: string): boolean { - return normalizePath(a) === normalizePath(b); -} + // Windows & Mac are currently being handled + // as case insensitive file systems in VS Code. + if (isWindows || isMacintosh) { + a = a.toLowerCase(); + b = b.toLowerCase(); + } -export function relativePath(from: string, to: string): string { - return path.relative(normalizePath(from), normalizePath(to)); + return a === b; } export function* splitInChunks(array: string[], maxChunkLength: number): IterableIterator {