Skip to content

wt new: bare-repo main worktree misclassified as pr_worktree scenario in non-interactive mode #21

Description

@chrissena

Summary

In a bare-repo + linked-worktrees layout (.bare/ + main/ + pr/prNNNN.slug/), running wt new from the main worktree in non-interactive mode fails with:

Cannot create PR from a PR worktree in non-interactive mode. Switch to the main worktree first.

— even though the current worktree is the main worktree, and wt list itself identifies it correctly ([main] * … Path main (current)).

Environment

  • @camaradesuk/git-worktree-tools 1.14.0 (pnpm global install; incidentally wt --version prints unknown)
  • Repo layout: /home/chris/workspace/syrf/.bare (bare) with linked worktrees main/ (branch main) and pr/prNNNN.slug/
  • .worktreerc: worktreeParent: ".worktrees", worktreePattern: "pr{number}.{slug}"
  • Working tree had unstaged changes (2 untracked paths + 1 modified file) at the time

Repro

cd /home/chris/workspace/syrf/main   # linked worktree, branch = main
wt new "Some new work" --ready --non-interactive --action=empty_commit --json

Result:

{"success": false, "error": {"code": "INVALID_ARGUMENT",
 "message": "Cannot create PR from a PR worktree in non-interactive mode. Switch to the main worktree first."}}

--verbose shows the state analysis contradicting itself — scenario is pr_worktree while branchType/currentBranch are main:

[DEBUG] State analysis complete {"scenario":"pr_worktree","branchType":"main","currentBranch":"main",
 "commitRelationship":"same","workingTreeStatus":"unstaged_only","stagedFiles":[],
 "unstagedFiles":[".generated-checksums.json",".claude/skills/promote-staging-to-production/",
 "src/libs/project-management/SyRF.ProjectManagement.Core.Tests/PartitionAsyncDeadlockRepro.cs"],
 "repoRoot":"/home/chris/workspace/syrf/main"}
[ERROR] Cannot create PR from a PR worktree in non-interactive mode. Switch to the main worktree first.

Meanwhile wt list from the same directory is correct:

main worktrees:
  [main] *
    Branch  main
    Path    main (current)

Hypothesis

Scenario detection appears to treat any linked worktree as a PR worktree. In a bare-repo layout every checkout is a linked worktree (there is no non-linked primary checkout), so the main worktree gets classified pr_worktree. wt list evidently uses different (correct) logic — probably branch/config based.

Suggested direction: derive "main worktree"-ness the way wt list does (current branch == default branch, or an explicitly configured main-worktree path) rather than from worktree linkage; at minimum, trust branchType: "main" over the linkage heuristic in wt new's guard.

Impact / workaround

wt new is unusable non-interactively in bare-repo layouts (the recommended layout for this repo family). Workaround used: manual git worktree add + gh pr create + git worktree move to the pr{number}.{slug} convention.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions