Exit cleanly when worktree/repository is removed while lazygit is running#5355
Exit cleanly when worktree/repository is removed while lazygit is running#5355ruudk wants to merge 1 commit intojesseduffield:masterfrom
Conversation
…ning
When a worktree or repository is removed while lazygit is running,
git commands fail with "fatal: not a git repository" or
"fatal: Unable to read current working directory". Previously this
caused a panic in BranchLoader.obtainBranches, crashing lazygit with
a stack trace.
Changes:
- BranchLoader.obtainBranches: return error instead of panic(err)
- RefreshHelper.refreshBranches: wrap the error in ErrFatal and send
it to the UI thread, causing the program to exit
- PopupHandler.ErrorHandler: let ErrFatal bypass the popup handler
so the error propagates to the main loop and triggers a clean exit
- Add ErrFatal type to gui/types for errors that should terminate
the program immediately
- Add "fatal: Unable to read current working directory" to the known
error mappings so it prints a friendly message on exit
Manual testing:
Terminal 1:
cd "$(mktemp -d)" && mkdir test-repo && cd test-repo
git init && git commit --allow-empty -m "init"
git worktree add ../test-wt && cd ../test-wt
go build -o lazygit . && ./lazygit # (or path to built binary)
Terminal 2:
rm -rf /path/to/test-wt /path/to/test-repo
Then press R in lazygit to refresh. It should exit with:
"Error: the current working directory does not exist"
|
I ran into this as well. I was running lazygit inside a Claude Code worktree that got cleaned up when the session ended, which triggered the same panic in I took a different approach: instead of exiting, I detect the missing CWD at the top of One thing worth noting: on macOS, PR with code and integration test: #5367 |
That's also a possibility. But in that case, I think you should add a prompt that informs the user that this happened. |
PR Description
Please check if the PR fulfills these requirements
go generate ./...)When a worktree or repository is removed while lazygit is running, git commands fail with "fatal: not a git repository" or "fatal: Unable to read current working directory". Previously this caused a panic in BranchLoader.obtainBranches, crashing lazygit with a stack trace.
Changes:
Manual testing:
Terminal 1: cd "$(mktemp -d)" && mkdir test-repo && cd test-repo git init && git commit --allow-empty -m "init" git worktree add ../test-wt && cd ../test-wt
go build -o lazygit . && ./lazygit # (or path to built binary)
Terminal 2: rm -rf /path/to/test-wt /path/to/test-repo
Then press R in lazygit to refresh. It should exit with: "Error: the current working directory does not exist"