Re: [PATCH] git-gui: remove lines starting with the comment character

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 02.02.21 um 21:03 schrieb Pratyush Yadav:
> The comment character is specified by the config variable
> 'core.commentchar'. Any lines starting with this character is considered
> a comment and should not be included in the final commit message.
> 
> Teach git-gui to filter out lines in the commit message that start with
> the comment character. If the config is not set, '#' is taken as the
> default.

This is WRONG. Git GUI is that: a GUI, it's all about WYSIWYG. If you do
not give sufficient unambiguous visual clue to the user that certain
lines will be ignored, you cannot ignore them.

You cannot just throw away what the user has typed into the edit box
without warning. How would you make it possible to insert text that
happens to begin with the comment character of the day?

Perhaps what you are really only interested in is to remove the list of
conflicted files after a merge conflict? Then the correct way to proceed
would be to sanitize the contents of .git/MERGE_MSG before it is
inserted into the edit box.

> 
> Signed-off-by: Pratyush Yadav <me@xxxxxxxxxxxxxxxxx>
> ---
>  lib/commit.tcl | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/lib/commit.tcl b/lib/commit.tcl
> index 11379f8..3c3035f 100644
> --- a/lib/commit.tcl
> +++ b/lib/commit.tcl
> @@ -209,6 +209,28 @@ You must stage at least 1 file before you can commit.
>  	#
>  	set msg [string trim [$ui_comm get 1.0 end]]
>  	regsub -all -line {[ \t\r]+$} $msg {} msg
> +
> +	# Remove lines starting with the comment character.
> +	set comment_char [get_config core.commentchar]
> +	if {[string length $comment_char] > 1} {
> +		error_popup [mc "core.commitchar should only be one character."]
> +		unlock_index
> +		return
> +	}
> +
> +	if {$comment_char eq {}} {
> +		set comment_char "#"
> +	}
> +
> +	# If the comment character is not alphabetical, then we need to escape it
> +	# with a backslash to make sure it is not interpreted as a special character
> +	# in the regex.
> +	if {![string is alpha $comment_char]} {
> +		set comment_char "\\$comment_char"
> +	}
> +
> +	regsub -all -line "$comment_char.*(\\n|\\Z)" $msg {} msg
> +
>  	if {$msg eq {}} {
>  		error_popup [mc "Please supply a commit message.
> 

-- Hannes



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux