Skip to content

Commit 542a37c

Browse files
committed
fix(path): path handling
Refactored multiple components to utilize the toSimplePath function for improved path normalization. Updated copyFilePathCmd, getMainFolder, getWorktreeList, and pickWorktree to ensure consistent handling of file paths across the application.
1 parent 666839c commit 542a37c

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as vscode from 'vscode';
22
import { Alert } from '@/core/ui/message';
33
import { IWorktreeLess } from '@/types';
4+
import { toSimplePath } from '@/core/util/path';
45

56
export const copyFilePathCmd = (item?: IWorktreeLess) => {
67
if (!item) return;
7-
vscode.env.clipboard.writeText(item.fsPath).then(() => {
8-
Alert.showInformationMessage(vscode.l10n.t('Copied successfully: {0}', item.fsPath));
8+
const folderPath = toSimplePath(item.fsPath);
9+
vscode.env.clipboard.writeText(folderPath).then(() => {
10+
Alert.showInformationMessage(vscode.l10n.t('Copied successfully: {0}', folderPath));
911
});
1012
};

src/core/git/getMainFolder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import path from 'path';
22
import { execBase } from '@/core/git/exec-base';
3+
import { toSimplePath } from '@/core/util/path';
34

45
export const getMainFolder = async (cwd: string) => {
56
try {
67
const { stdout: mainFolderFull } = await execBase(cwd, ['rev-parse', '--git-common-dir']);
78
const trimmed = mainFolderFull.trim();
89
if (!trimmed) return '';
9-
const absPath = path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
10+
const absPath = toSimplePath(path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed));
1011
return path.basename(absPath) === '.git' ? path.dirname(absPath) : absPath;
1112
} catch {
1213
return '';

src/core/git/getWorktreeList.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import folderRoot from '@/core/folderRoot';
22
import { execBase } from '@/core/git/exec-base';
33
import { getNameRev } from '@/core/git/getNameRev';
44
import { getMainFolder } from '@/core/git/getMainFolder';
5+
import { toSimplePath } from '@/core/util/path';
56
import type { IWorktreeDetail, IWorktreeOutputItem } from '@/types';
67
import logger from '@/core/log/logger';
78

@@ -65,7 +66,7 @@ async function buildWorktreeDetail(item: IWorktreeOutputItem, mainFolder: string
6566

6667
return {
6768
name,
68-
path: item.worktree,
69+
path: toSimplePath(item.worktree),
6970
isBare,
7071
isBranch,
7172
isTag,

src/core/quickPick/pickWorktree.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
import { pickAction } from '@/core/quickPick/pickAction';
4646
import { withResolvers } from '@/core/util/promise';
4747
import { satisfies } from '@/core/util/version';
48+
import { toSimplePath } from '@/core/util/path';
4849

4950
interface IWorktreePick extends vscode.QuickPickItem {
5051
kind: vscode.QuickPickItemKind.Default;
@@ -432,7 +433,7 @@ const handleTriggerItemButton = ({ resolve, quickPick, event, actionService }: T
432433
const text = template
433434
.replace(/\$HASH/g, commitDetail.H || '')
434435
.replace(/\$MESSAGE/g, commitDetail.s || '')
435-
.replace(/\$FULL_PATH/g, viewItem.fsPath)
436+
.replace(/\$FULL_PATH/g, toSimplePath(viewItem.fsPath))
436437
.replace(/\$BASE_NAME/g, path.basename(viewItem.fsPath))
437438
.replace(/\$LABEL/g, viewItem.name);
438439
vscode.env.clipboard.writeText(text).then(() => {

0 commit comments

Comments
 (0)