Skip to content

fix: Recover from deleted cwd #1168

@davidbeesley

Description

@davidbeesley

Follow up on #1109 #1146

I think #1146 has a bug where it won't work if there are multiple git repos in the parent dir (in my case ~/git).

Since wt has a good guess for the main repo location from its own configuration worktree-path, I think wt could try that route before giving up.

Also the UX is a bit off, I think it should only recommend wt switch ^ if it's resolvable.

[dave@scgtaranaki] [02/22/26 17:03:56.590] [🐏  84%] [~/git/accounting-rs.data] []
❯ wt switch                                                            
✗ fatal: Unable to read current working directory: No such file or directory                                                                  
↳ Current directory was removed. Try: wt switch ^

[dave@scgtaranaki] [02/22/26 17:03:59.867] [🐏  84%] [~/git/accounting-rs.data] []
❯ wt switch ^                                                          
✗ Failed to switch worktree                                            
  fatal: Unable to read current working directory: No such file or directory
↳ Current directory was removed. Try: wt switch ^

[dave@scgtaranaki] [02/22/26 17:04:05.106] [🐏  84%] [~/git/accounting-rs.data] []
❯ wt switch main
✗ Failed to switch worktree
  fatal: Unable to read current working directory: No such file or directory
↳ Current directory was removed. Try: wt switch ^

I had CC take a regex approach to reverse engineer using worktree-path with a fair amount of success for minimal effort if that route has any interest to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions