Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for amending git commits (#67)
* Optional improved support for amending git commits Add opt-in feature to allow the diff and status to be extracted from the commit message template if the verbose option is used with git commit, e.g. git commit --verbose or git config --global commit.verbose=true When amending commits, this allows the author of the commit message to see all of the changes, in both the status and diff windows, if they enabled the verbose option for git commit. Without the verbose option, the behaviour is as before, show only new changes, if there are any. Enable in your vimrc with: let g:committia#git#use_verbose = 1 * Improve regex to find git diff start line Allow for non-default git config core.commentChar, e.g. ; Supported comment chars extracted from pattern in gitcommit syntax file, see https://github.com/tpope/vim-git/blob/master/syntax/gitcommit.vim * Fix regex to extract status from commit template * Fix inaccurate status when amending commits When amending commits without g:committia#git#use_verbose enabled but with the verbose option provided to git commit, committia falls back to extracting the diff from the commit message template when the git diff command shows no changes, but this leads to an inaccurate status as the diff show existing changes, but the status shows no changes. * Improve code to extract status from commit template Search backwards from the scissors line to find the start of the status in case someone copies the same text somewhere into the commit message. * Minor changes to code to extract verbose status - Rename status_end variable to scissors_line, more accurate - Switch single line if to multi line for readability & consistency * Improve code to clean comments from message window Use match() with regex to allow for non-default git `core.commentChar` * Further improve code to extract status from commit Avoid moving the cursor by simply searching backwards for pattern match * Revert "Further improve code to extract status from commit" Will do this by iterating in reverse from scissors line instead, safer This reverts commit 6b91ce8. * Further improve code to extract status from commit Avoid moving cursor by iterating in reverse from scissors line This is safer than simply searching backwards as it allows for weirdness like someone managing to put exactly the start of the status in code that gets shown in the diff (yeah, I know, unlikely, but you never know) * Update README, document new use_verbose option * Safer code to clean comments from message window Do not assume any lines starting with common comment chars is a comment, actually get the comment char from the first line and then match that. Note: I did initially use `s:execute_git('config core.commentChar)`, and it worked fine, but concluded it was unnecessary, at least for now. * Respect git comment char in status window Prefix lines in status with git comment char rather than # For most people, who accept the default comment char of #, this makes absolutely no difference. However, if you do set core.commentChar to something other than the default, this change means that character is now consistently used in the status window, whether it is populated by by running `git status` or extracted from the verbose commit message. Technical note: this assumes that the last line in the message before the diff is a comment, which it should be unless the --no-status option is used, in which case it falls back to using '#' rather than execute a git command. The alternative would be to run `git config core.commentChar` * Improve regex conditional statements, match case Replace match() with case sensitive regex comparison operators Apply same change to all regex conditional statements for consistency (even ones which currently do not match any alphabetical characters) Co-authored-by: Linda_pp <rhysd@users.noreply.github.com> * Fix for regex special chars as comment char Revert to using stridx() to match comment char, which avoids issues with regex special chars being used as comment char, e.g. $. The regex match is no longer needed as we are again matching on a single comment char. Co-authored-by: Linda_pp <rhysd@users.noreply.github.com> --------- Co-authored-by: Linda_pp <rhysd@users.noreply.github.com>
- Loading branch information