-
Notifications
You must be signed in to change notification settings - Fork 227
feat(worktree): add optional custom branch and worktree names #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,9 @@ export class WorktreeService { | |
| projectPath: string, | ||
| taskName: string, | ||
| projectId: string, | ||
| baseRef?: string | ||
| baseRef?: string, | ||
| customBranchName?: string, | ||
| customWorktreeName?: string | ||
| ): Promise<WorktreeInfo> { | ||
| // Declare variables outside try block for access in catch block | ||
| let branchName: string | undefined; | ||
|
|
@@ -192,8 +194,17 @@ export class WorktreeService { | |
| const { getAppSettings } = await import('../settings'); | ||
| const settings = getAppSettings(); | ||
| const prefix = settings?.repository?.branchPrefix || 'emdash'; | ||
| branchName = this.sanitizeBranchName(`${prefix}/${sluggedName}-${hash}`); | ||
| worktreePath = path.join(projectPath, '..', `worktrees/${sluggedName}-${hash}`); | ||
|
|
||
| // Use custom names if provided, otherwise auto-generate | ||
| branchName = customBranchName | ||
| ? this.sanitizeBranchName(customBranchName) | ||
| : this.sanitizeBranchName(`${prefix}/${sluggedName}-${hash}`); | ||
|
|
||
| const worktreeDirName = customWorktreeName | ||
| ? this.sanitizeWorktreeName(customWorktreeName) | ||
| : `${sluggedName}-${hash}`; | ||
|
|
||
| worktreePath = path.join(projectPath, '..', `worktrees/${worktreeDirName}`); | ||
| const worktreeId = this.stableIdFromPath(worktreePath); | ||
|
|
||
| log.info(`Creating worktree: ${branchName} -> ${worktreePath}`); | ||
|
|
@@ -400,6 +411,16 @@ export class WorktreeService { | |
| return n; | ||
| } | ||
|
|
||
| /** Sanitize worktree directory name to ensure it's a valid path component */ | ||
| private sanitizeWorktreeName(name: string): string { | ||
| return name | ||
| .replace(/[/\\:*?"<>|]/g, '-') | ||
| .replace(/\s+/g, '-') | ||
| .replace(/-+/g, '-') | ||
| .replace(/^-|-$/g, '') | ||
| .slice(0, 100); | ||
| } | ||
|
||
|
|
||
| /** Remove a worktree */ | ||
| async removeWorktree( | ||
| projectPath: string, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sanitizeBranchNameandsanitizeWorktreeNameare duplicated verbatim in bothWorktreeService(lines 401–422) andWorktreePoolService(lines 682–704). Keeping two copies means any future bug-fix or rule change must be applied in both places — and divergence is one commit away from happening.Consider extracting these helpers into a shared module (e.g.
src/main/lib/worktreeNameUtils.ts) and importing them in both services to prevent drift.