lmi
[Top][All Lists]
Advanced

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

Re: [lmi] Detecting a non-empty second line in commit-msg hook


From: Vadim Zeitlin
Subject: Re: [lmi] Detecting a non-empty second line in commit-msg hook
Date: Sat, 10 Dec 2016 01:38:36 +0100

On Sat, 10 Dec 2016 00:22:08 +0000 Greg Chicares <address@hidden> wrote:

GC> Is git silently removing trailing blanks from commit messages?

 The short answer is "yes".

 The longer answer is: working from the end, I've found this in git
sources:

        https://github.com/git/git/blob/v2.11.0/builtin/commit.c#L790

The function strbuf_stripspace() does what you'd expect it to do, here is
an extract from its description:

/*
 * Remove empty lines from the beginning and end
 * and also trailing spaces from every line.
 *
 * Turn multiple consecutive empty lines between paragraphs
 * into just one empty line.
...
 */

So the only remaining question is when "clean_message_contents" is true or,
looking at https://github.com/git/git/blob/v2.11.0/builtin/commit.c#L671,
when is "clean_mode" set to CLEANUP_NONE. And the value of this variable is
determined by Git commit.cleanup config option and/or --cleanup command
line option.

 The conclusion is that while you could set commit.cleanup to "verbatim" or
use --cleanup=verbatim on the command line, usually there is no reason to
do it (and, indeed, I didn't even know about this option existence until
today) and if you don't do this, leading and trailing empty lines as well
as trailing whitespace will be removed, see the "default" option
description at https://www.kernel.org/pub/software/scm/git/docs/git-commit.html

 Hope this helps,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]