Skip to content

Commit

Permalink
Merge branch 'bc/commit-complete-lines-given-via-m-option'
Browse files Browse the repository at this point in the history
'git commit -m "$str"' when $str was already terminated with a LF
now avoids adding an extra LF to the message.

* bc/commit-complete-lines-given-via-m-option:
  Documentation/git-commit.txt: rework the --cleanup section
  git-commit: only append a newline to -m mesg if necessary
  t7502: demonstrate breakage with a commit message with trailing newlines
  t/t7502: compare entire commit message with what was expected
  • Loading branch information
gitster committed Mar 21, 2013
2 parents f5715de + 46fbf75 commit 54797b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
29 changes: 19 additions & 10 deletions Documentation/git-commit.txt
Expand Up @@ -172,16 +172,25 @@ OPTIONS
linkgit:git-commit-tree[1].

--cleanup=<mode>::
This option sets how the commit message is cleaned up.
The '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
and 'default'. The 'default' mode will strip leading and
trailing empty lines and #commentary from the commit message
only if the message is to be edited. Otherwise only whitespace
removed. The 'verbatim' mode does not change message at all,
'whitespace' removes just leading/trailing whitespace lines
and 'strip' removes both whitespace and commentary. The default
can be changed by the 'commit.cleanup' configuration variable
(see linkgit:git-config[1]).
This option determines how the supplied commit message should be
cleaned up before committing. The '<mode>' can be `strip`,
`whitespace`, `verbatim`, or `default`.
+
--
strip::
Strip leading and trailing empty lines, trailing whitespace, and
#commentary and collapse consecutive empty lines.
whitespace::
Same as `strip` except #commentary is not removed.
verbatim::
Do not change the message at all.
default::
Same as `strip` if the message is to be edited.
Otherwise `whitespace`.
--
+
The default can be changed by the 'commit.cleanup' configuration
variable (see linkgit:git-config[1]).

-e::
--edit::
Expand Down
4 changes: 3 additions & 1 deletion builtin/commit.c
Expand Up @@ -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);
}
return 0;
}
Expand Down
16 changes: 12 additions & 4 deletions t/t7502-commit.sh
Expand Up @@ -177,12 +177,20 @@ test_expect_success 'verbose respects diff config' '
git config --unset color.diff
'

mesg_with_comment_and_newlines='
# text
'

test_expect_success 'prepare file with comment line and trailing newlines' '
printf "%s" "$mesg_with_comment_and_newlines" >expect
'

test_expect_success 'cleanup commit messages (verbatim option,-t)' '
echo >>negative &&
{ echo;echo "# text";echo; } >expect &&
git commit --cleanup=verbatim -t expect -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
git commit --cleanup=verbatim --no-status -t expect -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d" >actual &&
test_cmp expect actual
'
Expand All @@ -199,7 +207,7 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '
test_expect_success 'cleanup commit messages (verbatim option,-m)' '
echo >>negative &&
git commit --cleanup=verbatim -m "$(cat expect)" -a &&
git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
test_cmp expect actual
Expand Down

0 comments on commit 54797b9

Please sign in to comment.