From patchwork Mon Mar 1 08:45:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12109073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D1EBC433E9 for ; Mon, 1 Mar 2021 08:49:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 415BF64E04 for ; Mon, 1 Mar 2021 08:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233599AbhCAItA (ORCPT ); Mon, 1 Mar 2021 03:49:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233456AbhCAIrh (ORCPT ); Mon, 1 Mar 2021 03:47:37 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47DEAC0617AA for ; Mon, 1 Mar 2021 00:46:32 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id e9so9417664plh.3 for ; Mon, 01 Mar 2021 00:46:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=lj8J54VPnUWrGYLdXGgLgaNBhpU1h+x2dO0LH2yGcuM=; b=K/tEHUAC0MQhidsRpAv9ihCjpRXGg18TNCLQG7yeMcLX+G5W+0s38HmX/qlHGICiI4 OglpLldNM1jSOiIlAU5Dff4gv4aEHNaCWBwB2TaRdzEw1avUDXXCGiYWCYAz5glOqOzk ntEkSSz6xFW0tl7rkoRccicGujN/hb6imYdOwXbxb/Am4ozB1+xYMrSjDPL9w21hGLUC CxCrs09E/eFwf1bF5+O4BzpWGR5y9onfvde2v0AEXKSN+PT5Xz8vl0VfYum5T1ol6K2P Wed0FFbi9c8u11BFPUdqLrePYl4HIdxU7ln6AqPSea2yxu8nLL/5WotHtqPOZ5vhvnl0 HvAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=lj8J54VPnUWrGYLdXGgLgaNBhpU1h+x2dO0LH2yGcuM=; b=XBEqabcMiDuKacGgCFRzUGdcx+5fzb7w7WpTNM2htRp3EgOeG6hOyTQm8rjM+P0nFV tNAbLgnllumFDuXsPAZ50bAS0uHU3oLPvEZKVFJzCpd+bSHxVQ7RWtmPJ0AzGNNIKhML S0z7xfkvbLjZdaYG1fYqYQP3yY4wm5bq/UhU6VMFGxb1+m2B9dI/iyc2dOim7AGq2skF DfBsa/qqNNzM568cwsMax96l6mxw84GN3Ne8wNpsNAs+LrIVvA7DhnOY6+0oyc5+ZoB4 PHR8iFddAl++1gFvIgymq7Hma9nWGpBGtxJfIqITQ7F3LDGQH7KdUaxhWT0LR2UEaJXz cCLg== X-Gm-Message-State: AOAM532M1pCIq+x0xdnRBzR6m+N9uDVANjlLEFJs1I3IQ/Qk00Vxa3Ai KpiPkd1+sM79jB47W2IigedC01g9UBQDug== X-Google-Smtp-Source: ABdhPJx7K1mav7ol7OdZg+mwzeh4nXu89VWa5mNcyWcytIRUIbcahyLhpIvTyEuWfTnYsLCeMR8RbQ== X-Received: by 2002:a17:90a:8b02:: with SMTP id y2mr16412203pjn.111.1614588391647; Mon, 01 Mar 2021 00:46:31 -0800 (PST) Received: from localhost.localdomain ([2405:204:302d:d8af:c047:a272:aff7:4de6]) by smtp.googlemail.com with ESMTPSA id b34sm16781426pgl.63.2021.03.01.00.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 00:46:31 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: gitster@pobox.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v3 1/6] sequencer: export subject_length() Date: Mon, 1 Mar 2021 14:15:09 +0530 Message-Id: <20210301084512.27170-2-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210301084512.27170-1-charvi077@gmail.com> References: <20210301084512.27170-1-charvi077@gmail.com> Reply-To: 20210217072904.16257-1-charvi077@gmail.com MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This function can be used in other parts of git. Let's move the function to commit.c. Mentored-by: Christian Couder Mentored-by: Phillip Wood Signed-off-by: Charvi Mendiratta --- commit.c | 14 ++++++++++++++ commit.h | 3 +++ sequencer.c | 14 -------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/commit.c b/commit.c index bab8d5ab07..41cc72c4de 100644 --- a/commit.c +++ b/commit.c @@ -535,6 +535,20 @@ int find_commit_subject(const char *commit_buffer, const char **subject) return eol - p; } +size_t subject_length(const char *body) +{ + const char *p = body; + while (*p) { + const char *next = skip_blank_lines(p); + if (next != p) + break; + p = strchrnul(p, '\n'); + if (*p) + p++; + } + return p - body; +} + struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p) { struct commit_list *new_list = xmalloc(sizeof(struct commit_list)); diff --git a/commit.h b/commit.h index f4e7b0158e..12ff6bc641 100644 --- a/commit.h +++ b/commit.h @@ -165,6 +165,9 @@ const void *detach_commit_buffer(struct commit *, unsigned long *sizep); /* Find beginning and length of commit subject. */ int find_commit_subject(const char *commit_buffer, const char **subject); +/* Return length of the commit subject from commit log message. */ +size_t subject_length(const char *body); + struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list); int commit_list_contains(struct commit *item, diff --git a/sequencer.c b/sequencer.c index abc6d5cdfd..3fac4ba62f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1724,20 +1724,6 @@ enum todo_item_flags { TODO_EDIT_FIXUP_MSG = (1 << 2), }; -static size_t subject_length(const char *body) -{ - const char *p = body; - while (*p) { - const char *next = skip_blank_lines(p); - if (next != p) - break; - p = strchrnul(p, '\n'); - if (*p) - p++; - } - return p - body; -} - static const char first_commit_msg_str[] = N_("This is the 1st commit message:"); static const char nth_commit_msg_fmt[] = N_("This is the commit message #%d:"); static const char skip_first_commit_msg_str[] = N_("The 1st commit message will be skipped:"); From patchwork Mon Mar 1 08:45:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12109071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D1E8C433E6 for ; Mon, 1 Mar 2021 08:49:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1032964DE0 for ; Mon, 1 Mar 2021 08:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233525AbhCAIsj (ORCPT ); Mon, 1 Mar 2021 03:48:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233479AbhCAIrh (ORCPT ); Mon, 1 Mar 2021 03:47:37 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1499AC0617AB for ; Mon, 1 Mar 2021 00:46:39 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id q20so11002808pfu.8 for ; Mon, 01 Mar 2021 00:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=rjgN7dEMQC5aY5MliYWkSP66M4/Ow+a2V2KayVbmRXE=; b=JwA5OHSUgR9WSEQ/UDIt28+PxtzfjZBKqV5QpP4dhFNExvR9QMGbUB1q0Aa9Efys/c ntoJgaa7PWGWosZYdQbePQ0Si/rceir5h+NSNPwXAQPss6nvjFkA4yntdPkGcgl+6zxn pnuKtngLV177LHWvUgAnlEp9t+DShC+zk5av/EZSDEZELffy5KD6naPAxqGjmhaLnLQu KX4PWnewiSFh8wTVr2/0MhAzbnh9LNTaTNG0Iq3+bPp+lNQ2EL8vZ3sQfAFbspF2eHs3 cqQ+1JsSPeQ7dIXtrTOhGYLUw2HxflJr/Bxvu/zH+iiBQ86BgCIO7+zwbYdAyT+y/cqH VvXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=rjgN7dEMQC5aY5MliYWkSP66M4/Ow+a2V2KayVbmRXE=; b=rMHUq129JDVRB5PEBN8CycT/mAkZ2vKTqeBYwlkKGOqmAUoHZXJGqxVMQtFBVhAu8F 6oU1+3ncW9+JmTi5wqTdy8EhmdK4ZSWN/xKFFP3UF6b1PVdC3j0EIsbyJofilIeaKAa4 1oKGv1oCmihtiWfcORzgoqfTQIqaLl8kT+PeAMNKbqCU1hgWty+bTMp+CFcS8uW3/RWj sq22DHpvRvuwxOBHF7FhIwFKtwBtFw2xx3mr23BrbsxAPSVKg4n6R+KAsCiXuB62GYSJ PAkXMzowe/FPPgDZb58rCeMM+tPLlQEAlYxlzNtFwNwAWKmNIOQEA/Gu6UB8A8nqyjUZ FhRg== X-Gm-Message-State: AOAM531w70n7w3LDBP8BxukYOCm1me6jm/VwjQ30HtiGh9EA5YhqKFu/ UtvuulcQwmidTwPUFOJXRXts6lrKeUXvCw== X-Google-Smtp-Source: ABdhPJwjp1EL1bmBo7Dc9ATqDX3xPNj5bYX0EDGnReCbrvXH01OxLHUmriU5UflUXh0K8knqN6hOhw== X-Received: by 2002:a63:fa07:: with SMTP id y7mr13012915pgh.213.1614588397452; Mon, 01 Mar 2021 00:46:37 -0800 (PST) Received: from localhost.localdomain ([2405:204:302d:d8af:c047:a272:aff7:4de6]) by smtp.googlemail.com with ESMTPSA id b34sm16781426pgl.63.2021.03.01.00.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 00:46:37 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: gitster@pobox.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v3 2/6] commit: add amend suboption to --fixup to create amend! commit Date: Mon, 1 Mar 2021 14:15:10 +0530 Message-Id: <20210301084512.27170-3-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210301084512.27170-1-charvi077@gmail.com> References: <20210301084512.27170-1-charvi077@gmail.com> Reply-To: 20210217072904.16257-1-charvi077@gmail.com MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git commit --fixup=amend:` will create an "amend!" commit. The resulting commit message subject will be "amend! ..." where "..." is the subject line of and the initial message body will be 's message. -m can be used to override the message body. The "amend!" commit when rebased with --autosquash will fixup the contents and replace the commit message of with the "amend!" commit's message body. In order to prevent rebase from creating commits with an empty message we refuse to create an "amend!" commit if commit message body is empty. Mentored-by: Christian Couder Mentored-by: Phillip Wood Helped-by: Junio C Hamano Signed-off-by: Charvi Mendiratta --- builtin/commit.c | 97 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 9 deletions(-) -- 2.29.0.rc1 diff --git a/builtin/commit.c b/builtin/commit.c index 505fe60956..200ef83cc0 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -105,7 +105,8 @@ static const char *template_file; */ static const char *author_message, *author_message_buffer; static char *edit_message, *use_message; -static char *fixup_message, *squash_message; +static char *fixup_message, *fixup_commit, *squash_message; +static const char *fixup_prefix; 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; @@ -681,6 +682,21 @@ static void adjust_comment_line_char(const struct strbuf *sb) comment_line_char = *p; } +static int prepare_amend_commit(struct commit *commit, struct strbuf *sb, + struct pretty_print_context *ctx) { + /* + * If we amend the 'amend!' commit then we don't want to + * duplicate the subject line. + */ + const char *format = NULL; + if (starts_with(sb->buf, "amend! amend!")) + format = "%b"; + else + format = "%B"; + format_commit_message(commit, format, sb, ctx); + return 0; +} + static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, @@ -745,15 +761,33 @@ static int prepare_to_commit(const char *index_file, const char *prefix, } else if (fixup_message) { struct pretty_print_context ctx = {0}; struct commit *commit; - commit = lookup_commit_reference_by_name(fixup_message); + char *fmt = xstrfmt("%s! %%s\n\n", fixup_prefix); + commit = lookup_commit_reference_by_name(fixup_commit); if (!commit) - die(_("could not lookup commit %s"), fixup_message); + die(_("could not lookup commit %s"), fixup_commit); ctx.output_encoding = get_commit_output_encoding(); - format_commit_message(commit, "fixup! %s\n\n", - &sb, &ctx); - if (have_option_m) - strbuf_addbuf(&sb, &message); + format_commit_message(commit, fmt, &sb, &ctx); + free(fmt); hook_arg1 = "message"; + + /* + * Only `-m` commit message option is checked here, as + * it supports `--fixup` to append the commit message. + * + * The other commit message options `-c`/`-C`/`-F` are + * incompatible with all the forms of `--fixup` and + * have already errored out while parsing the `git commit` + * options. + */ + if (have_option_m && !strcmp(fixup_prefix, "fixup")) + strbuf_addbuf(&sb, &message); + + if (!strcmp(fixup_prefix, "amend")) { + if (have_option_m) + die(_("cannot combine -m with --fixup:%s"), fixup_message); + else + prepare_amend_commit(commit, &sb, &ctx); + } } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) { size_t merge_msg_start; @@ -1152,6 +1186,12 @@ static void finalize_deferred_config(struct wt_status *s) s->ahead_behind_flags = AHEAD_BEHIND_FULL; } +/* returns the length of intial segment of alpha characters only */ +static size_t get_alpha_len(char *fixup_message) { + const char alphas[] = "abcdefghijklmnopqrstuvwxyz"; + return strspn(fixup_message, alphas); +} + static int parse_and_validate_options(int argc, const char *argv[], const struct option *options, const char * const usage[], @@ -1170,7 +1210,7 @@ static int parse_and_validate_options(int argc, const char *argv[], if (force_author && renew_authorship) die(_("Using both --reset-author and --author does not make sense")); - if (logfile || have_option_m || use_message || fixup_message) + if (logfile || have_option_m || use_message) use_editor = 0; if (0 <= edit_flag) use_editor = edit_flag; @@ -1227,6 +1267,28 @@ static int parse_and_validate_options(int argc, const char *argv[], if (also + only + all + interactive > 1) die(_("Only one of --include/--only/--all/--interactive/--patch can be used.")); + + if (fixup_message) { + /* + * As `amend` suboption contains only alpha + * character. So check if first non alpha + * character in fixup_message is ':'. + */ + size_t len = get_alpha_len(fixup_message); + if (len && fixup_message[len] == ':') { + fixup_message[len++] = '\0'; + fixup_commit = fixup_message + len; + if (starts_with("amend", fixup_message)) + fixup_prefix = "amend"; + else + die(_("unknown option: --fixup=%s:%s"), fixup_message, fixup_commit); + } else { + fixup_commit = fixup_message; + fixup_prefix = "fixup"; + use_editor = 0; + } + } + cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor); handle_untracked_files_arg(s); @@ -1504,7 +1566,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_CALLBACK('m', "message", &message, N_("message"), N_("commit message"), opt_parse_m), 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")), - OPT_STRING(0, "fixup", &fixup_message, N_("commit"), N_("use autosquash formatted message to fixup specified commit")), + /* + * TRANSLATORS: Leave "[amend:]" as-is, and + * only translate . + */ + OPT_STRING(0, "fixup", &fixup_message, N_("[amend:]commit"), N_("use autosquash formatted message to fixup or amend 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")), @@ -1663,6 +1729,19 @@ int cmd_commit(int argc, const char **argv, const char *prefix) exit(1); } + if (fixup_message && starts_with(sb.buf, "amend! ") && + !allow_empty_message) { + struct strbuf body = STRBUF_INIT; + size_t len = subject_length(sb.buf); + strbuf_addstr(&body, sb.buf + len); + if (message_is_empty(&body, cleanup_mode)) { + rollback_index_files(); + fprintf(stderr, _("Aborting commit due to empty commit message body.\n")); + exit(1); + } + strbuf_release(&body); + } + if (amend) { const char *exclude_gpgsig[3] = { "gpgsig", "gpgsig-sha256", NULL }; extra = read_commit_extra_headers(current_head, exclude_gpgsig); From patchwork Mon Mar 1 08:45:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12109079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 816DFC43381 for ; Mon, 1 Mar 2021 08:50:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5426E61494 for ; Mon, 1 Mar 2021 08:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233351AbhCAIuS (ORCPT ); Mon, 1 Mar 2021 03:50:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233612AbhCAIsC (ORCPT ); Mon, 1 Mar 2021 03:48:02 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 594DAC06121D for ; Mon, 1 Mar 2021 00:46:43 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id g20so9428958plo.2 for ; Mon, 01 Mar 2021 00:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=YxqQsDI0zFyuBn5mSvfS9/jBCh8E3c+8ydIfalKbHAQ=; b=oJKmrYaK9upxEeMXb1wBgLNXtYqNB2jVtyt8XbKBbaDrLI4zwr6LPYAZzwu4DbBgx2 HrsRJKGj0M+wtY2nSQqBl4ZignKVskScu+bEzruKyiNld0eT2ENbAaKFdNriVTt+UFzV 8AqmkD+PaOXycUw4l3nkSK4mdxG2snCjJMAFXDXb7OQZUxHwjeS5Rbix7xK+FW5/8Ykz o6A6NkMNmk4uc1aii3dAfe9K6kFjM0fTHamQqMRvKRXc04w0DTEsXQ3ShSRyuD/TSIB7 yAIBu0xK16PPXwRWsrX/SF+ESTHMkROmlzR4Vh60qebhzxeQoRULhk5OWJgcz9a0CJqC UZ/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=YxqQsDI0zFyuBn5mSvfS9/jBCh8E3c+8ydIfalKbHAQ=; b=femirNLgeSYT0xXtsGIoP8CCH+bO6z+DBjQhPrWiculDViaNwFP/zLODltMF/SUg8h ttw55Tyk4XusEUTEpSPp36T45LvaamgTTGwjfZ/1Um8xkRTXksZqF4hjuTwTZVp0v6Q/ fHTUOd2OWBtHhAJAllniMKecLVrBQGhbAwUZIFEwAqg1FGwknVhpAfitFiR+6m4xhQ6w /Eh+BdByuBnBeT4WCRpMckawCT0nVFqIK1oz1xnnl8hR/LfEqpFH8m8IpdDG9OGVYRmE cZeExhv+7VmxcH3bxEI6eMJ2qbe4wXu0+zszw9m0iwtyUz8pambyHR8OmZvGtftYL9Qg iJiw== X-Gm-Message-State: AOAM530I1L8Qt8IPlFCoQx3lDaDyM/y4heyWn024YW85ySqYCnnMZYw9 XVCyUTsPn8SXYAcgOPxOqjIm0p4SfIkBwA== X-Google-Smtp-Source: ABdhPJx60w4OnItFzNrndXHGVyRctp6I971TIQ5kvOen6LMduRyHkj20zMVpKOFwp6YyBeUhIdDefw== X-Received: by 2002:a17:90a:4083:: with SMTP id l3mr16651583pjg.109.1614588402668; Mon, 01 Mar 2021 00:46:42 -0800 (PST) Received: from localhost.localdomain ([2405:204:302d:d8af:c047:a272:aff7:4de6]) by smtp.googlemail.com with ESMTPSA id b34sm16781426pgl.63.2021.03.01.00.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 00:46:42 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: gitster@pobox.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v3 3/6] commit: add a reword suboption to --fixup Date: Mon, 1 Mar 2021 14:15:11 +0530 Message-Id: <20210301084512.27170-4-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210301084512.27170-1-charvi077@gmail.com> References: <20210301084512.27170-1-charvi077@gmail.com> Reply-To: 20210217072904.16257-1-charvi077@gmail.com MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git commit --fixup=reword:` creates an empty "amend!" commit that will reword without changing its contents when it is rebased with --autosquash. Apart from ignoring staged changes it works similarly to `--fixup=amend:`. Mentored-by: Christian Couder Mentored-by: Phillip Wood Helped-by: Junio C Hamano Signed-off-by: Charvi Mendiratta --- builtin/commit.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) -- 2.29.0.rc1 diff --git a/builtin/commit.c b/builtin/commit.c index 200ef83cc0..a4d18d96df 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1186,6 +1186,27 @@ 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) + die(_("cannot combine reword option of --fixup with --patch")); + if (interactive) + die(_("cannot combine reword option of --fixup with --interactive")); + if (all) + die(_("cannot combine reword option of --fixup with --all")); + if (also) + die(_("cannot combine reword option of --fixup with --include")); + if (only) + die(_("cannot combine reword option of --fixup with --only")); +} + /* returns the length of intial segment of alpha characters only */ static size_t get_alpha_len(char *fixup_message) { const char alphas[] = "abcdefghijklmnopqrstuvwxyz"; @@ -1270,18 +1291,25 @@ static int parse_and_validate_options(int argc, const char *argv[], if (fixup_message) { /* - * As `amend` suboption contains only alpha - * character. So check if first non alpha - * character in fixup_message is ':'. + * As `amend`/`reword` suboptions contains only alpha + * characters. So check if first non alpha character + * in fixup_message is ':'. */ size_t len = get_alpha_len(fixup_message); if (len && fixup_message[len] == ':') { fixup_message[len++] = '\0'; fixup_commit = fixup_message + len; - if (starts_with("amend", fixup_message)) + if (starts_with("amend", fixup_message) || + starts_with("reword", fixup_message)) { fixup_prefix = "amend"; - else + if (*fixup_message == 'r') { + check_fixup_reword_options(argc, argv); + allow_empty = 1; + only = 1; + } + } else { die(_("unknown option: --fixup=%s:%s"), fixup_message, fixup_commit); + } } else { fixup_commit = fixup_message; fixup_prefix = "fixup"; @@ -1567,10 +1595,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 . + * TRANSLATORS: Leave "[(amend|reword):]" as-is, + * and only translate . */ - 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")), From patchwork Mon Mar 1 08:45:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12109077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85C4EC433DB for ; Mon, 1 Mar 2021 08:50:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54A7264DF2 for ; Mon, 1 Mar 2021 08:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233666AbhCAIts (ORCPT ); Mon, 1 Mar 2021 03:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233545AbhCAIrk (ORCPT ); Mon, 1 Mar 2021 03:47:40 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1131C06121E for ; Mon, 1 Mar 2021 00:46:49 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id l2so11091738pgb.1 for ; Mon, 01 Mar 2021 00:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=5fAbtlR263x+jVai0ez7OLPSNnNsRFJly2JTIe69cYo=; b=HXAFyBPLN/SIuHaWmgBIJfBjHQ2tM+kb5u5+ulsiibKSrodC6LZnSBWq4JqPGdCQYN VFwmjIX64hCl8gOZ2Coi8wZybUELqHoBiAd3AP6P0M4A2Val8jR0u8BM5xQUlAcLW0Z0 DE2EoZfvbixzSPdVs8Gu7l80CiF9LUdxU73YjZgrRuSXSNpeC0wJwu1xLKnETMAkoIc2 2VRCJ8jATnqGnANFzZS2OwWPIdUkQXnX7eudUymYJgnLUyEQx09xAMZr9Ldwq4Nn0v6n DAjR0+vKOwXkVza1UVYv4F0f45I4k2vHRpdjIX9lH8ARz+TgMBDo+t6/UsgkGmBEJ/zQ 40uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=5fAbtlR263x+jVai0ez7OLPSNnNsRFJly2JTIe69cYo=; b=BOKmUTgp2lPY4XhXnCnGsIFko9zy3Bct/lRTteJxZLHqmsIf3DojaeF4cq+fRwDeK5 Vz+SeSL7bUpk2YsCd8SxY+c6Z9a+hdkNJ4rEbNkERhrfnTQfGmjJAK6vO3S6ilJsXGJu gFOe/TeInEYSn6eIhi/mIuTJVFcenEt8zP2cdFuWXzcgHtnUa54ewR0RcpthMIIub+Fr L8I+KmpTsq6EMqhQ5R5MY8CDn9tMVcB+CmoE9JNNmyYm0nkEUvKzfSwgrCZ4bvC+EuCx 6a8zfN1iMDdL5+NPUgXbtvp4LU/vi23rU/Cyjh7zQdyQhJXiiQP1b2ekPqOz+8EGVS9X +IdA== X-Gm-Message-State: AOAM531KLHYCd/M4QG1S8dyaFw3pFDdyr+EboLsr8zC56dkss46mYFes 6gxYvcBccUDS//NiEsiMA/YFvycknJfvAA== X-Google-Smtp-Source: ABdhPJyzpPg4+J017laNdE1xgW35BRpD5/ruEETY5R0VRTQXhZNhe44YSLpXNndA2cIOpm5GuZfjcw== X-Received: by 2002:aa7:84d4:0:b029:1ee:44a4:d29c with SMTP id x20-20020aa784d40000b02901ee44a4d29cmr12391185pfn.81.1614588409250; Mon, 01 Mar 2021 00:46:49 -0800 (PST) Received: from localhost.localdomain ([2405:204:302d:d8af:c047:a272:aff7:4de6]) by smtp.googlemail.com with ESMTPSA id b34sm16781426pgl.63.2021.03.01.00.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 00:46:48 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: gitster@pobox.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v3 4/6] t7500: add tests for --fixup=[amend|reword] options Date: Mon, 1 Mar 2021 14:15:12 +0530 Message-Id: <20210301084512.27170-5-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210301084512.27170-1-charvi077@gmail.com> References: <20210301084512.27170-1-charvi077@gmail.com> Reply-To: 20210217072904.16257-1-charvi077@gmail.com MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Mentored-by: Christian Couder Mentored-by: Phillip Wood Signed-off-by: Charvi Mendiratta --- t/t7500-commit-template-squash-signoff.sh | 135 ++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh index 6d19ece05d..e62b7fbc1a 100755 --- a/t/t7500-commit-template-squash-signoff.sh +++ b/t/t7500-commit-template-squash-signoff.sh @@ -9,6 +9,8 @@ Tests for template, signoff, squash and -F functions.' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + commit_msg_is () { expect=commit_msg_is.expect actual=commit_msg_is.actual @@ -279,6 +281,139 @@ test_expect_success 'commit --fixup -m"something" -m"extra"' ' extra" ' +get_commit_msg () { + rev="$1" && + git log -1 --pretty=format:"%B" "$rev" +} + +test_expect_success 'commit --fixup=amend: creates amend! commit' ' + commit_for_rebase_autosquash_setup && + cat >expected <<-EOF && + amend! $(git log -1 --format=%s HEAD~) + + $(get_commit_msg HEAD~) + + edited + EOF + ( + set_fake_editor && + FAKE_COMMIT_AMEND="edited" \ + git commit --fixup=amend:HEAD~ + ) && + get_commit_msg HEAD >actual && + test_cmp expected actual +' + +test_expect_success '--fixup=reword: does not commit staged changes' ' + commit_for_rebase_autosquash_setup && + cat >expected <<-EOF && + amend! $(git log -1 --format=%s HEAD~) + + $(get_commit_msg HEAD~) + + edited + EOF + ( + set_fake_editor && + FAKE_COMMIT_AMEND="edited" \ + git commit --fixup=reword:HEAD~ + ) && + get_commit_msg HEAD >actual && + test_cmp expected actual && + test_cmp_rev HEAD@{1}^{tree} HEAD^{tree} && + test_cmp_rev HEAD@{1} HEAD^ && + test_expect_code 1 git diff --cached --exit-code && + git cat-file blob :foo >actual && + test_cmp foo actual +' + +test_expect_success '--fixup=reword: error out with -m option' ' + commit_for_rebase_autosquash_setup && + echo "fatal: cannot combine -m with --fixup:reword" >expect && + test_must_fail git commit --fixup=reword:HEAD~ -m "reword commit message" 2>actual && + test_cmp expect actual +' + +test_expect_success '--fixup=amend: error out with -m option' ' + commit_for_rebase_autosquash_setup && + echo "fatal: cannot combine -m with --fixup:amend" >expect && + test_must_fail git commit --fixup=amend:HEAD~ -m "amend commit message" 2>actual && + test_cmp expect actual +' + +test_expect_success 'consecutive amend! commits remove amend! line from commit msg body' ' + commit_for_rebase_autosquash_setup && + cat >expected <<-EOF && + amend! amend! $(git log -1 --format=%s HEAD~) + + $(get_commit_msg HEAD~) + + edited 1 + + edited 2 + EOF + echo "reword new commit message" >actual && + ( + set_fake_editor && + FAKE_COMMIT_AMEND="edited 1" \ + git commit --fixup=reword:HEAD~ && + FAKE_COMMIT_AMEND="edited 2" \ + git commit --fixup=reword:HEAD + ) && + get_commit_msg HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'deny to create amend! commit if its commit msg body is empty' ' + commit_for_rebase_autosquash_setup && + echo "Aborting commit due to empty commit message body." >expected && + ( + set_fake_editor && + test_must_fail env FAKE_COMMIT_MESSAGE="amend! target message subject line" \ + git commit --fixup=amend:HEAD~ 2>actual + ) && + test_cmp expected actual +' + +test_expect_success 'amend! commit allows empty commit msg body with --allow-empty-message' ' + commit_for_rebase_autosquash_setup && + cat >expected <<-EOF && + amend! $(git log -1 --format=%s HEAD~) + EOF + ( + set_fake_editor && + FAKE_COMMIT_MESSAGE="amend! target message subject line" \ + git commit --fixup=amend:HEAD~ --allow-empty-message && + get_commit_msg HEAD >actual + ) && + test_cmp expected actual +' + +test_fixup_reword_opt () { + test_expect_success C_LOCALE_OUTPUT "--fixup=reword: incompatible with $1" " + echo 'fatal: cannot combine reword option of --fixup with $1' >expect && + test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual && + test_cmp expect actual + " +} + +for opt in --all --include --only --interactive --patch +do + test_fixup_reword_opt $opt +done + +test_expect_success '--fixup=reword: give error with pathsec' ' + commit_for_rebase_autosquash_setup && + echo "fatal: cannot combine reword option of --fixup with path foo" >expect && + test_must_fail git commit --fixup=reword:HEAD~ -- foo 2>actual && + test_cmp expect actual +' + +test_expect_success '--fixup=reword: -F give error message' ' + echo "fatal: Only one of -c/-C/-F/--fixup can be used." >expect && + test_must_fail git commit --fixup=reword:HEAD~ -F msg 2>actual && + test_cmp expect actual +' test_expect_success 'commit --squash works with -F' ' commit_for_rebase_autosquash_setup && From patchwork Mon Mar 1 08:45:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12109075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E3E7C433E9 for ; Mon, 1 Mar 2021 08:50:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6321664DE0 for ; Mon, 1 Mar 2021 08:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbhCAItS (ORCPT ); Mon, 1 Mar 2021 03:49:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233549AbhCAIrk (ORCPT ); Mon, 1 Mar 2021 03:47:40 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2DCCC06174A for ; Mon, 1 Mar 2021 00:46:55 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id i10so1843482pfk.4 for ; Mon, 01 Mar 2021 00:46:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=ZqyQqnN/r9Yp2nVabx5VAmks8N5fv9M2AVAwzn2f2LI=; b=B0LL4ZPultqRwEOXcX6CaD4kb3TBq75/xZ+23Uq+zQj3oj3pOtnx+w9CasSc9vtJik vnKXTvEx9lB9FTmj9gyPXVYR9WRflF0LhwowxQgB/950d8UDhwSWAaDKXlTxa5qIE2zF /0h5Yz5/5DHpUnbn4/qGwV1q96Omk2j5zes+269HaPc79UuBYexzjdKx2OYvdHOKdtWv 94XMpOnJYwRbcknEGooDATMccZocOF39JceC497W6D53yR6JH0zqVx6SRNinhCcFR8Ni CEpTvNCgQLFsHx4sIM8DA20Clq38UQtCTXOWjzMirnntpWCXO7+/FY/Fr/w3pst+QpwV YXdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=ZqyQqnN/r9Yp2nVabx5VAmks8N5fv9M2AVAwzn2f2LI=; b=a2pkaGzSUj6ldgQdwVQvTLAK27qko5aEVoTtMhLe2Nlu/HvX+zp6G3TEEbZ58Nl1L9 ZdIv5rv8QOZeQBNO0tRH6PcDyu9WyvCL3FP+gMd63OtLAZy9Z2hgJeZm9ddqaM1NqkeB f6aFMjilXiN8bLCrBN46DEVN4lFkn0atybgW3TICU9n0bTCVeUK2ywYko7OSMcUeaTc9 nm9nhVt0wa4jVtc8fFXy65DleZZuLc9GHfetiTGropIGD6VMxT4laFTjylRSB3D/A2Zv 7uKXW2nx+lKWNFNaA16qxLTEipPO0qdGcScprt5rJOQn5iQSJMtXjHIdvzfSraZMzkk1 4y/A== X-Gm-Message-State: AOAM531GzPoRBF9jDAN2mMpeq7qdL9aF4kh57NdOMCLDI8Eg8iJeCg2r YqX+RDCYfjeciKQscvKvxaRTnbqnaCQ0BQ== X-Google-Smtp-Source: ABdhPJzJhPf8KlCAountqotwyDBkwvGpJeugP+o1oAf9QfrGUYn5BYX+bM9IP5k+JmaO+Wtsk64XWA== X-Received: by 2002:a05:6a00:a95:b029:1ee:471f:e323 with SMTP id b21-20020a056a000a95b02901ee471fe323mr11307770pfl.69.1614588415319; Mon, 01 Mar 2021 00:46:55 -0800 (PST) Received: from localhost.localdomain ([2405:204:302d:d8af:c047:a272:aff7:4de6]) by smtp.googlemail.com with ESMTPSA id b34sm16781426pgl.63.2021.03.01.00.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 00:46:55 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: gitster@pobox.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v3 5/6] t3437: use --fixup with options to create amend! commit Date: Mon, 1 Mar 2021 14:15:13 +0530 Message-Id: <20210301084512.27170-6-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210301084512.27170-1-charvi077@gmail.com> References: <20210301084512.27170-1-charvi077@gmail.com> Reply-To: 20210217072904.16257-1-charvi077@gmail.com MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We taught `git commit --fixup` to create "amend!" commit. Let's also update the tests and use it to setup the rebase tests. Mentored-by: Christian Couder Mentored-by: Phillip Wood Signed-off-by: Charvi Mendiratta --- t/t3437-rebase-fixup-options.sh | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh index a5a20354e3..d0bdc7ed02 100755 --- a/t/t3437-rebase-fixup-options.sh +++ b/t/t3437-rebase-fixup-options.sh @@ -72,40 +72,16 @@ test_expect_success 'setup' ' git commit --fixup=HEAD -a && git tag B1 && test_tick && - git commit --allow-empty -F - <<-EOF && - amend! B - $EMPTY - B - $EMPTY - edited 1 - EOF + FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B && test_tick && - git commit --allow-empty -F - <<-EOF && - amend! amend! B - $EMPTY - B - $EMPTY - edited 1 - $EMPTY - edited 2 - EOF + FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD && echo B2 >B && test_tick && FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a && git tag B2 && echo B3 >B && test_tick && - git commit -a -F - <<-EOF && - amend! amend! amend! B - $EMPTY - B - $EMPTY - edited 1 - $EMPTY - edited 2 - $EMPTY - edited 3 - EOF + FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ && git tag B3 && GIT_AUTHOR_NAME="Rebase Author" && From patchwork Mon Mar 1 08:45:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12109081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F700C433DB for ; Mon, 1 Mar 2021 08:51:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3DBA64DF5 for ; Mon, 1 Mar 2021 08:51:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233574AbhCAIuq (ORCPT ); Mon, 1 Mar 2021 03:50:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbhCAIsF (ORCPT ); Mon, 1 Mar 2021 03:48:05 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D311C061221 for ; Mon, 1 Mar 2021 00:47:01 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id 201so11019705pfw.5 for ; Mon, 01 Mar 2021 00:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=fu9Li6f2BXPvbJPvP3/+R8Hby4Jd/CBBLZZ/FboEsTg=; b=fCROvi4It/Z4qkJQhzw6i8Ot0FofmosxhIHYTZa1vfNMdJ9fVm0yBFpHqBfMqQx6Z+ N9Hjbgithzk7r5j8HnaiuuaHg32UUKgG/+hmAYjCLZazveq4cPTd2P9YLH5FjvgvBXyL G0eh86p3iNCDSrcoq3Mfu5V3nfqqJdeUe/jEmGLsapwmTJn/Qt4mOOsu20nHjdmLe4Xt SYUvrBJp7ZS7dxySkgO+yT/P4Hg9HuPdpv/6mlrveDDd8+cAnP6Ee6+CCzjzthtfIwMU RP53MuMb0QC+lpTAdL6e+ujoYgQN2qXD2O/0EivbBiXmKtx5CuroR8z+qNVSiCwcQb0Y JBAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=fu9Li6f2BXPvbJPvP3/+R8Hby4Jd/CBBLZZ/FboEsTg=; b=PKIz/xbPwwdz+65bTFdOjums0H8aEP8GZzmyyyX3L9Iu9XYpwp8K4ZHD5MmPlNaRnh TYAl+++ce68Kxhjxrac3kozYdjaYRw6uA30c8Qq16f+HWFyfwGdJVp/WdFJoikHOW5eV BSO0ubaCd6t45rFA5MSnGYOuurHm4KRvcIcYa7QxcDru/JAsp8Z82oWDTiGjT3LRBjAU SPbw3XkQ4lqid5qGcDHaZoPPkJLOi4fWIDUFw/7pySPMpdB7a3sWgYa3qd1/bRrOuxXJ OBrdaaCEBW01bPcCCjnHezMyxPw5oDipIdweuleWCXM+lRkbR60wX55gHBa4UYnhXp0o CDwQ== X-Gm-Message-State: AOAM533dqXHYERuQwY9c1xuKT0rKii8Glwv4oeDnJBQJJX9tWnE54DM/ G/tTZ9NoW7KBbkYtq1nOjjFDj7m1LpU4cw== X-Google-Smtp-Source: ABdhPJxjah1iTr1rRKWsMPlvTRGhNGasnmKPt0CiUGZhdXMadmj6lxBNmZme/dzNpOku4BkDwBM/NA== X-Received: by 2002:a65:44c5:: with SMTP id g5mr13111358pgs.295.1614588420994; Mon, 01 Mar 2021 00:47:00 -0800 (PST) Received: from localhost.localdomain ([2405:204:302d:d8af:c047:a272:aff7:4de6]) by smtp.googlemail.com with ESMTPSA id b34sm16781426pgl.63.2021.03.01.00.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 00:47:00 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: gitster@pobox.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v3 6/6] doc/git-commit: add documentation for fixup=[amend|reword] options Date: Mon, 1 Mar 2021 14:15:14 +0530 Message-Id: <20210301084512.27170-7-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210301084512.27170-1-charvi077@gmail.com> References: <20210301084512.27170-1-charvi077@gmail.com> Reply-To: 20210217072904.16257-1-charvi077@gmail.com MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Mentored-by: Christian Couder Mentored-by: Phillip Wood Helped-by: Junio C Hamano Signed-off-by: Charvi Mendiratta --- Documentation/git-commit.txt | 40 ++++++++++++++++++++++++++++++------ Documentation/git-rebase.txt | 21 ++++++++++--------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 17150fa7ea..722f8f0a6d 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'git commit' [-a | --interactive | --patch] [-s] [-v] [-u] [--amend] - [--dry-run] [(-c | -C | --fixup | --squash) ] + [--dry-run] [(-c | -C | --squash) | --fixup [(amend|reword):])] [-F | -m ] [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=] [--date=] [--cleanup=] [--[no-]status] @@ -86,11 +86,39 @@ OPTIONS Like '-C', but with `-c` the editor is invoked, so that the user can further edit the commit message. ---fixup=:: - Construct a commit message for use with `rebase --autosquash`. - The commit message will be the subject line from the specified - commit with a prefix of "fixup! ". See linkgit:git-rebase[1] - for details. +--fixup=[(amend|reword):]:: + Without `amend:` or `reword:`, create a `fixup!` commit where + the commit message will be the subject line from the specified + commit with a prefix of "fixup!'". The resulting "fixup!" commit + is further used with `git rebase --autosquash` to fixup the + content of the specified commit. ++ +The `--fixup=amend:` form creates an "amend!" commit to +fixup both the content and the commit log message of the specified +commit. The resulting "amend!" commit's commit message subject +will be the subject line from the specified commit with a prefix of +"amend!'" and the message body will be commit log message of the +specified commit. It also invokes an editor seeded with the log +message of the "amend!" commit to allow to edit further. And it +refuses to create "amend!" commit if it's commit message body is +empty unless used with the `--allow-empty-message` option. "amend!" +commit when rebased with `--autosquash` will fixup the contents and +replace the commit message of the specified commit with the "amend!" +commit's message body. ++ +The `--fixup=reword:` form creates an "amend!" commit similar +to `--fixup=amend:` creates, but it records the same tree as +`HEAD`, i.e. it does not take any staged changes and only allows to +fixup the commit message of the specified commit. It will reword the +specified commit when it is rebased with `--autosquash`. ++ +The `--fixup=amend:` and `--fixup=reword:` forms cannot be used with +other options to add to the commit log message i.e it is incompatible +with `-m`/`-F`/`-c`/`-C` options. ++ +Also, after fixing the commit using `--fixup`, with or without option +and rebased with `--autosquash`, the authorship of the original commit +remains unchanged. See linkgit:git-rebase[1] for details. --squash=:: Construct a commit message for use with `rebase --autosquash`. diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 8bfa5a9272..ffea76e53b 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -593,16 +593,17 @@ See also INCOMPATIBLE OPTIONS below. --autosquash:: --no-autosquash:: - When the commit log message begins with "squash! ..." (or - "fixup! ..."), and there is already a commit in the todo list that - matches the same `...`, automatically modify the todo list of rebase - -i so that the commit marked for squashing comes right after the - commit to be modified, and change the action of the moved commit - from `pick` to `squash` (or `fixup`). A commit matches the `...` if - the commit subject matches, or if the `...` refers to the commit's - hash. As a fall-back, partial matches of the commit subject work, - too. The recommended way to create fixup/squash commits is by using - the `--fixup`/`--squash` options of linkgit:git-commit[1]. + When the commit log message begins with "squash! ..." (or "fixup! ..." + or "amend! ..."), and there is already a commit in the todo list that + matches the same `...`, automatically modify the todo list of + `rebase -i`, so that the commit marked for squashing comes right after + the commit to be modified, and change the action of the moved commit + from `pick` to `squash` (or `fixup` or `fixup -C`) respectively. A commit + matches the `...` if the commit subject matches, or if the `...` refers + to the commit's hash. As a fall-back, partial matches of the commit + subject work, too. The recommended way to create fixup/squash/amend + commits is by using the `--fixup=[amend|reword]`/`--squash` options of + linkgit:git-commit[1]. + If the `--autosquash` option is enabled by default using the configuration variable `rebase.autoSquash`, this option can be