mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-16 01:25:42 -05:00
Fixes issues with paths on Windows
This commit is contained in:
@@ -91,20 +91,20 @@ export class Git {
|
||||
|
||||
static splitPath(fileName: string, repoPath?: string): [string, string] {
|
||||
if (repoPath) {
|
||||
fileName = this.normalizePath(fileName);
|
||||
repoPath = this.normalizePath(repoPath);
|
||||
|
||||
const normalizedRepoPath = (repoPath.endsWith('/') ? repoPath : `${repoPath}/`).toLowerCase();
|
||||
if (fileName.toLowerCase().startsWith(normalizedRepoPath)) {
|
||||
fileName = fileName.substring(normalizedRepoPath.length);
|
||||
}
|
||||
}
|
||||
else {
|
||||
repoPath = path.dirname(fileName);
|
||||
fileName = path.basename(fileName);
|
||||
repoPath = this.normalizePath(path.dirname(fileName));
|
||||
fileName = this.normalizePath(path.basename(fileName));
|
||||
}
|
||||
|
||||
return [
|
||||
this.normalizePath(fileName),
|
||||
this.normalizePath(repoPath)
|
||||
];
|
||||
return [ fileName, repoPath ];
|
||||
}
|
||||
|
||||
// Git commands
|
||||
@@ -182,7 +182,7 @@ export class Git {
|
||||
}
|
||||
|
||||
static log_file(repoPath: string, fileName: string, sha?: string, maxCount?: number, reverse: boolean = false, startLine?: number, endLine?: number) {
|
||||
const [file, root]: [string, string] = Git.splitPath(fileName, repoPath);
|
||||
const [file, root] = Git.splitPath(fileName, repoPath);
|
||||
|
||||
const params = [...defaultLogParams, `--no-merges`, `--follow`];
|
||||
if (maxCount && !reverse) {
|
||||
@@ -215,7 +215,7 @@ export class Git {
|
||||
}
|
||||
|
||||
static status_file(repoPath: string, fileName: string): Promise<string> {
|
||||
const [file, root]: [string, string] = Git.splitPath(fileName, repoPath);
|
||||
const [file, root] = Git.splitPath(fileName, repoPath);
|
||||
|
||||
const params = ['status', '--porcelain=v2', file];
|
||||
return gitCommand(root, ...params);
|
||||
|
||||
@@ -64,6 +64,8 @@ export class GitUri extends Uri {
|
||||
if (this.repoPath) {
|
||||
directory = path.relative(this.repoPath, directory);
|
||||
}
|
||||
directory = Git.normalizePath(directory);
|
||||
|
||||
return (!directory || directory === '.')
|
||||
? path.basename(this.fsPath)
|
||||
: `${path.basename(this.fsPath)}${separator}${directory}`;
|
||||
|
||||
@@ -86,7 +86,7 @@ export class GitCommit implements IGitCommit {
|
||||
}
|
||||
|
||||
getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string {
|
||||
const directory = path.dirname(this.fileName);
|
||||
const directory = Git.normalizePath(path.dirname(this.fileName));
|
||||
return (!directory || directory === '.')
|
||||
? path.basename(this.fileName)
|
||||
: `${path.basename(this.fileName)}${separator}${directory}`;
|
||||
|
||||
@@ -132,7 +132,7 @@ export class GitBlameParser {
|
||||
|
||||
if (i === 0) {
|
||||
// Try to get the repoPath from the most recent commit
|
||||
repoPath = fileName.replace(`/${entry.fileName}`, '');
|
||||
repoPath = Git.normalizePath(fileName.replace(`/${entry.fileName}`, ''));
|
||||
relativeFileName = path.relative(repoPath, fileName).replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ export class GitLogParser {
|
||||
let recentCommit: GitLogCommit;
|
||||
|
||||
if (isRepoPath) {
|
||||
repoPath = fileNameOrRepoPath;
|
||||
repoPath = Git.normalizePath(fileNameOrRepoPath);
|
||||
}
|
||||
|
||||
for (let i = 0, len = entries.length; i < len; i++) {
|
||||
@@ -203,7 +203,7 @@ export class GitLogParser {
|
||||
}
|
||||
else {
|
||||
// Try to get the repoPath from the most recent commit
|
||||
repoPath = fileNameOrRepoPath.replace(fileNameOrRepoPath.startsWith('/') ? `/${entry.fileName}` : entry.fileName, '');
|
||||
repoPath = Git.normalizePath(fileNameOrRepoPath.replace(fileNameOrRepoPath.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
|
||||
relativeFileName = path.relative(repoPath, fileNameOrRepoPath).replace(/\\/g, '/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
import { GitStatusFileStatus, GitStatusFile, IGitStatus } from './../git';
|
||||
import { Git, GitStatusFileStatus, GitStatusFile, IGitStatus } from './../git';
|
||||
|
||||
interface IFileStatusEntry {
|
||||
staged: boolean;
|
||||
@@ -17,7 +17,7 @@ export class GitStatusParser {
|
||||
if (!lines.length) return undefined;
|
||||
|
||||
const status = {
|
||||
repoPath: repoPath,
|
||||
repoPath: Git.normalizePath(repoPath),
|
||||
state: {
|
||||
ahead: 0,
|
||||
behind: 0
|
||||
|
||||
Reference in New Issue
Block a user