committia.vim icon indicating copy to clipboard operation
committia.vim copied to clipboard

Improve support for amending git commits

Open mmrwoods opened this issue 4 months ago • 1 comments

This really a feature suggestion supplied with working code. There are a few niggles when amending git commits which in the past put me off using committia, which I've tried to address here...

When amending a commit there was no way to explicitly tell committia to show the full diff of all changes introduced by the commit, it would show you either the new changes, if there were any (i.e. git diff showed some changes), or, if the verbose option was provided to git commit, fall back to showing the full diff extracted from the commit message template, otherwise do nothing. When falling back to showing the full diff extracted from the commit message template, the status would not match the diff, with the diff showing changes, but status showing no changes.

This PR introduces a new opt-in feature to always extract status and diff from the commit message template when the verbose option is enabled for git commit, e.g. git commit --verbose or git config --global commit.verbose=true. This allows users to choose to see only the new changes when amending commits, e.g. git commit --amend -a, or show all changes, e.g. git commit --amend -av.

I find this really useful as I often want to see the entire diff when amending a commit and updating the message.

I've also added an, admittedly fugly, hack to fix the fall back issue with the status not matching the diff, and updated the regex to find the diff start line in the commit message template to allow for non-default git config core.commentChar, e.g. ;

Let me know what you think, I can supply some screenshots explaining in more detail if I've not made myself clear above.

mmrwoods avatar Sep 30 '24 15:09 mmrwoods