Skip to content

Commit 3270ae8

Browse files
charvi-077gitster
authored andcommitted
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 <[email protected]> Mentored-by: Phillip Wood <[email protected]> Helped-by: Junio C Hamano <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Charvi Mendiratta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 494d314 commit 3270ae8

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

builtin/commit.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,19 @@ static void finalize_deferred_config(struct wt_status *s)
11881188
s->ahead_behind_flags = AHEAD_BEHIND_FULL;
11891189
}
11901190

1191+
static void check_fixup_reword_options(int argc, const char *argv[]) {
1192+
if (whence != FROM_COMMIT) {
1193+
if (whence == FROM_MERGE)
1194+
die(_("You are in the middle of a merge -- cannot reword."));
1195+
else if (is_from_cherry_pick(whence))
1196+
die(_("You are in the middle of a cherry-pick -- cannot reword."));
1197+
}
1198+
if (argc)
1199+
die(_("cannot combine reword option of --fixup with path '%s'"), *argv);
1200+
if (patch_interactive || interactive || all || also || only)
1201+
die(_("reword option of --fixup is mutually exclusive with --patch/--interactive/--all/--include/--only"));
1202+
}
1203+
11911204
static int parse_and_validate_options(int argc, const char *argv[],
11921205
const struct option *options,
11931206
const char * const usage[],
@@ -1269,8 +1282,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
12691282
* We limit --fixup's suboptions to only alpha characters.
12701283
* If the first character after a run of alpha is colon,
12711284
* then the part before the colon may be a known suboption
1272-
* name `amend` or a misspelt suboption name. In this case,
1273-
* we treat it as --fixup=<suboption>:<arg>.
1285+
* name like `amend` or `reword`, or a misspelt suboption
1286+
* name. In either case, we treat it as
1287+
* --fixup=<suboption>:<arg>.
12741288
*
12751289
* Otherwise, we are dealing with --fixup=<commit>.
12761290
*/
@@ -1280,9 +1294,14 @@ static int parse_and_validate_options(int argc, const char *argv[],
12801294
if (p > fixup_message && *p == ':') {
12811295
*p = '\0';
12821296
fixup_commit = p + 1;
1283-
if (!strcmp("amend", fixup_message)) {
1297+
if (!strcmp("amend", fixup_message) ||
1298+
!strcmp("reword", fixup_message)) {
12841299
fixup_prefix = "amend";
12851300
allow_empty = 1;
1301+
if (*fixup_message == 'r') {
1302+
check_fixup_reword_options(argc, argv);
1303+
only = 1;
1304+
}
12861305
} else {
12871306
die(_("unknown option: --fixup=%s:%s"), fixup_message, fixup_commit);
12881307
}
@@ -1571,10 +1590,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
15711590
OPT_STRING('c', "reedit-message", &edit_message, N_("commit"), N_("reuse and edit message from specified commit")),
15721591
OPT_STRING('C', "reuse-message", &use_message, N_("commit"), N_("reuse message from specified commit")),
15731592
/*
1574-
* TRANSLATORS: Leave "[amend:]" as-is, and
1575-
* only translate <commit>.
1593+
* TRANSLATORS: Leave "[(amend|reword):]" as-is,
1594+
* and only translate <commit>.
15761595
*/
1577-
OPT_STRING(0, "fixup", &fixup_message, N_("[amend:]commit"), N_("use autosquash formatted message to fixup or amend specified commit")),
1596+
OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
15781597
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
15791598
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
15801599
OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),

0 commit comments

Comments
 (0)