fix(status): detect committed source changes with a clean working tree - #1540
Open
WhoJay0609 wants to merge 1 commit into
Open
fix(status): detect committed source changes with a clean working tree#1540WhoJay0609 wants to merge 1 commit into
WhoJay0609 wants to merge 1 commit into
Conversation
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.
Problem
codegraph statususedgit status --porcelainto detect pending source changes. That catches uncommitted edits, but it misses changes already committed or introduced by a pull, merge, rebase, or branch checkout.Once the working tree is clean,
statuscan report that the index is up to date even though the source tree no longer matches the stored index.Reproduction
This reproduces on CodeGraph 1.5.0:
Before this patch, the status output contains:
{"pendingChanges":{"added":0,"modified":0,"removed":0}}The query does not return
newly_committed_symbol. Runningcodegraph syncdetects one added file, and the query succeeds afterward.With this patch,
statusstays read-only and reports:{"pendingChanges":{"added":1,"modified":0,"removed":0}}Fix
statusandsyncpreviously used different freshness checks.getChangedFiles(), which supplies the status counts, readgit status.sync()compared the current source tree with the file records stored in the index.getChangedFiles()now scans the current indexable files and compares them with the stored records. It uses the existing scanner, so ignore rules, explicit includes, custom extensions, and embedded repositories follow the same visibility rules as indexing and sync. For tracked files, size and mtime filter out unchanged files before content hashing.Removal detection also checks whether an indexed path still exists on disk. This matters because
git ls-filescan list a tracked file after it has been deleted but before the deletion is staged.The separate
git statusdetector is removed. Files that are untracked by Git but already indexed by CodeGraph are still compared with their stored records, so unchanged files are not reported as new on every status call.This change does not alter the database schema, public API, or JSON field names. It does not require a full re-index.
Performance
I measured the complete
status --jsoncommand on one of our own repositories. CodeGraph saw 1,812 source files with 909,802 physical lines. The benchmark disabled the daemon, ran three warmups, then alternated the baseline and patched commands for 20 measured runs.The filesystem scan adds about 260 ms on this repository. Files whose size and mtime still match the index are not read or hashed.
The patched run also reported one 2.39 MB generated source file as pending, so each run read and hashed that file. The measured difference is therefore a conservative estimate of the scan-only cost.
Tests
The new tests cover committed additions, modifications, and deletions with a clean working tree. An end-to-end test checks the
status --jsonpending-change count.The focused run passes all 41 tests, including all 35 tests in
sync.test.ts.A full
npm testrun on Linux reported 2,891 passing, 178 skipped, and 12 failing tests. The failures are in Git-hook andincludeIgnoredor nested-repository test files outside this diff. I have not treated the full run as green or claimed that those failures reproduce on the base branch.