git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/4] git-commit: only append a newline to -m mesg if necessary

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 19, 2013, 06:31 UTC
Message-ID
<20130219063121.GF19757@elie.Belkin>
In-Reply-To
<1361247427-438-3-git-send-email-drafnel@gmail.com>
Brandon Casey wrote:
Show 12 quoted lines
> Currently, git will append two newlines to every message supplied via
> the -m switch.  The purpose of this is to allow -m to be supplied
> multiple times and have each supplied string become a paragraph in the
> resulting commit message.
>
> Normally, this does not cause a problem since any trailing newlines will
> be removed by the cleanup operation.  If cleanup=verbatim for example,
> then the trailing newlines will not be removed and will survive into the
> resulting commit message.
>
> Instead, let's ensure that the string supplied to -m is newline terminated,
> but only append a second newline when appending additional messages.
[...]
Show 11 quoted lines
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -124,8 +124,10 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
>  	if (unset)
>  		strbuf_setlen(buf, 0);
>  	else {
> +		if (buf->len)
> +			strbuf_addch(buf, '\n');
>  		strbuf_addstr(buf, arg);
> -		strbuf_addstr(buf, "\n\n");
> +		strbuf_complete_line(buf);

As long as 'message' always consists of complete lines, this will append 'arg' as a new paragraph, as desired. And no other code path touches 'message', so it always consists of complete lines.

Thanks for a clear patch and explanation.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
(rest of patch kept unsnipped for reference)
Show 17 quoted lines
>  	}
>  	return 0;
>  }
> diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
> index 39e55f8..292bc08 100755
> --- a/t/t7502-commit.sh
> +++ b/t/t7502-commit.sh
> @@ -204,7 +204,7 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '
>  
>  '
>  
> -test_expect_failure 'cleanup commit messages (verbatim option,-m)' '
> +test_expect_success 'cleanup commit messages (verbatim option,-m)' '
>  
>  	echo >>negative &&
>  	git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
> -- 
Previous: Brandon CaseyNext: Brandon Casey
Message 5 of 19 in “t/t7502: compare entire commit message with what was expected”
  1. 1/4 t/t7502: compare entire commit message with what was expectedBrandon Casey, Feb 19, 2013
  2. 2/4 t7502: demonstrate breakage with a commit message with trailing newlinesBrandon Casey, Feb 19, 2013
  3. Jonathan NiederFeb 19, 2013
  4. 3/4 git-commit: only append a newline to -m mesg if necessaryBrandon Casey, Feb 19, 2013
  5. Jonathan NiederFeb 19, 2013
  6. 4/4 Documentation/git-commit.txt: correct a few minor grammatical mistakesBrandon Casey, Feb 19, 2013
  7. Jonathan NiederFeb 19, 2013
  8. Brandon CaseyFeb 19, 2013
  9. Jonathan NiederFeb 19, 2013
  10. Junio C HamanoFeb 19, 2013
  11. 4/4 Documentation/git-commit.txt: rework the --cleanup sectionBrandon Casey, Feb 19, 2013
  12. 4/4 Documentation/git-commit.txt: rework the --cleanup sectionBrandon Casey, Feb 19, 2013
  13. 4/4 Documentation/git-commit.txt: rework the --cleanup sectionBrandon Casey, Feb 19, 2013
  14. fixup! Documentation/git-commit.txt: rework the --cleanup sectionJonathan Nieder, Feb 19, 2013
  15. Brandon CaseyFeb 19, 2013
  16. Junio C HamanoFeb 19, 2013
  17. Jonathan NiederFeb 19, 2013
  18. Jonathan NiederFeb 19, 2013
  19. Junio C HamanoFeb 19, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.