Skip to content

Skip .git, .svn, .hg and .bzr directories when scanning [patch] - #194

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/192-skip-vcs-metadata
Oct 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/192-skip-vcs-metadata

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #192

What changes

Inside .git, every branch ref that points at the same commit has identical content, and so do the reflogs of branches created together. FileScanner.ScanForFiles walked into .git like any other folder. Deduplicate then grouped those files as duplicates and deleted all but one, which deleted branches and their reflogs in every repository under the root.

  • FileScanner now walks with a FileSystemEnumerable whose ShouldRecursePredicate prunes directories named .git, .svn, .hg or .bzr. The name match ignores case, and the walk keeps the same WalkOptions. This is a directory filter on the enumeration, not a substring match on paths: a .git file (a worktree or submodule pointer), .github/ and mirror.git/ are still scanned.
  • The README states the exclusion next to the empty-file rule.

Tests

The new VersionControlMetadataTests:

  • The scan skips each of the four metadata directories (plus a .GIT spelling) and keeps the file outside them.
  • Look-alike names are still scanned: a .git file, .github/, mirror.git/ and .gitignore.
  • Deduplicate (confirmed with y) deletes the real duplicate outside .git and leaves every ref and reflog in place.
  • Scan and DryRun report the real duplicate and nothing inside .git.

With the scanner change reverted, 7 of the 8 fail. The look-alike guard passes either way, which is intended. Full suite: 114 passed, 3 skipped (the same 3 are skipped on main), 0 failed.

The same bug is open in KtsuTools as ktsu-dev/KtsuTools#222. It isn't touched here.


Generated by Claude Code

Inside .git, every branch ref pointing at the same commit has identical
content, as do the reflogs of branches created together. The scan walked
into .git like any other folder, so Deduplicate grouped those files as
duplicates and deleted all but one, deleting branches and their reflogs in
every repository under the root.

The walk now prunes version-control metadata directories by name, so their
contents are never scanned, reported or deleted. A .git file (a worktree or
submodule pointer) and directories such as .github are still scanned. The
README notes the exclusion next to the empty-file rule.

Fixes #192

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW34mg5yez39UfTV7yf
@sonarqubecloud

Copy link
Copy Markdown

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.

Deduplicate deletes git branch refs and reflogs because .git folders under the root are scanned as ordinary files

2 participants