From 4e97bad5071be2559233268a412d400db3b9483a Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jerome.reybert@tiempo-secure.com> Date: Wed, 4 May 2022 17:22:03 +0200 Subject: [PATCH] Update mg_get_commit_section function This function gets the initial commit message. It is based on a fake commit message, done with `git -c commit.verbose=no commit`. This is useful to catch any preparatory git message (template, hook, etc...). Until now, the initial git commit message was fetched, and cleaned up of comment in vimagit, mainly because of the '# Please enter the commit message ...' postscript. New method simply discard the postscript with `--no-status` option, and do not touch the commit message with `--cleanup=verbatim`. Options availaible at least since git v1.7.0 Fixes #196 --- plugin/magit.vim | 7 +++---- syntax/magit.vim | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 1455382..8028b60 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -232,16 +232,15 @@ function! s:mg_get_commit_section() " refresh the COMMIT_EDITMSG file if ( b:magit_current_commit_mode == 'CC' ) silent! call magit#sys#system_noraise("GIT_EDITOR=/bin/false " . - \ g:magit_git_cmd . " -c commit.verbose=no commit -e 2> /dev/null") + \ g:magit_git_cmd . " -c commit.verbose=no commit --cleanup=verbatim --no-status -e 2> /dev/null") elseif ( b:magit_current_commit_mode == 'CA' ) silent! call magit#sys#system_noraise("GIT_EDITOR=/bin/false " . - \ g:magit_git_cmd . " -c commit.verbose=no commit --amend -e 2> /dev/null") + \ g:magit_git_cmd . " -c commit.verbose=no commit --cleanup=verbatim --no-status --amend -e 2> /dev/null") endif if ( !empty(b:magit_current_commit_msg) ) silent put =b:magit_current_commit_msg elseif ( filereadable(git_dir . 'COMMIT_EDITMSG') ) - let comment_char=magit#git#get_config("core.commentChar", '#') - let commit_msg=magit#utils#join_list(filter(readfile(git_dir . 'COMMIT_EDITMSG'), 'v:val !~ "^' . comment_char . '"')) + let commit_msg=readfile(git_dir . 'COMMIT_EDITMSG') silent put =commit_msg endif silent put ='' diff --git a/syntax/magit.vim b/syntax/magit.vim index 6225e87..3726ead 100644 --- a/syntax/magit.vim +++ b/syntax/magit.vim @@ -15,7 +15,9 @@ hi def link titleEntry Comment execute 'syn region commitMsg start=/' . g:magit_sections.commit . '/ end=/\%(' . g:magit_section_re . '\)\@=/ contains=titleEntry' execute 'syn match commitMsgExceed "\%(=\+\n\+\_^.\{' . g:magit_commit_title_limit . '}\)\@<=.*$" contained containedin=commitMsg' +execute 'syn match commitMsgComment "^\s*#.*$" contained containedin=commitMsg' hi def link commitMsgExceed Comment +hi def link commitMsgComment Comment execute 'syn match stashEntry "' . g:magit_stash_re . '"' hi def link stashEntry String -- GitLab