lore: Discard reverted uncommitted directory adds on scan#104
Open
lehuan5062 wants to merge 5 commits into
Open
lore: Discard reverted uncommitted directory adds on scan#104lehuan5062 wants to merge 5 commits into
lehuan5062 wants to merge 5 commits into
Conversation
A working-tree scan (`status --scan` / `stage --scan`) already discards a reverted uncommitted *file* add so `state_staged` matches the filesystem: a file that was staged and then removed before any commit has no committed base to delete from, so reporting a `Delete` would leave an unremovable "zombie" entry. A reverted uncommitted *directory* add was not handled the same way. Extend the same treatment to directories. When a directory node exists in `state_from` but neither in `state_current` (never committed) nor on disk, queue it for discard instead of emitting a meaningless `Delete`. Discarding a directory node must also reclaim its subtree: `apply_pending_discards` now recursively discards every child below a directory node before unlinking the node itself, so no stale descendant slots are left behind. Includes a Rust test covering the index-then-remove cycle for a directory add, asserting the node is discarded (and does not resurface on a later scan) rather than reported as a delete. Signed-off-by: Huân Lê-Vương <65440815+lehuan5062@users.noreply.github.com>
9facad1 to
7befc87
Compare
mjansson
reviewed
Jul 10, 2026
Collaborator
|
Could you also add a smoke test for it in some appropriate file in |
- Condense verbose comment in state.rs explaining reverted uncommitted directory handling to a single sentence - Add smoke test to verify directory discard behavior with JSON output validation (no stray deletes, no duplicates, concurrent changes properly reported) Signed-off-by: Huân Lê-Vương <65440815+lehuan5062@users.noreply.github.com>
…path The smoke test previously called status() without --scan, so the filesystem-diff walk containing the discard logic never ran, and it filtered results to type == "file", hiding the directory-node entries where a regression would actually surface. Verified by disabling the discard logic and confirming the old test still passed; it now fails as expected. The fix drives status(scan=True) and checks a follow-up call (since the scan that performs the discard reports its own stale pre-discard snapshot) with no type filter. Signed-off-by: Huân Lê-Vương <65440815+lehuan5062@users.noreply.github.com>
Local mid-function import didn't match the file's existing convention of importing at module scope. Signed-off-by: Huân Lê-Vương <65440815+lehuan5062@users.noreply.github.com>
Per Lore's comment standards, remove comments that only restate what the adjacent code already says; keep the ones explaining non-obvious behavior (the revert simulation, the two-scan reconciliation quirk, and why no type filter is applied). Signed-off-by: Huân Lê-Vương <65440815+lehuan5062@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A working-tree scan (
status --scan/stage --scan) already discards a reverted uncommitted file add sostate_stagedmatches the filesystem: a file that was staged and then removed before any commit has no committed base to delete from, so reporting aDeletewould leave an unremovable "zombie" entry. A reverted uncommitted directory add was not handled the same way.Extend the same treatment to directories. When a directory node exists in
state_frombut neither instate_current(never committed) nor on disk, queue it for discard instead of emitting a meaninglessDelete.Discarding a directory node must also reclaim its subtree:
apply_pending_discardsnow recursively discards every child below a directory node before unlinking the node itself, so no stale descendant slots are left behind.Includes a Rust test covering the index-then-remove cycle for a directory add, asserting the node is discarded (and does not resurface on a later scan) rather than reported as a delete.