Skip to content

Add --as <name> to tsk add for duplicate worktrees of the same repo - #3

Merged
cavalle merged 3 commits into
mainfrom
feat/duplicate-repo-worktrees
Jul 3, 2026
Merged

Add --as <name> to tsk add for duplicate worktrees of the same repo#3
cavalle merged 3 commits into
mainfrom
feat/duplicate-repo-worktrees

Conversation

@migueltorresvalls

Copy link
Copy Markdown
Contributor

Add --as <name> to tsk add so the same repo can be added twice.

Changes:

  • --as overrides the worktree directory name (default: repo base name)
  • Reject --as with multiple repo paths; validate the name is a clean path component
  • Docs + tests (same-repo-twice, multi-repo rejection, name validation)

🤖 Generated with Claude Code

The worktree directory was always named after the repo's base name, so a
second worktree of the same repo collided. --as <name> overrides the
directory name (paired with -b for a distinct branch), defaulting to the
base name when omitted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
--as previously replaced the whole worktree directory name; it now
appends -<suffix> to the repo's base name, so `tsk add --as hotfix
../gov-fr` produces gov-fr-hotfix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cavalle cavalle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Miguel!

For a parameter called --as I'd expect the full name to be provided, not just a suffix. At the end of the day, using the name of the repo as the default worktree name is just a convention. One that you may want to override occasionally (including but not limited to when you want the same repo twice, heaven knows why!).

So, I think I'd prefer that --as receives the full name: I think it's both more clear and more versatile.

Per review feedback, --as sets the full directory name (overriding the
repo-name default) rather than appending a suffix -- clearer and more
versatile.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 3, 2026 11:00
@migueltorresvalls
migueltorresvalls requested a review from cavalle July 3, 2026 11:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an --as <name> option to tsk add to allow adding the same source repo multiple times to a task by overriding the destination worktree directory name (while still requiring distinct branches).

Changes:

  • Introduces --as flag to override the worktree directory name and rejects --as when multiple repo paths are provided.
  • Adds validWorktreeName validation and corresponding tests for same-repo-twice, multi-repo rejection, and bad names.
  • Updates CLI usage text and README documentation with examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
README.md Documents adding the same repo twice and updates tsk add usage to include --as.
main.go Implements --as flag wiring, validation, and directory name override in worktree creation.
main_test.go Adds test coverage for --as behaviors and validWorktreeName.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.go
Comment on lines +509 to +514
func validWorktreeName(s string) bool {
if s == "" || s == "." || s == ".." {
return false
}
return !strings.ContainsRune(s, '/') && !strings.ContainsRune(s, filepath.Separator)
}

@cavalle cavalle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@cavalle
cavalle merged commit c662904 into main Jul 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants