Skip to content

fix: reflog N+1 queries, hard reset false positives, broken test script#4

Open
sulthonzh wants to merge 1 commit into
mainfrom
fix/round4-bugs-reflog-performance-hard-reset-false-positive
Open

fix: reflog N+1 queries, hard reset false positives, broken test script#4
sulthonzh wants to merge 1 commit into
mainfrom
fix/round4-bugs-reflog-performance-hard-reset-false-positive

Conversation

@sulthonzh

Copy link
Copy Markdown
Owner

Round 4 fixes:

1. Reflog N+1 query problem (performance)
ReflogParser.getReflog() was spawning a separate git log -1 process for every reflog entry to get timestamps. With limit=30, that's 30+ git process spawns for a single call. Fixed by using git reflog --format='%H %ct %gs' to get timestamps inline in one call.

2. Hard reset false positive (correctness)
HardResetDetector detected ALL resets as hard resets. The logic excluded --soft and --mixed literal strings, but git reset HEAD~1 (the default mixed mode) doesn't write --mixed in the reflog message. Every normal git reset was being flagged as a hard reset. Fixed by using git diff-index --quiet HEAD to check if the working tree was actually nuked.

3. Wrong pre-reset commit in hard reset recovery (correctness)
HardResetDetector used getPreviousState(1) which returns HEAD@{1} relative to current HEAD — not relative to when the reset happened. If there were other operations after the reset, this would point to the wrong commit. Now uses the reflog entry at index+1 for the actual pre-reset state.

4. Broken test script
Test command referenced dist/tests/**/*.test.js but test files are at dist/*.test.js. The glob matched nothing, so tests never actually ran via npm test. Fixed the glob.

5. Build artifacts leaking to git
Updated .gitignore to prevent .js, .d.ts, .js.map, .d.ts.map files from being tracked in src/ and tests/ directories.

- ReflogParser.getReflog() spawned a git process per entry to fetch
  timestamps (N+1 queries — 30+ git calls for limit=30). Now uses
  'git reflog --format=%H\ %ct\ %gs' to get timestamps inline in
  a single call.

- HardResetDetector falsely detected ALL resets (soft, mixed) as hard
  resets. It only excluded literal --soft/--mixed strings in the reflog
  message, but 'git reset HEAD~1' (mixed, default) doesn't include
  --mixed in the message. Fixed by checking diff-index to verify the
  working tree was actually nuked.

- HardResetDetector used getPreviousState(1) which returns HEAD@{1}
  relative to current HEAD, not relative to the reset event. Now uses
  the reflog entry at index+1 for the correct pre-reset commit.

- Test script referenced 'dist/tests/**/*.test.js' but test files
  compile to 'dist/*.test.js'. Fixed glob pattern.

- Updated .gitignore to prevent build artifacts (*.js, *.d.ts, etc.)
  from leaking into the src/ and tests/ directories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant