# [PATCH] commit: add -f to force creation when no changes or an empty message

1 messages from 2015-03-29 to 2015-03-29. Participants: Ivan Ukhov.
Thread: https://gitlist.dev/t/38939

## Ivan Ukhov, 2015-03-29 15:34

Subject: [PATCH] commit: add -f to force creation when no changes or an empty message
Message-ID: <E2201BDB-4441-4BD0-B0ED-2F39A2838A7F@gmail.com>
URL: https://gitlist.dev/e/E2201BDB-4441-4BD0-B0ED-2F39A2838A7F%40gmail.com

```
An attempt to commit gets rejected if there are no changes staged or there is no
message given. In such a case, the --allow-empty and --allow-empty-message flags
can be used to force the action. The standard approach to force an action,
however, is the -f/--force flag, as used in other built-ins.

Signed-off-by: Ivan Ukhov <ivan.ukhov@gmail.com>
---
 builtin/commit.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index da79ac4..fb76aee 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -113,7 +113,7 @@ static char *fixup_message, *squash_message;
 static int all, also, interactive, patch_interactive, only, amend, signoff;
 static int edit_flag = -1; /* unspecified */
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
-static int no_post_rewrite, allow_empty_message;
+static int no_post_rewrite, allow_empty_message, force;
 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
 static char *sign_commit;

@@ -1614,6 +1614,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "amend", &amend, N_("amend previous commit")),
 		OPT_BOOL(0, "no-post-rewrite", &no_post_rewrite, N_("bypass post-rewrite hook")),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
+		OPT__FORCE(&force, N_("force creation when no changes or an empty message")),
 		/* end commit contents options */

 		OPT_HIDDEN_BOOL(0, "allow-empty", &allow_empty,
@@ -1653,6 +1654,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	argc = parse_and_validate_options(argc, argv, builtin_commit_options,
 					  builtin_commit_usage,
 					  prefix, current_head, &s);
+
+	allow_empty += force;
+	allow_empty_message += force;
+
 	if (dry_run)
 		return dry_run_commit(argc, argv, prefix, current_head, &s);
 	index_file = prepare_index(argc, argv, prefix, current_head, 0);
--
2.3.4

```
