Add test for Git editor swap cleanup and improve swap file handling

- Added `test_swap_git_editor.cc` to verify proper swap file cleanup during Git editor workflows. Ensures no stale swap files are left after editor closure.
- Updated swap handling logic in `Editor.cc` to always remove swap files on buffer closure during normal exit, preventing accumulation of leftover files.
- Bumped version to 1.6.5 in `CMakeLists.txt`.
This commit is contained in:
2026-02-17 13:10:01 -08:00
parent 199d7a20f7
commit 95a588b0df
3 changed files with 100 additions and 4 deletions

View File

@@ -486,9 +486,10 @@ Editor::CloseBuffer(std::size_t index)
return false;
}
if (swap_) {
// If the buffer is clean, remove its swap file when closing.
// (Crash recovery is unaffected: on crash, close paths are not executed.)
swap_->Detach(&buffers_[index], !buffers_[index].Dirty());
// Always remove swap file when closing a buffer on normal exit.
// Swap files are for crash recovery; on clean close, we don't need them.
// This prevents stale swap files from accumulating (e.g., when used as git editor).
swap_->Detach(&buffers_[index], true);
buffers_[index].SetSwapRecorder(nullptr);
}
buffers_.erase(buffers_.begin() + static_cast<std::ptrdiff_t>(index));