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

Re: [PATCHv2] commit: make default of "cleanup" option configurable

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 10, 2013, 00:17 UTC
Message-ID
<7vwqvl3n9a.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1357760209-3407-1-git-send-email-ralf.thielow@gmail.com>
Ralf Thielow <ralf.thielow@gmail.com> writes:
Show 10 quoted lines
> The default of the "cleanup" option in "git commit"
> is not configurable. Users who don't want to use the
> default have to pass this option on every commit since
> there's no way to configure it. This commit introduces
> a new config option "commit.cleanup" which can be used
> to change the default of the "cleanup" option in
> "git commit".
>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
Thanks.
Show 28 quoted lines
> Changes in v2:
> - simplify implementation
> - mention configuration variable in documentation of "git commit --cleanup"
> - add an example usecase to documention of commit.cleanup configuration variable
> - add tests
>
>  Documentation/config.txt        |  7 ++++
>  Documentation/git-commit.txt    |  4 +-
>  builtin/commit.c                |  5 ++-
>  t/t7500/add-content-and-comment |  4 ++
>  t/t7502-commit.sh               | 84 +++++++++++++++++++++++++++++++++++++----
>  5 files changed, 95 insertions(+), 9 deletions(-)
>  create mode 100755 t/t7500/add-content-and-comment
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 53c4ca1..0452d56 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -917,6 +917,13 @@ column.tag::
>  	Specify whether to output tag listing in `git tag` in columns.
>  	See `column.ui` for details.
>  
> +commit.cleanup::
> +	This setting overrides the default of the `--cleanup` option in
> +	`git commit`. See linkgit:git-commit[1] for details. Changing the
> +	default can be useful if you want to use the comment character (#)
> +	consistently within your commit messages, in which case you would
> +	like to change the default to 'whitespace'.

When the documentation suggests to use 'whitespace', it would be helpful to warn the readers that hints Git produces in '#'-commented section need to be removed, if they are not ment to be kept (which is 99.99% of the case). Perhaps:

	This setting overrides the default of the `--cleanup` option
	in `git commit`. Changing the default can be useful when you
	always want to keep lines that begin with comment character
	`#` in your log message, in which case you would do `git
	config commit.cleanup whitespace` (note that you will have
	to remove the help lines that begin with '#' in the commit
	log template yourself, if you do this).
or something?
Show 12 quoted lines
> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
> index 7bdb039..41b27da 100644
> --- a/Documentation/git-commit.txt
> +++ b/Documentation/git-commit.txt
> @@ -179,7 +179,9 @@ OPTIONS
>  	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.
> +	and 'strip' removes both whitespace and commentary. The default
> +	can be changed by the 'commit.cleanup' configuration variable
> +	(see linkgit:git-config[1]).
Nicely written.
Show 19 quoted lines
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -103,7 +103,7 @@ static enum {
>  	CLEANUP_NONE,
>  	CLEANUP_ALL
>  } cleanup_mode;
> -static char *cleanup_arg;
> +static const char *cleanup_arg;
>  
>  static enum commit_whence whence;
>  static int use_editor = 1, include_status = 1;
> @@ -966,6 +966,7 @@ static const char *read_commit_message(const char *name)
>  	return out;
>  }
>  
> +
>  static int parse_and_validate_options(int argc, const char *argv[],
>  				      const struct option *options,
>  				      const char * const usage[],
Don't add an extra blank line, please.
Show 6 quoted lines
> @@ -1320,6 +1321,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
>  		include_status = git_config_bool(k, v);
>  		return 0;
>  	}
> +	if (!strcmp(k, "commit.cleanup"))
> +		return git_config_string(&cleanup_arg, k, v);
Nice.
Show 11 quoted lines
> diff --git a/t/t7500/add-content-and-comment b/t/t7500/add-content-and-comment
> new file mode 100755
> index 0000000..988f5e9
> --- /dev/null
> +++ b/t/t7500/add-content-and-comment
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +echo "commit message" >> "$1"
> +echo "# comment" >> "$1"
> +exit 0
> \ No newline at end of file
Have newline at end of file, please.
Show 8 quoted lines
> diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
> index 1a5cb69..b1c7648 100755
> --- a/t/t7502-commit.sh
> +++ b/t/t7502-commit.sh
> @@ -4,6 +4,15 @@ test_description='git commit porcelain-ish'
> +...
> +'
> +
Nicely done.
Thanks.
Previous: Ralf ThielowNext: Ralf Thielow
Message 17 of 18 in “commit: make default of "cleanup" option configurable”
  1. commit: make default of "cleanup" option configurableRalf Thielow, Jan 8, 2013
  2. Junio C HamanoJan 8, 2013
  3. Jonathan NiederJan 9, 2013
  4. Ralf ThielowJan 9, 2013
  5. Jonathan NiederJan 9, 2013
  6. Junio C HamanoJan 9, 2013
  7. Junio C HamanoJan 9, 2013
  8. Re* [PATCH] commit: make default of "cleanup" option configurableJunio C Hamano, Jan 10, 2013
  9. Allow custom "comment char"Ralf Thielow, Jan 15, 2013
  10. Junio C HamanoJan 15, 2013
  11. Junio C HamanoJan 16, 2013
  12. Ralf ThielowJan 16, 2013
  13. Allow custom "comment char"Ralf Thielow, Jan 16, 2013
  14. Junio C HamanoJan 16, 2013
  15. Jens LehmannJan 16, 2013
  16. [PATCHv2] commit: make default of "cleanup" option configurableRalf Thielow, Jan 9, 2013
  17. Junio C HamanoJan 10, 2013
  18. [PATCHv3] commit: make default of "cleanup" option configurableRalf Thielow, Jan 10, 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.