Repository navigation
Fix #19: support --summary in show, log and diff - #21
Merged
Merged
Conversation
git log --graph --format=<fmt> --stat (or any other diff output) put the diff right under the formatted line. Real git separates them with a padded blank line, the same as without --graph and the same as the medium format already did here. Only --oneline skips it.
--summary prints git's create, delete, rename and mode-change lines. show and log print them under each commit and skip merges in log, as git does. They follow --stat, --shortstat and --numstat, come before a -p patch with a blank line between, and replace the patch when no other diff format is given. --name-only and --name-status drop them, and so does show --no-patch. A commit with changes but no summary lines still gets the blank line after its message. The lines come from one formatter in commit-summary.ts, formatSummaryLines, which commit and merge now use as well. That fixes two things they got wrong: a mode change printed as a delete plus a create instead of "mode change 100644 => 100755 <path>", and a rename that also changed the mode left out the pathless mode line. Paths are C-quoted the way git quotes them, and a rename with a quoted side prints both sides in full.
git show on a merge prints its patch as a combined diff, but --stat, --shortstat, --numstat and --summary compare the merge with its first parent. just-git printed nothing for those formats on a merge, so show --summary <merge> missed the files the merge brought in. The name formats still print nothing here, as before.
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.
Fixes #19
Summary
git show,git logandgit diffnow accept--summary. Before this change all three rejected it withUnknown option "--summary". The summary lists the files a change created, deleted, renamed or changed mode on, which is often all an agent needs from a commit.Supported surface:
The lines match git 2.34.1 byte for byte:
Ordering follows git:
--summaryon its own replaces the patch.--stat,--shortstator--numstatit prints right after their output.-pit prints before the patch, with a blank line between them.--name-onlyand--name-statusdrop it, and so doesshow --no-patch.logprints nothing for merges, since it doesn't diff them by default.git log --summaryshows two blank lines after such a commit in medium format.Before and after
How it works
formatSummaryLinesinsrc/lib/commit-summary.tsis the only formatter for these lines.commit,merge,show,loganddiffall call it.computeDiffStatsused to build the create/delete lines forcommitandmergeas a side output. It now returns only the file stats, and the summary lines come from the new function.Sharing the formatter changes the output of
commitandmergein three cases, and in each case the new output is what git prints:create mode 100755 nplusdelete mode 100644 n. It now printsmode change 100644 => 100755 n.mode changeline under the rename.quote_c_stylequotes them. If either side of a rename needs quoting, both sides print in full ("a" => "b") without the{a => b}form, as git'spprint_renamedoes.In
showandlogthe diff options now resolve to a main format plus a summary flag, andwithSummaryputs the two in git's order.log'sformatCommitDiffreturnsnullwhen it shows nothing at all (no diff option, a merge, an empty diff) and""when the commit has changes but the output is empty. The difference is the blank line described above.diffmaps its items to the same inputs and appends the summary.The PR has two more commits, split out so they are easy to review or drop:
log --graph --format=<fmt>blank line. With--graphand a custom format, the diff output came right under the formatted line. Git puts a padded blank line there, the same as without--graph. Only--onelineskips it. This showed up as soon as I comparedlog --graph --format=%s --summarywith git, and--stathad the same bug.showon a merge. Git shows a merge's patch as a combined diff, but--stat,--shortstat,--numstatand--summarycompare the merge with its first parent. just-git printed nothing for those formats on a merge, with a comment saying that matched git. It doesn't in 2.34.1, soshow --summary <merge>would have printed nothing where git lists the merged-in files. Both now use the first parent. The name formats still print nothing on a merge.Tests
test/commands/show.test.tshas 11 new tests: summary alone, after--stat/--shortstat/--numstat, before-p, symlinks and quoted names,dir/sub/{a => b}, a type change, the blank line on a content-only commit, dropped by the name formats and--no-patch, through an annotated tag, and merges against the first parent.log.test.tshas 6,diff.test.tshas 6 (two commits,--cached, unstaged deletions, stat formats) andcommit.test.tshas 1 for the mode-change lines. They share a history builder,setupSummaryHistoryintest/util.ts.test/interop/summary.test.tsbuilds a repo with real git, including an executable delete, a 70% rename that also gets+x, a symlink, a gitlink, a type change, names with a space, a quote, a tab andé, and a merge on its own branch. It runs 39 invocations ofshow,loganddiffthrough both and asserts identical stdout, stderr and exit code. I checked that it catches defects. Turning off path quoting failed 9 cases, and dropping the pathless mode line under renames failed 14.test/graph/scenarios/16-graph-with-summary.tscompareslog --graph --summarywith real git in medium,--oneline,--formatand--statforms. Scenario 09 gets two--graph --formatcases for the blank-line fix.bun test: 3576 pass, 29 skip, 0 fail. Onorigin/main(b509001) it was 3512 pass, 29 skip, 0 fail, with local git 2.34.1.bun checkis clean, andbun gen-docsupdateddocs/CLI.mdanddocs/FILE_REFERENCE.md.Not included
These are gaps I hit while comparing with git. None of them come from
--summary, and--stator--name-statusalready show them on main:git diff <commit>(commit against worktree) andgit diff HEADdon't run rename detection, so a staged rename shows as a delete plus a create.--name-statusdoes the same today.git diffandgit diff --cacheddon't see mode-only changes in the worktree or index. Fix #10: checkout sets the executable bit, and status/diff report mode changes #15 fixes that indiff.ts, and the summary lines will show them once it lands.-qwith--summaryprints the summary, the same way just-git already handles-q --stat. Git 2.34.1 prints nothing for both. I left this alone because just-git's-qhandling follows newer git.--stat,--numstatand-pfail on a commit that adds or removes a gitlink, because they try to read the submodule commit as a blob.--summaryalone works (create mode 160000 gm).-ppart ofshow -p --summary/log -p --summaryinherits the existing patch gaps: noold mode/new modelines, and combined diffs drop the hunk for a file both parents lack. The summary part matches.show --name-statuson a merge prints nothing where git prints combined status (MM f).--compact-summaryisn't supported, andshow -p --statstill prints only the stat.