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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]