From 811bb712b4ab38bb5e5d8882b8b1f21a82b53a7e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 1 Apr 2026 13:20:16 -0400 Subject: [PATCH] Fix off-by-one in FakeGitRepository::reset truncation The truncate(target_index + 1) call was a no-op when pop_count == 1 because target_index was len-1, so truncate(len) kept all elements. This meant subsequent resets kept returning the same commit. Fix: read the snapshot at target_index first, then truncate to target_index (removing the consumed entry). --- crates/fs/src/fake_git_repo.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/fs/src/fake_git_repo.rs b/crates/fs/src/fake_git_repo.rs index 589a6606b0087f2e27779f5bcf76b53ce8e5e3bf..d53d75cdfa13ca48acc34c07b4afd48f5cafc50d 100644 --- a/crates/fs/src/fake_git_repo.rs +++ b/crates/fs/src/fake_git_repo.rs @@ -255,12 +255,8 @@ impl GitRepository for FakeGitRepository { } let target_index = state.commit_history.len() - pop_count; - state.commit_history.truncate(target_index + 1); - let snapshot = state - .commit_history - .last() - .expect("pop_count validated above") - .clone(); + let snapshot = state.commit_history[target_index].clone(); + state.commit_history.truncate(target_index); match mode { ResetMode::Soft => {