Skip to content

Commit ee93653

Browse files
naps62claude
andcommitted
fix: address PR review feedback
- Re-add --no-worktree/--no-wt flag to skip auto-creation per-session - TUI: only enable worktree checkbox when path is a git repo, set branchAutoSet so branch auto-tracks name edits - Move duplicate detection after worktree creation so it uses the final session path instead of the pre-worktree path - Fork: add branch-exists check when createNewBranch is true to prevent silently reusing an existing branch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4d0990c commit ee93653

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

cmd/agent-deck/launch_cmd.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func handleLaunch(profile string, args []string) {
3939
newBranch := fs.Bool("b", false, "Create new branch (use with --worktree)")
4040
newBranchLong := fs.Bool("new-branch", false, "Create new branch")
4141
worktreeLocation := fs.String("location", "", "Worktree location: sibling, subdirectory, or custom path")
42-
42+
noWorktree := fs.Bool("no-worktree", false, "Skip automatic worktree creation")
43+
noWorktreeShort := fs.Bool("no-wt", false, "Skip automatic worktree creation (short)")
4344

4445
// MCP flag
4546
var mcpFlags []string
@@ -171,27 +172,19 @@ func handleLaunch(profile string, args []string) {
171172
}
172173
}
173174

174-
// Resolve title before worktree creation (auto-create needs title for branch name)
175+
// Generate title before worktree creation (auto-create needs title for branch name).
176+
// Duplicate detection runs after worktree creation so it uses the final session path.
175177
if sessionTitle == "" {
176178
sessionTitle = filepath.Base(path)
177179
}
178180

179-
// Check for duplicate and generate unique title
180181
userProvidedTitle := (mergeFlags(*title, *titleShort) != "")
181182
if !userProvidedTitle {
182183
sessionTitle = generateUniqueTitle(instances, sessionTitle, path)
183-
} else {
184-
if isDupe, existingInst := isDuplicateSession(instances, sessionTitle, path); isDupe {
185-
out.Error(
186-
fmt.Sprintf("session already exists: %s (%s)", existingInst.Title, existingInst.ID),
187-
ErrCodeAlreadyExists,
188-
)
189-
os.Exit(1)
190-
}
191184
}
192185

