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

[PATCH] commit: make default of "cleanup" option configurable

From
Ralf Thielow <ralf.thielow@gmail.com>
Date
Jan 8, 2013, 20:16 UTC
Message-ID
<1357676176-30019-1-git-send-email-ralf.thielow@gmail.com>

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>
---
 Documentation/config.txt |  4 ++++
 builtin/commit.c         | 29 ++++++++++++++++++-----------
 2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 53c4ca1..3f76cd1 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -917,6 +917,10 @@ 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.
+
 commit.status::
 	A boolean to enable/disable inclusion of status information in the
 	commit message template when using an editor to prepare the commit
diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..42acde7 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -103,7 +103,7 @@ static enum {
 	CLEANUP_NONE,
 	CLEANUP_ALL
 } cleanup_mode;
-static char *cleanup_arg;
+const static char *cleanup_arg;
 
 static enum commit_whence whence;
 static int use_editor = 1, include_status = 1;
@@ -966,6 +966,20 @@ static const char *read_commit_message(const char *name)
 	return out;
 }
 
+static void parse_cleanup_arg()
+{
+	if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
+		cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
+	else if (!strcmp(cleanup_arg, "verbatim"))
+		cleanup_mode = CLEANUP_NONE;
+	else if (!strcmp(cleanup_arg, "whitespace"))
+		cleanup_mode = CLEANUP_SPACE;
+	else if (!strcmp(cleanup_arg, "strip"))
+		cleanup_mode = CLEANUP_ALL;
+	else
+		die(_("Invalid cleanup mode %s"), cleanup_arg);
+}
+
 static int parse_and_validate_options(int argc, const char *argv[],
 				      const struct option *options,
 				      const char * const usage[],
@@ -1044,18 +1058,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
 		only_include_assumed = _("Clever... amending the last one with dirty index.");
 	if (argc > 0 && !also && !only)
 		only_include_assumed = _("Explicit paths specified without -i nor -o; assuming --only paths...");
-	if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
-		cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
-	else if (!strcmp(cleanup_arg, "verbatim"))
-		cleanup_mode = CLEANUP_NONE;
-	else if (!strcmp(cleanup_arg, "whitespace"))
-		cleanup_mode = CLEANUP_SPACE;
-	else if (!strcmp(cleanup_arg, "strip"))
-		cleanup_mode = CLEANUP_ALL;
-	else
-		die(_("Invalid cleanup mode %s"), cleanup_arg);
 
 	handle_untracked_files_arg(s);
+	parse_cleanup_arg();
 
 	if (all && argc > 0)
 		die(_("Paths with -a does not make sense."));
@@ -1320,6 +1325,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);
 
 	status = git_gpg_config(k, v, NULL);
 	if (status)
-- 
1.8.1.165.gd94bd4e.dirty
Next: Junio C Hamano
Message 1 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.