Render how a commit changes the project’s files
To provide the reader with ample context, render each commits’ file changes alongside their commit messages.
Descendants will split the remaining page width amongst themselves.
In the case of the project root, the diff will be omitted, and the
commit message will span the width of the page (by virtue of it being
the :only-child
to the .container
.
for project root
When a file’s diff is longer than 100 lines, render the <details>
element as collapsed by default. To do so, omit the open
attribute.
Likewise, when a commit’s subject starts with [GENERATED]
, don’t
render the <details>
element with an open
attribute.
Determining the diff contents
When a commit has a parent, generating the diff with the ruby-git
provided interface is straightforward:
diff = parent.diff(commit)
However, when the commit is the project’s root, it has no parent, and cannot be “diffed”.
To counteract this restriction, this commit invokes a git
show
command for each file included in the commit, passing
the --cc
combined diff flag. The --cc
flag will ensure
that the output contains the code diff. In order to separate out the
code from the prose, pass the command a --format=%n
flag which includes the %n
as a “newline” placeholder,
intended to serve as an omission of the prose.
The padding \n
character is subsequently omitted by the trailing
Ruby-side call to String#strip
.
The net result is that the contents of the diff include the changes to the code, and do not include the prose in the commit’s message.
Test Coverage
To ensure that this new behavior is covered, this commit includes corresponding System Tests.
To enable direct navigation to a commit, modify the existing commit
test helper to return the new commit object, so that the test can pass
it directly to the commit_path
helper.