summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Charvi Mendiratta <charvi077@gmail.com>2021-03-15 13:24:33 +0530
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-03-15 14:29:35 -0700
commit3270ae82acdec3d25491427e0ecff43c014ac4d9 (patch)
tree0079db76d1554afd3807a59f6247259e7e2ec686
parentcommit: add amend suboption to --fixup to create amend! commit (diff)
downloadtgif-3270ae82acdec3d25491427e0ecff43c014ac4d9.tar.xz
commit: add a reword suboption to --fixup
`git commit --fixup=reword:<commit>` aliases `--fixup=amend:<commit> --only`, where it creates an empty "amend!" commit that will reword <commit> without changing its contents when it is rebased with `--autosquash`. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Phillip Wood <phillip.wood@dunelm.org.uk> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Charvi Mendiratta <charvi077@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/commit.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 9697bba10b..b17e6e32f8 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1188,6 +1188,19 @@ static void finalize_deferred_config(struct wt_status *s)
s->ahead_behind_flags = AHEAD_BEHIND_FULL;
}
+static void check_fixup_reword_options(int argc, const char *argv[]) {
+ if (whence != FROM_COMMIT) {
+ if (whence == FROM_MERGE)
+ die(_("You are in the middle of a merge -- cannot reword."));
+ else if (is_from_cherry_pick(whence))
+ die(_("You are in the middle of a cherry-pick -- cannot reword."));
+ }
+ if (argc)
+ die(_("cannot combine reword option of --fixup with path '%s'"), *argv);
+ if (patch_interactive || interactive || all || also || only)
+ die(_("reword option of --fixup is mutually exclusive with --patch/--interactive/--all/--include/--only"));
+}
+
static int parse_and_validate_options(int argc, const char *argv[],
const struct option *options,
const char * const usage[],
@@ -1269,8 +1282,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
* We limit --fixup's suboptions to only alpha characters.
* If the first character after a run of alpha is colon,
* then the part before the colon may be a known suboption
- * name `amend` or a misspelt suboption name. In this case,
- * we treat it as --fixup=<suboption>:<arg>.
+ * name like `amend` or `reword`, or a misspelt suboption
+ * name. In either case, we treat it as
+ * --fixup=<suboption>:<arg>.
*
* Otherwise, we are dealing with --fixup=<commit>.
*/
@@ -1280,9 +1294,14 @@ static int parse_and_validate_options(int argc, const char *argv[],
if (p > fixup_message && *p == ':') {
*p = '\0';
fixup_commit = p + 1;
- if (!strcmp("amend", fixup_message)) {
+ if (!strcmp("amend", fixup_message) ||
+ !strcmp("reword", fixup_message)) {
fixup_prefix = "amend";
allow_empty = 1;
+ if (*fixup_message == 'r') {
+ check_fixup_reword_options(argc, argv);
+ only = 1;
+ }
} else {
die(_("unknown option: --fixup=%s:%s"), fixup_message, fixup_commit);
}
@@ -1571,10 +1590,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
OPT_STRING('c', "reedit-message", &edit_message, N_("commit"), N_("reuse and edit message from specified commit")),
OPT_STRING('C', "reuse-message", &use_message, N_("commit"), N_("reuse message from specified commit")),
/*
- * TRANSLATORS: Leave "[amend:]" as-is, and
- * only translate <commit>.
+ * TRANSLATORS: Leave "[(amend|reword):]" as-is,
+ * and only translate <commit>.
*/
- OPT_STRING(0, "fixup", &fixup_message, N_("[amend:]commit"), N_("use autosquash formatted message to fixup or amend specified commit")),
+ OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),