Skip to content

feat(core): analyze a git commit/tree-ish directly via --git-hash - #36

Merged
coldhighsun merged 1 commit into
mainfrom
feat/git-hash-analysis
Jul 27, 2026
Merged

feat(core): analyze a git commit/tree-ish directly via --git-hash#36
coldhighsun merged 1 commit into
mainfrom
feat/git-hash-analysis

Conversation

@coldhighsun

Copy link
Copy Markdown
Owner

Summary

  • Add GitSnapshotExtractor (src/Sloc.Core/GitSnapshotExtractor.cs), which shells out to git (ls-tree -r -z, cat-file --batch) to dump every tracked blob of a commit/tree-ish into a temp directory, without checking it out. Symlink and submodule tree entries are skipped and reported.
  • Add --git-hash <commit> CLI option (mutually exclusive with --list-file); path is used as the repo root to query.
  • AnalyzeHandler scans the extracted temp files via the existing --list-file code path (DirectoryScanner.ScanFiles), then remaps reported paths from temp paths back to git-relative paths before rendering/--baseline/--unique, and cleans up the temp directory in a finally.
  • Document the new flag and its limitations in CLAUDE.md.

Test plan

  • dotnet build Sloc.slnx — 0 warnings, 0 errors.
  • dotnet test Sloc.slnx — 295/295 passing, including new tests:
    • tests/Sloc.Core.Tests/GitSnapshotExtractorTests.cs — HEAD extraction matches working tree, older-commit extraction reflects historical state, symlink entries are skipped, binary content is dumped byte-for-byte, invalid hash / non-repo path throw GitSnapshotException.
    • tests/Sloc.Cli.Tests/AnalyzeHandlerGitHashTests.cs--git-hash HEAD reports git-relative paths and matches a normal scan's totals; invalid hash returns ExitCode.Error; temp directory is cleaned up after Execute returns.
  • Manually ran sloc . --git-hash HEAD -f json against this repo and confirmed output paths are git-relative and uncommitted files are correctly excluded.

Adds GitSnapshotExtractor, which shells out to git (ls-tree, cat-file
--batch) to dump a commit's tracked blobs into a temp directory without
checking it out. AnalyzeHandler scans the dump like --list-file and
remaps reported paths back to git-relative paths before rendering.
Symlink and submodule tree entries are skipped and reported.
@coldhighsun
coldhighsun merged commit 1eca4d9 into main Jul 27, 2026
5 checks passed
@coldhighsun
coldhighsun deleted the feat/git-hash-analysis branch July 27, 2026 05:57
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