193-
// Auto-create worktree if configured or requested via CLI flag
194-
if wtBranch == "" {
186+
// Auto-create worktree if configured and not explicitly skipped
187+
if wtBranch == "" && !*noWorktree && !*noWorktreeShort {
195188
wtSettings := session.GetWorktreeSettings()
196189
if wtSettings.AutoCreate && git.IsGitRepo(path) {
197190
wtBranch = wtSettings.Prefix() + git.SanitizeBranchName(sessionTitle)
@@ -263,6 +256,17 @@ func handleLaunch(profile string, args []string) {
263256
path = worktreePath
264257
}
265258

259+
// Check for duplicate sessions using the final path (after worktree resolution)
260+
if userProvidedTitle {
261+
if isDupe, existingInst := isDuplicateSession(instances, sessionTitle, path); isDupe {
262+
out.Error(
263+
fmt.Sprintf("session already exists: %s (%s)", existingInst.Title, existingInst.ID),
264+
ErrCodeAlreadyExists,
265+
)
266+
os.Exit(1)
267+
}
268+
}
269+
266270
// Create new instance
267271
var newInstance *session.Instance
268272
if sessionGroup != "" {

cmd/agent-deck/main.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ func handleAdd(profile string, args []string) {
818818
newBranch := fs.Bool("b", false, "Create new branch (use with --worktree)")
819819
newBranchLong := fs.Bool("new-branch", false, "Create new branch")
820820
worktreeLocation := fs.String("location", "", "Worktree location: sibling, subdirectory, or custom path")
821-
821+
noWorktree := fs.Bool("no-worktree", false, "Skip automatic worktree creation")
822+
noWorktreeShort := fs.Bool("no-wt", false, "Skip automatic worktree creation (short)")
822823

823824
// MCP flag - can be specified multiple times
824825
var mcpFlags []string
@@ -1014,31 +1015,23 @@ func handleAdd(profile string, args []string) {
10141015
}
10151016
}
10161017

1017-
// Resolve title before worktree creation (auto-create needs title for branch name)
1018+
// Generate title before worktree creation (auto-create needs title for branch name).
1019+
// Duplicate detection runs after worktree creation so it uses the final session path.
10181020
if sessionTitle == "" {
10191021
sessionTitle = filepath.Base(path)
10201022
}
10211023

1022-
// Track if user provided explicit title or we auto-generated from folder name
10231024
userProvidedTitle := (mergeFlags(*title, *titleShort) != "")
10241025
isQuick := *quickCreate || *quickCreateShort
10251026

10261027
if isQuick && !userProvidedTitle {
1027-
// Quick mode: use auto-generated adjective-noun name
10281028
sessionTitle = session.GenerateUniqueSessionName(instances, sessionGroup)
10291029
} else if !userProvidedTitle {
1030-
// User didn't provide title - auto-generate unique title for this path
10311030
sessionTitle = generateUniqueTitle(instances, sessionTitle, path)
1032-
} else {
1033-
// User provided explicit title - check for exact duplicate (same title AND path)
1034-
if isDupe, existingInst := isDuplicateSession(instances, sessionTitle, path); isDupe {
1035-
fmt.Printf("Session already exists with same title and path: %s (%s)\n", existingInst.Title, existingInst.ID)
1036-
os.Exit(0)
1037-
}
10381031
}
10391032

1040-
// Auto-create worktree if configured or requested via CLI flag
1041-
if wtBranch == "" {
1033+
// Auto-create worktree if configured and not explicitly skipped
1034+
if wtBranch == "" && !*noWorktree && !*noWorktreeShort {
10421035
wtSettings := session.GetWorktreeSettings()
10431036
if wtSettings.AutoCreate && git.IsGitRepo(path) {
10441037
wtBranch = wtSettings.Prefix() + git.SanitizeBranchName(sessionTitle)
@@ -1125,6 +1118,14 @@ func handleAdd(profile string, args []string) {
11251118
path = worktreePath
11261119
}
11271120

1121+
// Check for duplicate sessions using the final path (after worktree resolution)
1122+
if userProvidedTitle {
1123+
if isDupe, existingInst := isDuplicateSession(instances, sessionTitle, path); isDupe {
1124+
fmt.Printf("Session already exists with same title and path: %s (%s)\n", existingInst.Title, existingInst.ID)
1125+
os.Exit(0)
1126+
}
1127+
}
1128+
11281129
// Create new instance (without starting tmux)
11291130
var newInstance *session.Instance
11301131
if sessionGroup != "" {

cmd/agent-deck/session_cmd.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ func handleSessionFork(profile string, args []string) {
385385
worktreeBranchLong := fs.String("worktree", "", "Create fork in git worktree for branch")
386386
newBranch := fs.Bool("b", false, "Create new branch (use with --worktree)")
387387
newBranchLong := fs.Bool("new-branch", false, "Create new branch")
388+
noWorktree := fs.Bool("no-worktree", false, "Skip automatic worktree creation")
389+
noWorktreeShort := fs.Bool("no-wt", false, "Skip automatic worktree creation (short)")
388390

389391
sandbox := fs.Bool("sandbox", false, "Run forked session in Docker sandbox")
390392
sandboxImage := fs.String("sandbox-image", "", "Docker image for sandbox (overrides config default)")
@@ -475,8 +477,8 @@ func handleSessionFork(profile string, args []string) {
475477
}
476478
createNewBranch := *newBranch || *newBranchLong
477479

478-
// Auto-create worktree if configured or requested via CLI flag
479-
if wtBranch == "" {
480+
// Auto-create worktree if configured and not explicitly skipped
481+
if wtBranch == "" && !*noWorktree && !*noWorktreeShort {
480482
wtSettings := session.GetWorktreeSettings()
481483
if wtSettings.AutoCreate && git.IsGitRepo(inst.ProjectPath) {
482484
wtBranch = wtSettings.Prefix() + git.SanitizeBranchName(forkTitle)
@@ -497,10 +499,15 @@ func handleSessionFork(profile string, args []string) {
497499
os.Exit(1)
498500
}
499501

500-
if !createNewBranch && !git.BranchExists(repoRoot, wtBranch) {
502+
branchExists := git.BranchExists(repoRoot, wtBranch)
503+
if !createNewBranch && !branchExists {
501504
out.Error(fmt.Sprintf("branch '%s' does not exist (use -b to create)", wtBranch), ErrCodeInvalidOperation)
502505
os.Exit(1)
503506
}
507+
if createNewBranch && branchExists {
508+
out.Error(fmt.Sprintf("branch '%s' already exists (remove -b flag to use existing branch)", wtBranch), ErrCodeInvalidOperation)
509+
os.Exit(1)
510+
}
504511

505512
wtSettings := session.GetWorktreeSettings()
506513
worktreePath := git.WorktreePath(git.WorktreePathOptions{

internal/ui/newdialog.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ func (d *NewDialog) ShowInGroup(groupPath, groupName, defaultPath string) {
250250
d.inheritedSettings = buildInheritedSettings(userConfig.Docker)
251251
d.branchPrefix = userConfig.Worktree.Prefix()
252252
if userConfig.Worktree.AutoCreate {
253-
d.worktreeEnabled = true
253+
// Only auto-enable worktree if the resolved path is a git repo
254+
pathValue := d.pathInput.Value()
255+
if pathValue != "" && git.IsGitRepo(pathValue) {
256+
d.worktreeEnabled = true
257+
d.branchAutoSet = true
258+
}
254259
}
255260
}
256261
d.branchInput.Placeholder = d.branchPrefix + "branch-name"

0 commit comments

Comments
 (0)