From patchwork Thu Feb 4 19:05:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068405 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 63A3AC433E0 for ; Thu, 4 Feb 2021 19:06:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2406A64E3F for ; Thu, 4 Feb 2021 19:06:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239606AbhBDTGt (ORCPT ); Thu, 4 Feb 2021 14:06:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239589AbhBDTGS (ORCPT ); Thu, 4 Feb 2021 14:06:18 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A170C061786 for ; Thu, 4 Feb 2021 11:05:38 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id t25so2792346pga.2 for ; Thu, 04 Feb 2021 11:05:38 -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 :mime-version:content-transfer-encoding; bh=cVwqRHiCPVOdFvi8BGeDd6ox9vceEwe8HnBQfQjgJgU=; b=lMmcCy+DoREI0RIUPtepKBf2zlKTqeEY98vFReWJEJ4AvnAgxD70EbbRFLQrefVeSn 9RkX+Ve84NKzq8TVkR5HUfZn8kb+pNka06jBukE3ZHtq1O240HbJAeTHiuE30aRGfJYH perFwP3AavZBWiYJnZe4rh1fjiXseJ24UVXO0h1E6jfEStVPpzmqR+MAhunSubb998AS U6qNcOt12U3/T2a72sQ9TujWwDk/mn+VkAKxpC53hNpARuTumsCAyBQ8xi4J7mTIWLwg cR9U22vDtLDCw0PQC9CYBqN+QREh4WeIlWunDNnoZAnZBoaszittD0pJp53BZ+D0dDzM GcGA== 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:mime-version:content-transfer-encoding; bh=cVwqRHiCPVOdFvi8BGeDd6ox9vceEwe8HnBQfQjgJgU=; b=YJJt0urewa775Z0Gr7ayfiq7iB9uPwKTp+Qvs4Sv5kqtZ+x5T7W/PKsgZZPDSwcCdt lJAkz83KrOf6zjCG8PjkRrO24UyExUuoIhZFnTZF8NN8qnrx2sqas512FgLImuHv/waX t5zk2J7N6o00PmEollFqQqRPebpgBV+6323hqEDr6n3G1mfiqC8agPWv3O8qt437HK+X 7uQ23XJ7OPH/5zAyAe8qK3ggFDtDYTLk9vy3aE7j4B59Te59GrdNxuZRRJhAXWkU7g99 KJxWLy+9F6KelNZ8uM/FMNn/fhMeHgfxKbCtbhsa53EMEfKa9CeVYBhruJPCiYwyEx8o g6aA== X-Gm-Message-State: AOAM533155J/qgnGEFD2MF/94XcBd6M40xIv/4EUjkUAqCffzGy5EIrZ io6CidxHvA71lmxSj//dV2iHePFr/AS19A== X-Google-Smtp-Source: ABdhPJzid7q98EphW2D9r5VmB5qVdyo/iqZEyoSWdnjmtu0sUmWbf5X4crkIl/cKwjpoJgPJmPloMQ== X-Received: by 2002:a63:1f1e:: with SMTP id f30mr432789pgf.141.1612465537971; Thu, 04 Feb 2021 11:05:37 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:05:37 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Phillip Wood , Taylor Blau , Charvi Mendiratta Subject: [PATCH v5 1/8] rebase -i: only write fixup-message when it's needed Date: Fri, 5 Feb 2021 00:35:00 +0530 Message-Id: <20210204190507.26487-2-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted. Signed-off-by: Phillip Wood Reviewed-by: Taylor Blau Signed-off-by: Charvi Mendiratta --- sequencer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index 8909a46770..a59e0c84af 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1757,11 +1757,10 @@ static int update_squash_messages(struct repository *r, return error(_("could not read HEAD's commit message")); find_commit_subject(head_message, &body); - if (write_message(body, strlen(body), - rebase_path_fixup_msg(), 0)) { + if (command == TODO_FIXUP && write_message(body, strlen(body), + rebase_path_fixup_msg(), 0) < 0) { unuse_commit_buffer(head_commit, head_message); - return error(_("cannot write '%s'"), - rebase_path_fixup_msg()); + return error(_("cannot write '%s'"), rebase_path_fixup_msg()); } strbuf_addf(&buf, "%c ", comment_line_char); From patchwork Thu Feb 4 19:05:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068413 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 D65F1C433E6 for ; Thu, 4 Feb 2021 19:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C64A64F5E for ; Thu, 4 Feb 2021 19:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239567AbhBDTH1 (ORCPT ); Thu, 4 Feb 2021 14:07:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239599AbhBDTGd (ORCPT ); Thu, 4 Feb 2021 14:06:33 -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 F17C4C061788 for ; Thu, 4 Feb 2021 11:05:52 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id u11so2240703plg.13 for ; Thu, 04 Feb 2021 11:05:52 -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 :mime-version:content-transfer-encoding; bh=wq7AT0GeWUiw6/y3jlwDs7feIY/g4Gw8ax680CWXrw4=; b=O3TXXPqr/zkrOUNjQARBZo1pkywe83PxUSbUTrZxg2HvRoOpQak2IVRGtEDHsoC17o d9JqOl3AG+BRRRUt3AqOywDJzOuZ8EBQlYYHuLcEuhj8aZ9uiNsxizBP2Q8xkxNehsp8 RGF4ev0P9x5XXWDXw0WxY5IUc5OXQRYzHEZ4HWF0Lwu0ULBe+Nn7zvohhweEld9o1qsC uix6dr2DrsHuxVoY+CIwouJo1972pv/lzZqVVprMM8Yyos85Vm7PuioDT/Bbtvc7YThB gngNliPQgw1dNBJTLGqwGhaprj/ywTfE6yQffVfnIqsvmonck16WOjybOs91uWLDVhHF 5JrQ== 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:mime-version:content-transfer-encoding; bh=wq7AT0GeWUiw6/y3jlwDs7feIY/g4Gw8ax680CWXrw4=; b=OksUPBDqvJ8Yk2hSNIXQcFCdWtLVLigXXFHIHipJkXtDpM/ZU3ONDRDXLJIdGkiMH8 ugB9Q8UL8INt7ZqCy26bq61sOKpocYS3QaNYdCfQB8vKBntwSFhXZIi7cU3OmrONMEzD gxWzT+Bqri0jBdiUsxNShShwNRxBEY3Qi58KNuNkwtAalfOYyXdbk1b7HtEi/HTZ2vNs vfw2UqrCLaQigkgzqR8z+5hIdIaqe8/8MPdOfa0cUfpcx6KXk0fCcltVvlAl0gwcbldE x4Pyqh0qBvoen1V5NlJoMmfF3jhgy7/njN8TmxA4rkhI0PND4Hohpt0H28CH/HdrNjgf EZvQ== X-Gm-Message-State: AOAM532jeXf6SfmvNTSL9+dNWsR6jLJYycTE3fcGwKbcLNeUyPzwFdiJ LXAKgwT8xdmqVPQGHrTSRuV+0ACh3tsImQ== X-Google-Smtp-Source: ABdhPJyG5nA8AWV8ENxUuBnc8cVXx5pCwavCuys2oUhu/ZygWI0cde6IvxpxBg8lp8QyN26DgndY0w== X-Received: by 2002:a17:90a:170f:: with SMTP id z15mr389909pjd.63.1612465552425; Thu, 04 Feb 2021 11:05:52 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:05:52 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Phillip Wood , Charvi Mendiratta Subject: [PATCH v5 2/8] sequencer: factor out code to append squash message Date: Fri, 5 Feb 2021 00:35:01 +0530 Message-Id: <20210204190507.26487-3-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood This code is going to grow over the next two commits so move it to its own function. Signed-off-by: Phillip Wood Signed-off-by: Charvi Mendiratta --- sequencer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sequencer.c b/sequencer.c index a59e0c84af..08cce40834 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1718,6 +1718,17 @@ static int is_pick_or_similar(enum todo_command command) } } +static void append_squash_message(struct strbuf *buf, const char *body, + struct replay_opts *opts) +{ + unlink(rebase_path_fixup_msg()); + strbuf_addf(buf, "\n%c ", comment_line_char); + strbuf_addf(buf, _("This is the commit message #%d:"), + ++opts->current_fixup_count + 1); + strbuf_addstr(buf, "\n\n"); + strbuf_addstr(buf, body); +} + static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit, @@ -1779,12 +1790,7 @@ static int update_squash_messages(struct repository *r, find_commit_subject(message, &body); if (command == TODO_SQUASH) { - unlink(rebase_path_fixup_msg()); - strbuf_addf(&buf, "\n%c ", comment_line_char); - strbuf_addf(&buf, _("This is the commit message #%d:"), - ++opts->current_fixup_count + 1); - strbuf_addstr(&buf, "\n\n"); - strbuf_addstr(&buf, body); + append_squash_message(&buf, body, opts); } else if (command == TODO_FIXUP) { strbuf_addf(&buf, "\n%c ", comment_line_char); strbuf_addf(&buf, _("The commit message #%d will be skipped:"), From patchwork Thu Feb 4 19:05:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068407 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 5E1A1C433DB for ; Thu, 4 Feb 2021 19:07:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 225C064F65 for ; Thu, 4 Feb 2021 19:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239602AbhBDTHc (ORCPT ); Thu, 4 Feb 2021 14:07:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239603AbhBDTGl (ORCPT ); Thu, 4 Feb 2021 14:06:41 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F28ACC06178C for ; Thu, 4 Feb 2021 11:06:00 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id i7so2767416pgc.8 for ; Thu, 04 Feb 2021 11:06:00 -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 :mime-version:content-transfer-encoding; bh=EfYYnHwUIihEh7v3AmkOo7Bl1PLcpbzVNEik165bR84=; b=Tz8Qt1vZwy025OMRlR3DuwazDbjqN9g1fdyy/6mmdDBL3iaQwuInCZ3H0HlwQ3CZR+ podE6X5qXi8kalLP6rkmE1Xn2uviGfrTrff8s+jkNjYbqauC9MwbPjop7O1owC/GTU9u J2rR/UwvHjX4CUyjSOwbGfUVWnDIQEe4L3gqf+jeLl7T59HMsApWDdga0B97fiHOjYA1 1N7UVP69uYwRiImNtb+q/dR2hbP9QI3GlNY0b1bwrXEpO1Ov373/ci9Z3cuxGx2tp715 c1RAGXa6wGZleZk82tM/GJ4ZhjM8B3AIdvbz77Kwl/SYaFeHW+EYt1+kFSTBYqCIPU8c cAAw== 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:mime-version:content-transfer-encoding; bh=EfYYnHwUIihEh7v3AmkOo7Bl1PLcpbzVNEik165bR84=; b=tBLVd9nzdlMU3ubmLE/nQ0SWBA1wK4pI6Tw9M557D+GsEO51wqw6+E590ejmK2VkxT bbobgowBxRb7LcDZjToS4V4ORcFl0K4VkpNjPJlzsuLIWTEQaHsfzWBUnWPN+Ik46GKP Kt2W0U/VmMPcfG+/cbqKhYOg42aUcvWASXmhoUDmXPVHqfFHDyszhlCCRDmcHOmDTwNB bU7qnaL9xj47Lv9AcDm009YBFK+/fBKkGnzxr+feRjldpVNnIBMwUmQ7YnZuavQlVF1s YNGwcXMVXG4a7ZdZP9KJWQd1tw2maPXBVmghx1PHaf0q1sGTAusEqIRCUnPRPDU50TR3 EEbw== X-Gm-Message-State: AOAM532LSD8xIYt8CVATaOdu2CgaCXf+jQ3ou+1Zmpk/V3gcpl4xaWvp 6ZfFmsIwl/cLU6J4k2LlghDqJQHlB4DqUw== X-Google-Smtp-Source: ABdhPJxgbeqeoN+p8viBb7olM3s2itHaHsm7jiHyNsll7uJCbCBRBI3gsI4cxD/aVsl9hFr+eWSrKw== X-Received: by 2002:a65:6450:: with SMTP id s16mr412773pgv.71.1612465560282; Thu, 04 Feb 2021 11:06:00 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:05:59 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Phillip Wood , Taylor Blau , Charvi Mendiratta Subject: [PATCH v5 3/8] rebase -i: comment out squash!/fixup! subjects from squash message Date: Fri, 5 Feb 2021 00:35:02 +0530 Message-Id: <20210204190507.26487-4-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message. This change breaks a bunch of --autosquash tests which rely on the "squash! " line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that. Signed-off-by: Phillip Wood Reviewed-by: Taylor Blau Signed-off-by: Charvi Mendiratta --- sequencer.c | 21 ++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 30 ++++++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/sequencer.c b/sequencer.c index 08cce40834..034149f24d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1718,15 +1718,34 @@ static int is_pick_or_similar(enum todo_command command) } } +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 void append_squash_message(struct strbuf *buf, const char *body, struct replay_opts *opts) { + size_t commented_len = 0; + unlink(rebase_path_fixup_msg()); + if (starts_with(body, "squash!") || starts_with(body, "fixup!")) + commented_len = subject_length(body); strbuf_addf(buf, "\n%c ", comment_line_char); strbuf_addf(buf, _("This is the commit message #%d:"), ++opts->current_fixup_count + 1); strbuf_addstr(buf, "\n\n"); - strbuf_addstr(buf, body); + strbuf_add_commented_lines(buf, body, commented_len); + strbuf_addstr(buf, body + commented_len); } static int update_squash_messages(struct repository *r, diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh index e7087befd4..78cc2260cc 100755 --- a/t/t3415-rebase-autosquash.sh +++ b/t/t3415-rebase-autosquash.sh @@ -84,8 +84,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" && git tag $1 && test_tick && git rebase $2 -i HEAD^^^ && @@ -142,7 +141,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 && @@ -195,7 +194,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ && @@ -206,7 +205,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual ' @@ -216,7 +216,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git add -u && test_tick && oid=$(git rev-parse --short=11 HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-longshasquash && test_tick && git rebase --autosquash -i HEAD^^^ && @@ -227,7 +227,8 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual ' @@ -236,7 +237,7 @@ test_auto_commit_flags () { echo 1 >file1 && git add -u && test_tick && - git commit --$1 first-commit && + git commit --$1 first-commit -m "extra para for first" && git tag final-commit-$1 && test_tick && git rebase --autosquash -i HEAD^^^ && @@ -264,11 +265,11 @@ test_auto_fixup_fixup () { echo 1 >file1 && git add -u && test_tick && - git commit -m "$1! first" && + git commit -m "$1! first" -m "extra para for first" && echo 2 >file1 && git add -u && test_tick && - git commit -m "$1! $2! first" && + git commit -m "$1! $2! first" -m "second extra para for first" && git tag "final-$1-$2" && test_tick && ( @@ -329,12 +330,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para for first" && echo 1 >file1 && git add -u && test_tick && subject=$(git log -n 1 --format=%s HEAD~2) && - git commit -m "squash! $subject" && + git commit -m "squash! $subject" -m "second extra para for first" && git tag final-squash-instFmt && test_tick && git rebase --autosquash -i HEAD~4 && @@ -345,8 +346,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + ! grep "squash" commit && + grep first commit >actual && + test_line_count = 3 actual ' test_expect_success 'autosquash with empty custom instructionFormat' ' diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index d277a9f4b7..bfab245eb3 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - if test $flag = squash; then - subject="$(head -1 expect)" && - printf "\nsquash! %s\n" "$subject" >>expect - fi && git cat-file commit HEAD^ >raw && (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && test_cmp expect actual From patchwork Thu Feb 4 19:05:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068419 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 51713C433E6 for ; Thu, 4 Feb 2021 19:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00B9164F64 for ; Thu, 4 Feb 2021 19:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239635AbhBDTIy (ORCPT ); Thu, 4 Feb 2021 14:08:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239604AbhBDTGs (ORCPT ); Thu, 4 Feb 2021 14:06:48 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C564C061793 for ; Thu, 4 Feb 2021 11:06:08 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id m6so2718497pfk.1 for ; Thu, 04 Feb 2021 11:06:08 -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 :mime-version:content-transfer-encoding; bh=AKNDGS89h3BP7A+kc9sS7Cfxp6AlmTx76lu6cpG0xto=; b=pjeD/5iII+wpd7eXuoJNZwQSxNEFcfUWISfFq8PAUkmz8o2JVc+0cj1OxJWsTH6dIu PmYfmp2dF0ELOU1W6X/Y4xhORiyGYsEur+WIuJfxuvZ9Nsz181rYFzu9PZPloFOzSh8s CuFXTdALzGIWW28BX/vAKsL7X+JCr4xhzwXV1yEYw4OMkbDkqImLLj9R1F8mRUqmvDlI y3yj2gqC7jE62pEnf/ol5tTVIyELbAuPdT5se1h9JGbHn/6tbKfG0ac3YEg0IF/YCBnp leblpxbpQ+StjH843RPxwZ/94x+uD4LFWtu63oT5G0WhAVK0t/b7rvhBCyt0VPn8Kovg hCvA== 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:mime-version:content-transfer-encoding; bh=AKNDGS89h3BP7A+kc9sS7Cfxp6AlmTx76lu6cpG0xto=; b=D7PzDWh9b6oTg1Zhiz8usRj1I/JvVeJgQoHtx6nbSv/QOPLirBGrv1TM7dOiEN15rK HvJ8G4Q49AccbZ/PDOvWugSJozKj023G1jEBJIQ7b9yVbfYEQRKgw7cGj2sjuQvL7k87 BJjlgeLE0AKmbeNmKoBwcYrAAhYH3VjcXBkug9rR71Erf5szsED+0P3rtmAugOght8ue YX7rIZhAXlOhqTO7Anlh1gzyPt/nY32lKDhzYf60FKjdS9KgjGni58D3UU37CwBI8oJ3 nocYGbXIUDFkiWQEpvd4aDihrXQpo9widkq/cOh5hpQU59FvFp0DJA6jLkGQStUtHcfm hMFg== X-Gm-Message-State: AOAM533qmR8KfyUfDwWsRvcxyCuIs7vSxieskl6ziGEVRHmC8Mo2Nypc P+9bt0G4Bs7pfJwWIcaXCj1MfF0n7aOKJw== X-Google-Smtp-Source: ABdhPJy68903wyaVx/fdHUFC9ijaZzRz482ebjCTkbOoqcc1q/VZU43F28n9kl2eZTRFeNTWWFjDBA== X-Received: by 2002:a63:9811:: with SMTP id q17mr452755pgd.238.1612465567398; Thu, 04 Feb 2021 11:06:07 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:06:06 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood Subject: [PATCH v5 4/8] sequencer: pass todo_item to do_pick_commit() Date: Fri, 5 Feb 2021 00:35:03 +0530 Message-Id: <20210204190507.26487-5-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As an additional member of the structure todo_item will be required in future commits pass the complete structure. Mentored-by: Christian Couder Mentored-by: Phillip Wood Signed-off-by: Charvi Mendiratta --- sequencer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sequencer.c b/sequencer.c index 034149f24d..09cbb17f87 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1877,8 +1877,7 @@ static void record_in_rewritten(struct object_id *oid, } static int do_pick_commit(struct repository *r, - enum todo_command command, - struct commit *commit, + struct todo_item *item, struct replay_opts *opts, int final_fixup, int *check_todo) { @@ -1891,6 +1890,8 @@ static int do_pick_commit(struct repository *r, struct commit_message msg = { NULL, NULL, NULL, NULL }; struct strbuf msgbuf = STRBUF_INIT; int res, unborn = 0, reword = 0, allow, drop_commit; + enum todo_command command = item->command; + struct commit *commit = item->commit; if (opts->no_commit) { /* @@ -4140,8 +4141,8 @@ static int pick_commits(struct repository *r, setenv(GIT_REFLOG_ACTION, reflog_message(opts, command_to_string(item->command), NULL), 1); - res = do_pick_commit(r, item->command, item->commit, - opts, is_final_fixup(todo_list), + res = do_pick_commit(r, item, opts, + is_final_fixup(todo_list), &check_todo); if (is_rebase_i(opts)) setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1); @@ -4603,11 +4604,14 @@ static int single_pick(struct repository *r, struct replay_opts *opts) { int check_todo; + struct todo_item item; + + item.command = opts->action == REPLAY_PICK ? + TODO_PICK : TODO_REVERT; + item.commit = cmit; setenv(GIT_REFLOG_ACTION, action_name(opts), 0); - return do_pick_commit(r, opts->action == REPLAY_PICK ? - TODO_PICK : TODO_REVERT, cmit, opts, 0, - &check_todo); + return do_pick_commit(r, &item, opts, 0, &check_todo); } int sequencer_pick_revisions(struct repository *r, From patchwork Thu Feb 4 19:05:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068415 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 232EFC433E0 for ; Thu, 4 Feb 2021 19:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE70064F6D for ; Thu, 4 Feb 2021 19:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239623AbhBDTIu (ORCPT ); Thu, 4 Feb 2021 14:08:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239499AbhBDTG4 (ORCPT ); Thu, 4 Feb 2021 14:06:56 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 121B9C06178B for ; Thu, 4 Feb 2021 11:06:16 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id e9so2373321pjj.0 for ; Thu, 04 Feb 2021 11:06:16 -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 :mime-version:content-transfer-encoding; bh=+sN6HX1BqV3b1XdRd5cbt+4ED2RdKrpGKUBRJZU//UU=; b=atoDgMo1NlC5ButhDWWDRfByAcbcXC771zKISW14XpuET+8BiHV3cGmxAy/LqQXVlS gcqsjP/E/yUjGltkMSlHhZiPwjW+KLnKg4fPzkRehpca2VP8XGjZmj1MGLbe6aKc8EpN z9EbNtPwxCtJPp/gLfUiCos/E1NQvzbPelSxgMgaQQubMWAbH82TfeSTL/3kT+pmSRDr ckxT6WJqYNhFiBFiE4a/lBxV3VJ4TGqpmY1wEkok6Gj+6Ps7sOVGWexB5enbitehgeNy G7ENWAfDxV3VrMHK3koGNQ1LaHRsTCsetehmC+xCjy05KmFeVV0cEVT7gXN6cffxRdMt h+4A== 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:mime-version:content-transfer-encoding; bh=+sN6HX1BqV3b1XdRd5cbt+4ED2RdKrpGKUBRJZU//UU=; b=XPqFWMoNXYysdGbZpkU1Dhx1PvofOBQsIdjvdZiq+fhakXu96lzlj6F8SJu3e/Fm9E AoSZZqJZv2J69qE/O9dG5DRXomRgWB3uNO9C4eJvO0cvRo6/ePHCVaqIoufNNyFgRnvn vybsMtfABRQqvVwtuOjfohvYKfWl9xyecLKCMItoHXQcvfEW4qguV2H1U0OC3A9+FD5E 40XysV6hF3PzGLqUC81M/YAeQdkSno3cZ/5nOc09PGVzKdQ4lqxGD3JtP3ya3BWzuJ24 xEJWfHx3tbh5YFLezSevWwliYWFLNtyW+38HZktmuKN75kJuj+gY3xvznP+ycqFxswKk Llag== X-Gm-Message-State: AOAM5325LXUmQ/sF1nZ0Gu9R24Dd/mXE9EJ0f+bojZWHnbhiv4Qqq41b gw9SQXVHiowZmIhsmMUfMsUYEKQ9dYZ29g== X-Google-Smtp-Source: ABdhPJxr6Nf60TsliSNY6LxyNF06qydIJ6D7lbowhEO1/UmhlpZkf067GwHcKULDTv6TvH1CGs1GmQ== X-Received: by 2002:a17:902:ed83:b029:de:84d2:9ce9 with SMTP id e3-20020a170902ed83b02900de84d29ce9mr536251plj.2.1612465575425; Thu, 04 Feb 2021 11:06:15 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:06:15 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood , Taylor Blau Subject: [PATCH v5 5/8] sequencer: use const variable for commit message comments Date: Fri, 5 Feb 2021 00:35:04 +0530 Message-Id: <20210204190507.26487-6-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This makes it easier to use and reuse the comments. Mentored-by: Christian Couder Mentored-by: Phillip Wood Reviewed-by: Taylor Blau Signed-off-by: Charvi Mendiratta --- sequencer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sequencer.c b/sequencer.c index 09cbb17f87..6d9a10afcf 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1732,6 +1732,11 @@ static size_t subject_length(const char *body) 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_nth_commit_msg_fmt[] = N_("The commit message #%d will be skipped:"); +static const char combined_commit_msg_fmt[] = N_("This is a combination of %d commits."); + static void append_squash_message(struct strbuf *buf, const char *body, struct replay_opts *opts) { @@ -1741,7 +1746,7 @@ static void append_squash_message(struct strbuf *buf, const char *body, if (starts_with(body, "squash!") || starts_with(body, "fixup!")) commented_len = subject_length(body); strbuf_addf(buf, "\n%c ", comment_line_char); - strbuf_addf(buf, _("This is the commit message #%d:"), + strbuf_addf(buf, _(nth_commit_msg_fmt), ++opts->current_fixup_count + 1); strbuf_addstr(buf, "\n\n"); strbuf_add_commented_lines(buf, body, commented_len); @@ -1770,7 +1775,7 @@ static int update_squash_messages(struct repository *r, buf.buf : strchrnul(buf.buf, '\n'); strbuf_addf(&header, "%c ", comment_line_char); - strbuf_addf(&header, _("This is a combination of %d commits."), + strbuf_addf(&header, _(combined_commit_msg_fmt), opts->current_fixup_count + 2); strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len); strbuf_release(&header); @@ -1794,9 +1799,9 @@ static int update_squash_messages(struct repository *r, } strbuf_addf(&buf, "%c ", comment_line_char); - strbuf_addf(&buf, _("This is a combination of %d commits."), 2); + strbuf_addf(&buf, _(combined_commit_msg_fmt), 2); strbuf_addf(&buf, "\n%c ", comment_line_char); - strbuf_addstr(&buf, _("This is the 1st commit message:")); + strbuf_addstr(&buf, _(first_commit_msg_str)); strbuf_addstr(&buf, "\n\n"); strbuf_addstr(&buf, body); @@ -1812,7 +1817,7 @@ static int update_squash_messages(struct repository *r, append_squash_message(&buf, body, opts); } else if (command == TODO_FIXUP) { strbuf_addf(&buf, "\n%c ", comment_line_char); - strbuf_addf(&buf, _("The commit message #%d will be skipped:"), + strbuf_addf(&buf, _(skip_nth_commit_msg_fmt), ++opts->current_fixup_count + 1); strbuf_addstr(&buf, "\n\n"); strbuf_add_commented_lines(&buf, body, strlen(body)); From patchwork Thu Feb 4 19:05:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068411 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 BCBF0C433E0 for ; Thu, 4 Feb 2021 19:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DA2364F6B for ; Thu, 4 Feb 2021 19:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238713AbhBDTHt (ORCPT ); Thu, 4 Feb 2021 14:07:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239598AbhBDTHE (ORCPT ); Thu, 4 Feb 2021 14:07:04 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 431C7C0613D6 for ; Thu, 4 Feb 2021 11:06:24 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id lw17so5485771pjb.0 for ; Thu, 04 Feb 2021 11:06:24 -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 :mime-version:content-transfer-encoding; bh=9F6vU7A32uYF8EHTzD1fSoszSFNvqyjvUzPWRZs1dM8=; b=ZVpkGG44HKftLh214vBef/XxO/yiSyzWXoC0O6G3aO/gQ3b2F3ggiwD9ze+/2+Vp/Z 3hO620rEK8j2BrCg0Ju1NEqDOjeTIfyfukpkLY4R1/5QhN4kiUNPAwaA9zE5xQVPif2b LzxJY5CrM2T+Te4NUrxSjwktB/km43i+AXpbXqN+D2sNtPdLls2KfYm9VJCEadxUgc5k vatCxIXzvkB5DPVJ5WTgg4icobtyLU5/cIQrboHrF5tLXxVCoi4ku2L4K+ZI8+57YbY5 0ADk+/RHlV4o0rYPrPb0/AGMzT4EYh8T7oMP9dNd8SYhxFTVqkEkp0QrdhBKkqgvCtuH qJBA== 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:mime-version:content-transfer-encoding; bh=9F6vU7A32uYF8EHTzD1fSoszSFNvqyjvUzPWRZs1dM8=; b=DGH0L7NoIwDbmGWcARyj3Lz3SbFVmh1x7sR1USIvr5DYBpjzSouiLnoHAhVI6AUAKF qJG12H3uzZn13I1bMLlqv+4m+V4iMW1iz9wyVQoNqNhfAwQBpK15rLDX2pIIv8U/XMlo YUpzaPQeIxX+nNCIjhc92B8f/j2IseqYWekrbhnG7INWUirdRno/a4Zeqq508B68Ki06 oMZdq/kLlbCEmUZ5L8lTL3rEDpUKiaR6O7MqmT2ft6pHEsfp4CTVUs6u3go6iALG8/ga HLkR3h6Mh6gk91VEXn/47Iau1fR0VUIfwoR1TVpufBRRMEm+b8tx6UifX3WfUI6sr+4A oNFw== X-Gm-Message-State: AOAM531esDrwtTAEmNc3ivzoVI2cf1VXIhA8GeFyMBTmcpNGD39L1Lxy 0pkYYaFS+q8f2pEIdqw1ukaGDF+ccDsrvg== X-Google-Smtp-Source: ABdhPJwwodszYkOiyhZY+34K5LGOJXB9N5gusPCMzRP7uXOTQaZxbDMbQW7hx2e71J1j0pByLlTryA== X-Received: by 2002:a17:90a:468e:: with SMTP id z14mr443296pjf.174.1612465583346; Thu, 04 Feb 2021 11:06:23 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:06:22 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Phillip Wood , Christian Couder Subject: [PATCH v5 6/8] rebase -i: add fixup [-C | -c] command Date: Fri, 5 Feb 2021 00:35:05 +0530 Message-Id: <20210204190507.26487-7-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add options to `fixup` command to fixup both the commit contents and message. `fixup -C` command is used to replace the original commit message and `fixup -c`, additionally allows to edit the commit message. This convention is similar to the existing `merge` command in the interactive rebase, that also supports `-c` and `-C` options with similar meanings. Original-patch-by: Phillip Wood Mentored-by: Christian Couder Mentored-by: Phillip Wood Reviewed-by: Eric Sunshine Signed-off-by: Charvi Mendiratta --- rebase-interactive.c | 4 +- sequencer.c | 211 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 195 insertions(+), 20 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index 762853bc7e..13e7a6c475 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -44,7 +44,9 @@ void append_todo_help(int command_count, "r, reword = use commit, but edit the commit message\n" "e, edit = use commit, but stop for amending\n" "s, squash = use commit, but meld into previous commit\n" -"f, fixup = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] = like \"squash\", but discard this\n" +" commit's log message; use -C to replace with this\n" +" commit message or -c to edit this commit message\n" "x, exec = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop = remove commit\n" diff --git a/sequencer.c b/sequencer.c index 6d9a10afcf..324fc5698a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1718,6 +1718,12 @@ static int is_pick_or_similar(enum todo_command command) } } +enum todo_item_flags { + TODO_EDIT_MERGE_MSG = (1 << 0), + TODO_REPLACE_FIXUP_MSG = (1 << 1), + TODO_EDIT_FIXUP_MSG = (1 << 2), +}; + static size_t subject_length(const char *body) { const char *p = body; @@ -1734,32 +1740,174 @@ static size_t subject_length(const char *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:"); static const char skip_nth_commit_msg_fmt[] = N_("The commit message #%d will be skipped:"); static const char combined_commit_msg_fmt[] = N_("This is a combination of %d commits."); -static void append_squash_message(struct strbuf *buf, const char *body, - struct replay_opts *opts) +static int is_fixup_flag(enum todo_command command, unsigned flag) +{ + return command == TODO_FIXUP && ((flag & TODO_REPLACE_FIXUP_MSG) || + (flag & TODO_EDIT_FIXUP_MSG)); +} + +/* + * Wrapper around strbuf_add_commented_lines() which avoids double + * commenting commit subjects. + */ +static void add_commented_lines(struct strbuf *buf, const void *str, size_t len) +{ + const char *s = str; + while (len > 0 && s[0] == comment_line_char) { + size_t count; + const char *n = memchr(s, '\n', len); + if (!n) + count = len; + else + count = n - s + 1; + strbuf_add(buf, s, count); + s += count; + len -= count; + } + strbuf_add_commented_lines(buf, s, len); +} + +/* Does the current fixup chain contain a squash command? */ +static int seen_squash(struct replay_opts *opts) +{ + return starts_with(opts->current_fixups.buf, "squash") || + strstr(opts->current_fixups.buf, "\nsquash"); +} + +static void update_comment_bufs(struct strbuf *buf1, struct strbuf *buf2, int n) { - size_t commented_len = 0; + strbuf_setlen(buf1, 2); + strbuf_addf(buf1, _(nth_commit_msg_fmt), n); + strbuf_addch(buf1, '\n'); + strbuf_setlen(buf2, 2); + strbuf_addf(buf2, _(skip_nth_commit_msg_fmt), n); + strbuf_addch(buf2, '\n'); +} - unlink(rebase_path_fixup_msg()); - if (starts_with(body, "squash!") || starts_with(body, "fixup!")) +/* + * Comment out any un-commented commit messages, updating the message comments + * to say they will be skipped but do not comment out the empty lines that + * surround commit messages and their comments. + */ +static void update_squash_message_for_fixup(struct strbuf *msg) +{ + void (*copy_lines)(struct strbuf *, const void *, size_t) = strbuf_add; + struct strbuf buf1 = STRBUF_INIT, buf2 = STRBUF_INIT; + const char *s, *start; + char *orig_msg; + size_t orig_msg_len; + int i = 1; + + strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str)); + strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str)); + s = start = orig_msg = strbuf_detach(msg, &orig_msg_len); + while (s) { + const char *next; + size_t off; + if (skip_prefix(s, buf1.buf, &next)) { + /* + * Copy the last message, preserving the blank line + * preceding the current line + */ + off = (s > start + 1 && s[-2] == '\n') ? 1 : 0; + copy_lines(msg, start, s - start - off); + if (off) + strbuf_addch(msg, '\n'); + /* + * The next message needs to be commented out but the + * message header is already commented out so just copy + * it and the blank line that follows it. + */ + strbuf_addbuf(msg, &buf2); + if (*next == '\n') + strbuf_addch(msg, *next++); + start = s = next; + copy_lines = add_commented_lines; + update_comment_bufs(&buf1, &buf2, ++i); + } else if (skip_prefix(s, buf2.buf, &next)) { + off = (s > start + 1 && s[-2] == '\n') ? 1 : 0; + copy_lines(msg, start, s - start - off); + start = s - off; + s = next; + copy_lines = strbuf_add; + update_comment_bufs(&buf1, &buf2, ++i); + } else { + s = strchr(s, '\n'); + if (s) + s++; + } + } + copy_lines(msg, start, orig_msg_len - (start - orig_msg)); + free(orig_msg); + strbuf_release(&buf1); + strbuf_release(&buf2); +} + +static int append_squash_message(struct strbuf *buf, const char *body, + enum todo_command command, struct replay_opts *opts, + unsigned flag) +{ + const char *fixup_msg; + size_t commented_len = 0, fixup_off; + /* + * fixup -C is non-interactive and not normally used with fixup! + * or squash! commits, so only comment out those subjects when + * squashing commit messages. + */ + if ((command == TODO_SQUASH || seen_squash(opts)) && + (starts_with(body, "squash!") || starts_with(body, "fixup!"))) commented_len = subject_length(body); + strbuf_addf(buf, "\n%c ", comment_line_char); strbuf_addf(buf, _(nth_commit_msg_fmt), ++opts->current_fixup_count + 1); strbuf_addstr(buf, "\n\n"); strbuf_add_commented_lines(buf, body, commented_len); + /* buf->buf may be reallocated so store an offset into the buffer */ + fixup_off = buf->len; strbuf_addstr(buf, body + commented_len); + + /* fixup -C after squash behaves like squash */ + if (is_fixup_flag(command, flag) && !seen_squash(opts)) { + /* + * We're replacing the commit message so we need to + * append the Signed-off-by: trailer if the user + * requested '--signoff'. + */ + if (opts->signoff) + append_signoff(buf, 0, 0); + + if ((command == TODO_FIXUP) && + (flag & TODO_REPLACE_FIXUP_MSG) && + (file_exists(rebase_path_fixup_msg()) || + !file_exists(rebase_path_squash_msg()))) { + fixup_msg = skip_blank_lines(buf->buf + fixup_off); + if (write_message(fixup_msg, strlen(fixup_msg), + rebase_path_fixup_msg(), 0) < 0) + return error(_("cannot write '%s'"), + rebase_path_fixup_msg()); + } else { + unlink(rebase_path_fixup_msg()); + } + } else { + unlink(rebase_path_fixup_msg()); + } + + return 0; } static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit, - struct replay_opts *opts) + struct replay_opts *opts, + unsigned flag) { struct strbuf buf = STRBUF_INIT; - int res; + int res = 0; const char *message, *body; const char *encoding = get_commit_output_encoding(); @@ -1779,6 +1927,8 @@ static int update_squash_messages(struct repository *r, opts->current_fixup_count + 2); strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len); strbuf_release(&header); + if (is_fixup_flag(command, flag) && !seen_squash(opts)) + update_squash_message_for_fixup(&buf); } else { struct object_id head; struct commit *head_commit; @@ -1792,18 +1942,22 @@ static int update_squash_messages(struct repository *r, return error(_("could not read HEAD's commit message")); find_commit_subject(head_message, &body); - if (command == TODO_FIXUP && write_message(body, strlen(body), + if (command == TODO_FIXUP && !flag && write_message(body, strlen(body), rebase_path_fixup_msg(), 0) < 0) { unuse_commit_buffer(head_commit, head_message); return error(_("cannot write '%s'"), rebase_path_fixup_msg()); } - strbuf_addf(&buf, "%c ", comment_line_char); strbuf_addf(&buf, _(combined_commit_msg_fmt), 2); strbuf_addf(&buf, "\n%c ", comment_line_char); - strbuf_addstr(&buf, _(first_commit_msg_str)); + strbuf_addstr(&buf, is_fixup_flag(command, flag) ? + _(skip_first_commit_msg_str) : + _(first_commit_msg_str)); strbuf_addstr(&buf, "\n\n"); - strbuf_addstr(&buf, body); + if (is_fixup_flag(command, flag)) + strbuf_add_commented_lines(&buf, body, strlen(body)); + else + strbuf_addstr(&buf, body); unuse_commit_buffer(head_commit, head_message); } @@ -1813,8 +1967,8 @@ static int update_squash_messages(struct repository *r, oid_to_hex(&commit->object.oid)); find_commit_subject(message, &body); - if (command == TODO_SQUASH) { - append_squash_message(&buf, body, opts); + if (command == TODO_SQUASH || is_fixup_flag(command, flag)) { + res = append_squash_message(&buf, body, command, opts, flag); } else if (command == TODO_FIXUP) { strbuf_addf(&buf, "\n%c ", comment_line_char); strbuf_addf(&buf, _(skip_nth_commit_msg_fmt), @@ -1825,7 +1979,9 @@ static int update_squash_messages(struct repository *r, return error(_("unknown command: %d"), command); unuse_commit_buffer(commit, message); - res = write_message(buf.buf, buf.len, rebase_path_squash_msg(), 0); + if (!res) + res = write_message(buf.buf, buf.len, rebase_path_squash_msg(), + 0); strbuf_release(&buf); if (!res) { @@ -2026,7 +2182,8 @@ static int do_pick_commit(struct repository *r, if (command == TODO_REWORD) reword = 1; else if (is_fixup(command)) { - if (update_squash_messages(r, command, commit, opts)) + if (update_squash_messages(r, command, commit, + opts, item->flags)) return -1; flags |= AMEND_MSG; if (!final_fixup) @@ -2191,10 +2348,6 @@ static int read_and_refresh_cache(struct repository *r, return 0; } -enum todo_item_flags { - TODO_EDIT_MERGE_MSG = 1 -}; - void todo_list_release(struct todo_list *todo_list) { strbuf_release(&todo_list->buf); @@ -2281,6 +2434,18 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, return 0; } + if (item->command == TODO_FIXUP) { + if (skip_prefix(bol, "-C", &bol) && + (*bol == ' ' || *bol == '\t')) { + bol += strspn(bol, " \t"); + item->flags |= TODO_REPLACE_FIXUP_MSG; + } else if (skip_prefix(bol, "-c", &bol) && + (*bol == ' ' || *bol == '\t')) { + bol += strspn(bol, " \t"); + item->flags |= TODO_EDIT_FIXUP_MSG; + } + } + if (item->command == TODO_MERGE) { if (skip_prefix(bol, "-C", &bol)) bol += strspn(bol, " \t"); @@ -5287,6 +5452,14 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis short_commit_name(item->commit) : oid_to_hex(&item->commit->object.oid); + if (item->command == TODO_FIXUP) { + if (item->flags & TODO_EDIT_FIXUP_MSG) + strbuf_addstr(buf, " -c"); + else if (item->flags & TODO_REPLACE_FIXUP_MSG) { + strbuf_addstr(buf, " -C"); + } + } + if (item->command == TODO_MERGE) { if (item->flags & TODO_EDIT_MERGE_MSG) strbuf_addstr(buf, " -c"); From patchwork Thu Feb 4 19:05:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068409 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 8C3E2C433DB for ; Thu, 4 Feb 2021 19:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DBB964F65 for ; Thu, 4 Feb 2021 19:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239531AbhBDTHf (ORCPT ); Thu, 4 Feb 2021 14:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239614AbhBDTHL (ORCPT ); Thu, 4 Feb 2021 14:07:11 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6361AC061786 for ; Thu, 4 Feb 2021 11:06:31 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id o20so2723523pfu.0 for ; Thu, 04 Feb 2021 11:06:31 -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 :mime-version:content-transfer-encoding; bh=Wft5ezGvz2rkaVUQX0urthMTPZWEqxmeMp3WTgpz8Rg=; b=jkDMV2nJLQm9QAaTFtsNfjGInq3NsYvesmbafYcqh10/mYXJo7M0kBny+vMoYrRnai xT07wvGDHJVQcNpaW+tPH6WRxcpE547WZHvCj6wlXJKcEtuchqATZnYwVRtH92ugM6Fe X747w8Y2xBF/Q8ZTPrl4RhTTFjIu4FXpywcRZEKJL0kelI0FBkNh7XU1fc7ptwIp8SmA Qs2KSeOhCwbmyL2m93XVrJvVrGtQ/SImcoCtCw2LIss9vZ0tHlsVt9jnkPuaVweOpfp0 B2j/n/UUdICKskn2UbszT+4vRUP1n5C5/Ao1cz6jt4LhvhGpQ20fMhqsKdlXbfUj2Pjy xoYg== 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:mime-version:content-transfer-encoding; bh=Wft5ezGvz2rkaVUQX0urthMTPZWEqxmeMp3WTgpz8Rg=; b=Z1dF0glUn+CENRAAgzlcaMStQafRDkJNRTCGLJrYS/jOhw7gD0NYrnA8EcBYr0/YYm WchRp2msZ4vU5jJYaNO7VbjEdlGfB4FgF88jS0qFNMINjff/RjLC/OJINAv21I1pGacE J3ksRA+YqX2owmKhfnipTP3Xw447y5j7/371Q6dzC0IrWinAgFkOh3EJUcWtxU1oqZmW vPdveM/XlHDAe5GkgRzdS1g72eXpU0NG+vhzo2berSO2n5Egeq1jDrhAV2kD/sX4CBMO 7OFB3vYjaTQ2j8OlD89wlvP2gczEwx87CjHXjEAdbvfLNs7m0SsloOjqt7OeuwjgHQyc kUrg== X-Gm-Message-State: AOAM532lPgzpEBcow8mXxwI5rsgou8vP0J+4GKmt5jp89EjfKRlayeNy GAqqhXFFIZDdxQmfqHaUFV5sH3RQdsFaRw== X-Google-Smtp-Source: ABdhPJzoN4nfL+NDCR68kduHJ14LVDcaNVn4+gtKTACiBnVQJN2LYRm3OWKRpdQ8S8zeM/DORrHycg== X-Received: by 2002:a63:575e:: with SMTP id h30mr428094pgm.7.1612465590613; Thu, 04 Feb 2021 11:06:30 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:06:30 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Phillip Wood , Christian Couder Subject: [PATCH v5 7/8] t3437: test script for fixup [-C|-c] options in interactive rebase Date: Fri, 5 Feb 2021 00:35:06 +0530 Message-Id: <20210204190507.26487-8-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-1-charvi077@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Original-patch-by: Phillip Wood Mentored-by: Christian Couder Mentored-by: Phillip Wood Reviewed-by: Eric Sunshine Signed-off-by: Charvi Mendiratta --- t/lib-rebase.sh | 8 +- t/t3437-rebase-fixup-options.sh | 133 ++++++++++++++++++++++++++++++ t/t3437/expected-combined-message | 19 +++++ 3 files changed, 158 insertions(+), 2 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index b72c051f47..d9afed7b47 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -4,6 +4,7 @@ # # - override the commit message with $FAKE_COMMIT_MESSAGE # - amend the commit message with $FAKE_COMMIT_AMEND +# - copy the original commit message to a file with $FAKE_MESSAGE_COPY # - check that non-commit messages have a certain line count with $EXPECT_COUNT # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT # - rewrite a rebase -i script as directed by $FAKE_LINES. @@ -14,8 +15,8 @@ # specified line. # # " " -- add a line with the specified command -# ("pick", "squash", "fixup", "edit", "reword" or "drop") and the -# SHA1 taken from the specified line. +# ("pick", "squash", "fixup"|"fixup-C"|"fixup-c", "edit", "reword" or "drop") +# and the SHA1 taken from the specified line. # # "exec_cmd_with_args" -- add an "exec cmd with args" line. # @@ -33,6 +34,7 @@ set_fake_editor () { exit test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" exit ;; esac @@ -51,6 +53,8 @@ set_fake_editor () { action="$line";; exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + fixup-*) + action=$(echo "$line" | sed 's/-/ -/');; "#") echo '# comment' >> "$1";; ">") diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh new file mode 100755 index 0000000000..c2875803af --- /dev/null +++ b/t/t3437-rebase-fixup-options.sh @@ -0,0 +1,133 @@ +#!/bin/sh +# +# Copyright (c) 2018 Phillip Wood +# + +test_description='git rebase interactive fixup options + +This test checks the "fixup [-C|-c]" command of rebase interactive. +In addition to amending the contents of the commit, "fixup -C" +replaces the original commit message with the message of the fixup +commit. "fixup -c" also replaces the original message, but opens the +editor to allow the user to edit the message before committing. +' + +. ./test-lib.sh + +. "$TEST_DIRECTORY"/lib-rebase.sh + +EMPTY="" + +# test_commit_message -m +# test_commit_message +# Verify that the commit message of matches +# or the content of . +test_commit_message () { + git show --no-patch --pretty=format:%B "$1" >actual && + case "$2" in + -m) echo "$3" >expect && + test_cmp expect actual ;; + *) test_cmp "$2" actual ;; + esac +} + +test_expect_success 'setup' ' + cat >message <<-EOF && + new subject + $EMPTY + new + body + EOF + test_commit A A && + test_commit B B && + + set_fake_editor && + git checkout -b test-branch && + test_commit "$(cat message)" A A1 A1 && + test_commit A2 A && + test_commit A3 A && + git checkout -b conflicts-branch A && + test_commit conflicts A +' + +test_expect_success 'simple fixup -C works' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A1 && + git log -1 --pretty=format:%B >expected-message && + FAKE_LINES="1 fixup-C 2 " git rebase -i A && + test_cmp_rev HEAD^ A && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_commit_message HEAD expected-message +' + +test_expect_success 'simple fixup -c works' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A2 && + git log -1 --pretty=format:%B HEAD~ >expected-message && + test_write_lines "" "Modified A1" >>expected-message && + FAKE_LINES="1 fixup-c 2 3" \ + FAKE_COMMIT_AMEND="Modified A1" \ + git rebase -i A && + test_cmp_rev HEAD^{tree} A2^{tree} && + test_commit_message HEAD~ expected-message +' + +test_expect_success 'fixup -C with conflicts gives correct message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A1 && + git log -1 --pretty=format:%B HEAD >expected-message && + test_write_lines "" "edited" >>expected-message && + test_must_fail env FAKE_LINES="1 fixup-C 2" git rebase -i conflicts && + git checkout --theirs -- A && + git add A && + FAKE_COMMIT_AMEND=edited git rebase --continue && + test_cmp_rev HEAD^ conflicts && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_commit_message HEAD expected-message +' + +test_expect_success 'skipping fixup -C after fixup gives correct message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A3 && + test_must_fail env FAKE_LINES="1 fixup 2 fixup-C 4" git rebase -i A && + git reset --hard && + FAKE_COMMIT_AMEND=edited git rebase --continue && + test_commit_message HEAD -m "B" +' + +test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fixup -C' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A3 && + git log -1 --pretty=format:%B >expected-message && + FAKE_LINES="1 fixup 2 fixup-C 3 fixup-C 4" git rebase -i A && + test_cmp_rev HEAD^ A && + test_commit_message HEAD expected-message +' + +test_expect_success 'multiple fixup -c opens editor once' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A3 && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_MESSAGE="Modified-A3" \ + FAKE_LINES="1 fixup-C 2 fixup-c 3 fixup-c 4" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test_commit_message HEAD -m "Modified-A3" && + test_cmp_rev $base HEAD^ && + git show > raw && + grep Modified-A3 raw >out && + test_line_count = 1 out +' + +test_expect_success 'sequence squash, fixup & fixup -c gives combined message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A3 && + FAKE_LINES="1 squash 2 fixup 3 fixup-c 4" \ + FAKE_MESSAGE_COPY=actual-combined-message \ + git -c commit.status=false rebase -i A && + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-combined-message" \ + actual-combined-message && + test_cmp_rev HEAD^ A +' + +test_done diff --git a/t/t3437/expected-combined-message b/t/t3437/expected-combined-message new file mode 100644 index 0000000000..d21bd1b6bb --- /dev/null +++ b/t/t3437/expected-combined-message @@ -0,0 +1,19 @@ +# This is a combination of 4 commits. +# This is the 1st commit message: + +B + +# This is the commit message #2: + +new subject + +new +body + +# The commit message #3 will be skipped: + +# A2 + +# This is the commit message #4: + +A3 From patchwork Thu Feb 4 19:05:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charvi Mendiratta X-Patchwork-Id: 12068417 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 096ADC433DB for ; Thu, 4 Feb 2021 19:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA15064F6A for ; Thu, 4 Feb 2021 19:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239524AbhBDTIj (ORCPT ); Thu, 4 Feb 2021 14:08:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239616AbhBDTHT (ORCPT ); Thu, 4 Feb 2021 14:07:19 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA164C061794 for ; Thu, 4 Feb 2021 11:06:38 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id b8so2246527plh.12 for ; Thu, 04 Feb 2021 11:06:38 -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 :mime-version:content-transfer-encoding; bh=nHifqpaoWCPM5TGMO6nlc30LubOcJk/lRr8mR4S7jI0=; b=Z4ss7qubYkjSN2N8wsOufOb3XgzCkU7XdAksyYX9MBn5oN/8IbS0jrZkMtL1dnrEHS rRTCUm/3iUKtqhJJdMFkodwxX5wZONUhWRZYcZOJwtmaQ6bbgSmm+KZoEil1h5q8y8MA X9mUFDCdhKiUrqRl/4QwulCraT8mVdOYKqOo5QiL11CGHjgxF1Xm4ObciTyHBKVXFADi 7E0lHBAbuhTfS+4WVQ+I+RqNdt0qzWECxk0h3wBbDipGlcKiY602yOKH7iht5ks9u21X cQjXC5+DekIbcx2tEIWqEGE62GU2k0Pp247auSq32OH07MS6NgWDLonyF+nnrT1i579H iNxw== 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:mime-version:content-transfer-encoding; bh=nHifqpaoWCPM5TGMO6nlc30LubOcJk/lRr8mR4S7jI0=; b=eE89kbTJudjLgp/vA6Pq8uZxQUo30E7syL4Be0wJJ59JyL2WMxEivzaYPsyAFYheGw A6WuHim3FJnhpKtnXSdOXbVx78F0Z/p94ZBe4X7gH4PCNNFuD2WahaPAuxCxt0WC3w9r +BGtgt+ZK9Y3TQteWXjOb5GdDWy/d9KIpF3/h0a17947W5bRpfnZgAYxFxExg83z7K2R T7Y+dK9XD7qQ6snzKhyh++QhT6oOOfnNYZIVdYD0zFNacPyzZk0WwIk3v5XDDJOn5rOp 0fuxhrRcNCoSZE0rOhIK9xH5h+9/KLNsQCPm8KPfQrJaEmdv6SEPjjIVwL3kiN4U1MtG VMBw== X-Gm-Message-State: AOAM533B5HEoqDxAn7daexYcs9G1ikHbho2AXQyMPzZoDPWisbobz6GG s8/UaawljwIIACB+z1WVuL3Rmauiu9KZlA== X-Google-Smtp-Source: ABdhPJy64DsnaLits2t3OkCrbmBHr9/2sRT9hEd7zoAJ0UL55S3EO4Vvmhu4Em0uVQ0VsNpVpdhGuQ== X-Received: by 2002:a17:902:9a4a:b029:dc:435c:70ad with SMTP id x10-20020a1709029a4ab02900dc435c70admr718905plv.77.1612465597672; Thu, 04 Feb 2021 11:06:37 -0800 (PST) Received: from localhost.localdomain ([2405:204:332c:6caa:c21:291b:12a6:463f]) by smtp.googlemail.com with ESMTPSA id 9sm6729524pfo.1.2021.02.04.11.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:06:37 -0800 (PST) From: Charvi Mendiratta To: git@vger.kernel.org Cc: sunshine@sunshineco.com, christian.couder@gmail.com, phillip.wood123@gmail.com, Charvi Mendiratta , Christian Couder , Phillip Wood , Marc Branchaud Subject: [PATCH v5 8/8] doc/git-rebase: add documentation for fixup [-C|-c] options Date: Fri, 5 Feb 2021 00:35:07 +0530 Message-Id: <20210204190507.26487-9-charvi077@gmail.com> X-Mailer: git-send-email 2.29.0.rc1 In-Reply-To: <20210204190507.26487-1-charvi077@gmail.com> References: <20210129182050.26143-1-charvi077@gmail.com> <20210204190507.26487-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 Reviewed-by: Marc Branchaud Reviewed-by: Eric Sunshine Signed-off-by: Charvi Mendiratta --- Documentation/git-rebase.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index a0487b5cc5..97a8d2e1aa 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -887,9 +887,16 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omitting the +messages of commits identified by "fixup" commands, unless "fixup -c" +is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the final one is used. You can also use +"fixup -C" to get the same behavior as "fixup -c" except without opening +an editor. 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing