git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pratyush Yadav <me@yadavpratyush.com>
To: <git@vger.kernel.org>
Cc: Pratyush Yadav <me@yadavpratyush.com>
Subject: [PATCH] git-gui: remove lines starting with the comment character
Date: Wed,  3 Feb 2021 01:33:01 +0530	[thread overview]
Message-ID: <20210202200301.44282-1-me@yadavpratyush.com> (raw)

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.

Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
---
 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.

--
2.30.0


             reply	other threads:[~2021-02-02 20:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 20:03 Pratyush Yadav [this message]
2021-02-02 22:26 ` [PATCH] git-gui: remove lines starting with the comment character Eric Sunshine
2021-02-03 11:54   ` Pratyush Yadav
2021-02-03 17:33 ` Johannes Sixt
2021-02-03 17:48   ` Eric Sunshine
2021-02-03 17:58     ` Eric Sunshine
2021-02-03 21:42       ` Johannes Sixt
2021-02-03 20:39     ` Pratyush Yadav

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210202200301.44282-1-me@yadavpratyush.com \
    --to=me@yadavpratyush.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).