Skip to content

feat: inspect commit history with git tree <commit> [<commit>]#18

Open
wteuber wants to merge 1 commit into
masterfrom
feat/git-tree-commit-args
Open

feat: inspect commit history with git tree <commit> [<commit>]#18
wteuber wants to merge 1 commit into
masterfrom
feat/git-tree-commit-args

Conversation

@wteuber

@wteuber wteuber commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds two history-inspection modes that reuse the existing Node / NodesCollection tree renderer verbatim. git tree with no args is unchanged.

Invocation Meaning
git tree Working-tree status (unchanged)
git tree <commit> Files changed in <commit> (vs. its first parent)
git tree <c1> <c2> Files that differ between the two commits
git tree <c1>..<c2> Same as above, as a single range token

<commit> is any revision git accepts (SHA, HEAD, HEAD~3, branch, tag).

How it works

git diff-tree --name-status -z output is translated into the porcelain entry strings the node pipeline already understands, so everything downstream is reused. Commit-mode entries render in a distinct cyan color (separate from the green=staged / red=dirty working-tree palette) with the git status letter (A/M/D/R/T); -M rename detection shows old -> new (R).

  • Root commits (no parent) list every file as added (--root).
  • An empty diff prints (no changes).
  • Invalid revisions and the unsupported symmetric-difference A...B range fail with a clear error and non-zero exit; 3+ positional args are rejected with usage.
  • -i/--indent and -c/--collapse apply in all modes; -u/--untracked-files is ignored for commit views.

Tests

  • New integration tests: test_command_line_commit.rb, test_command_line_commit_range.rb (A/M/D, renames across dirs, root commit, no-changes, invalid rev, range token, reversed order, options in range mode).
  • New unit test: test/git_status_tree/test_parse_diff_tree.rb (the -z token walk: regular entries, rename/copy triplets, similarity-score stripping, empty stream, multibyte paths).
  • Added commit-mode cases to test_git_status_tree_class.rb, plus a teardown that resets Node's class-level state (indent/collapse_dirs/mode) so the suite is order-independent.
  • ruby test/coverage.rb (the CI path): 199 runs, 0 failures, 100.00% library coverage. Verified on Ruby 2.6 (support floor) and 4.0.4.

Notes

  • No version bump — changelog entry is under [Unreleased]; VERSION stays 3.6.0.
  • Includes a Gemfile.lock bump (json/prism/unicode-emoji) to versions whose required_ruby_version allows Ruby 4.0 — the previously locked unicode-emoji 4.0.4 forbids Ruby 4.0 (the pinned .ruby-version), breaking bundle on 4.0.x. RuboCop stays pinned at 1.77.0 to match CI. Happy to split this out if you'd prefer the PR to be feature-only.
  • Design doc included at docs/specs/git-tree-commit-args.md (tracking issue git tree [<commit>] [<commit>] #6).

Add two history-inspection modes that reuse the existing tree renderer:

  git tree <commit>      files changed in <commit> (vs. its first parent)
  git tree <c1> <c2>     files that differ between two commits
  git tree <c1>..<c2>    same, as a single range token

diff-tree -z output is translated into the porcelain entry strings the
Node pipeline already understands. Commit-mode entries render in a distinct
cyan color (separate from the green=staged / red=dirty working-tree palette)
with the git status letter; -M rename detection shows `old -> new (R)`.
Root commits list every file as added; an empty diff prints `(no changes)`.
Invalid revisions and the unsupported `A...B` range fail with a clear error.

The -i/--indent and -c/--collapse options apply in all modes; -u is ignored
for commit views. No version bump yet (changelog entry under [Unreleased]).

Also bumps json/prism/unicode-emoji in Gemfile.lock to versions whose
required_ruby_version allows Ruby 4.0 (the pinned .ruby-version), keeping
RuboCop at 1.77.0 to match CI.

Spec: docs/specs/git-tree-commit-args.md (tracking issue #6)
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