Add command that runs code style checks per commit on a topic branch!
I think this could be useful for identifying the exact commit where code style violations have been introduced, instead of just running code style checks on an entire branch.
If we could iterate through each commit on a branch, run any code style checks per commit (on only the changed files in the commit), and then once all commits have been checked - display the results in a overall table.
Future ideas (run fixer tools on each commit and automate fixup commits)
If we really wanted to, we could give this command extra ammunition when used locally, by being able to run vendor/bin/phpcbf
, php-cs-fixer
or eslint --fix
(i.e the fix mode versions of each tool) - on each commit. How I see this working would be to iterate through the commits using git checkout {$HASH}
, then run whatever fixers we need to and store any patch changes to our command process, then proceed to the next commit without making any change to the current commit. Once we have iterate through all commits, we would then loop through the appropriate patchs and automatically create fixup
commits which would be assigned to the relevant commits where we have found changes can be applied to. Using fixup
is the recommended way of adding changes which can be later merged into an original commit, later.
The reason for using fixup
commits instead of something else is for 2 reasons:
- Using
git checkout HASH
, creates a detached HEAD state (experimental mode), meaning you can't really make changes to the current commit you checkout anyways, without creating a new branch. - We won't be altering original commits, which would keep things safe for the user - so that they can review the changes which would be automatically applied. Once the user is happy their fixup commits do what they should, they can run
git rebase -i master --autosquash
.
However, there is potential for a merge conflict to occur during autosquash process, so the end user will have to resolve these to the best of their ability. So, users will have to be made aware of this.