worktree-flow 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { WorkspaceAlreadyExistsError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Replaces characters that could cause filesystem issues with underscores.
|
|
5
|
+
* e.g. "release/123" → "release_123"
|
|
6
|
+
*/
|
|
7
|
+
export function sanitizeBranchForFolder(branch) {
|
|
8
|
+
return branch.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* WorkspaceDirectoryService handles workspace directory operations.
|
|
5
12
|
* Pure directory management, no orchestration.
|
|
@@ -10,7 +17,7 @@ export class WorkspaceDirectoryService {
|
|
|
10
17
|
this.fs = fs;
|
|
11
18
|
}
|
|
12
19
|
createWorkspaceDir(destPath, branch) {
|
|
13
|
-
const workspacePath = path.join(destPath, branch);
|
|
20
|
+
const workspacePath = path.join(destPath, sanitizeBranchForFolder(branch));
|
|
14
21
|
if (this.fs.existsSync(workspacePath)) {
|
|
15
22
|
throw new WorkspaceAlreadyExistsError(workspacePath);
|
|
16
23
|
}
|
|
@@ -105,6 +112,7 @@ export class WorkspaceDirectoryService {
|
|
|
105
112
|
}
|
|
106
113
|
findWorkspace(destPath, branchName) {
|
|
107
114
|
const workspaces = this.listWorkspaces(destPath);
|
|
108
|
-
|
|
115
|
+
const sanitized = sanitizeBranchForFolder(branchName);
|
|
116
|
+
return workspaces.find(ws => ws.name === sanitized) || null;
|
|
109
117
|
}
|
|
110
118
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { NotInWorkspaceError, WorkspaceNotFoundError } from './errors.js';
|
|
3
|
+
import { sanitizeBranchForFolder } from './workspaceDirectory.js';
|
|
3
4
|
/**
|
|
4
5
|
* Resolves a workspace path from either an explicit branch name or by auto-detecting
|
|
5
6
|
* from the current working directory.
|
|
@@ -17,7 +18,8 @@ export function resolveWorkspace(branchName, workspaceDir, config, process) {
|
|
|
17
18
|
const { destPath } = config.getRequired();
|
|
18
19
|
if (branchName) {
|
|
19
20
|
// Explicit branch provided
|
|
20
|
-
const
|
|
21
|
+
const sanitized = sanitizeBranchForFolder(branchName);
|
|
22
|
+
const workspacePath = path.join(destPath, sanitized);
|
|
21
23
|
const workspace = workspaceDir.findWorkspace(destPath, branchName);
|
|
22
24
|
if (!workspace) {
|
|
23
25
|
throw new WorkspaceNotFoundError(workspacePath);
|