From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 5385E1F4B4 for ; Tue, 2 Feb 2021 20:08:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240391AbhBBUFA (ORCPT ); Tue, 2 Feb 2021 15:05:00 -0500 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:34235 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240374AbhBBUEQ (ORCPT ); Tue, 2 Feb 2021 15:04:16 -0500 X-Originating-IP: 103.82.80.138 Received: from localhost.localdomain (unknown [103.82.80.138]) (Authenticated sender: me@yadavpratyush.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9A87260008; Tue, 2 Feb 2021 20:03:20 +0000 (UTC) From: Pratyush Yadav To: Cc: Pratyush Yadav Subject: [PATCH] git-gui: remove lines starting with the comment character Date: Wed, 3 Feb 2021 01:33:01 +0530 Message-Id: <20210202200301.44282-1-me@yadavpratyush.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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