From patchwork Fri Apr 21 14:57:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13220240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B8A2C77B71 for ; Fri, 21 Apr 2023 14:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232477AbjDUO6E (ORCPT ); Fri, 21 Apr 2023 10:58:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233076AbjDUO6A (ORCPT ); Fri, 21 Apr 2023 10:58:00 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113EA125B2 for ; Fri, 21 Apr 2023 07:57:58 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-2f7c281a015so1154598f8f.1 for ; Fri, 21 Apr 2023 07:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682089077; x=1684681077; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=icne5xfGB2d788/L7Cr9bQB8RSyNpE8WakcsfTOQCfU=; b=MXEX3b3yLS1VRAa2gb4vsweFdBR/0ILoRbOhIp/bHLQl/ZZmYYkdC+98XyspZMfvk5 KFGmUVx93PgOclPtSrMCbPu6VGhdt3o2aknxNq6scX6r5McUWHjyYfn5JnR/Zg747y5q dU2V+6MLK7+ffSBbpYxBfBBBAOw/b46F+3XVFoMy8uo17nz9dahHA4DfdKMKy3QQp6Lc XG6LXz7vS7RWof80FmowH86nkjNAWyUKJXk+YPwI/KaEl3y9O2d7zK+WahKY6MhFtnTQ +nqHGhs3XR6BZR2hjLw9wpZBUdebpUKl+oySLIqHwrV9V80PsncnTJ1BmGJesKKiEs6n mgGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682089077; x=1684681077; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=icne5xfGB2d788/L7Cr9bQB8RSyNpE8WakcsfTOQCfU=; b=O6J0wOZM4eiLGDTrhfe4Xn8Gt5X5RcQIP7xXmwBEOyw3wHJx9C+cQpt4iEAoF2OM9j rI/0OMmSV1xaB6pOqbLtmHiQZeJHs3QTY9/nN42BJKkBVocI2B20jSj7u7hWJ30i5tnK s/scHcmn45ut7E2+8RpiJYMmILt/JwDSlcUCmUP9Tq2HzjShRNRg459MfiPaGjQgYuHn 4b6JL/bKQMyPUSfdlVsaq7DH+KMXyvFeTI1y3/CTOgGH0b/Hk7vcLbaaTCEdyIlmHs9i gqDxgDqP0fYmg1MBcdjD3Zc3+pyNqVUQOv2YWuTP/hnYr3g630yjBOkQffTuln6D/e7D AKmw== X-Gm-Message-State: AAQBX9f9CFjy8e5ExE7ftP5Ho1MpMgg7eWSeCzLwQb67in/ulRYokMB0 pNZaJO8BIrTHET30rvHTeys3clUQ3kM= X-Google-Smtp-Source: AKy350Ysm6NXQvvg04Zw/bY08/LdLP/nuZUa+iQMssSqPHFLx+n8zJPTN8rYyoRgx5eC91umkTmhOg== X-Received: by 2002:adf:f983:0:b0:2ef:ba4f:c821 with SMTP id f3-20020adff983000000b002efba4fc821mr3316137wrr.36.1682089077175; Fri, 21 Apr 2023 07:57:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c1-20020a5d4f01000000b002fc0de07930sm4564080wru.13.2023.04.21.07.57.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 07:57:56 -0700 (PDT) Message-Id: <3dfb2c6903bcc61258c72ba5c8e4201c9db2665b.1682089074.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Apr 2023 14:57:49 +0000 Subject: [PATCH v2 1/6] rebase -i: move unlink() calls Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Stefan Haller , Phillip Wood , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood At the start of each iteration the loop that picks commits removes state files from the previous pick. However some of these are only written if there are conflicts so only need to be removed before starting the loop, not in each iteration. Signed-off-by: Phillip Wood --- sequencer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sequencer.c b/sequencer.c index d2c7698c48c..5073ec5902b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4639,6 +4639,10 @@ static int pick_commits(struct repository *r, if (read_and_refresh_cache(r, opts)) return -1; + unlink(rebase_path_message()); + unlink(rebase_path_stopped_sha()); + unlink(rebase_path_amend()); + while (todo_list->current < todo_list->nr) { struct todo_item *item = todo_list->items + todo_list->current; const char *arg = todo_item_get_arg(todo_list, item); @@ -4662,10 +4666,7 @@ static int pick_commits(struct repository *r, todo_list->total_nr, opts->verbose ? "\n" : "\r"); } - unlink(rebase_path_message()); unlink(rebase_path_author_script()); - unlink(rebase_path_stopped_sha()); - unlink(rebase_path_amend()); unlink(git_path_merge_head(r)); unlink(git_path_auto_merge(r)); delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); From patchwork Fri Apr 21 14:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13220241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E688C7618E for ; Fri, 21 Apr 2023 14:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233072AbjDUO6H (ORCPT ); Fri, 21 Apr 2023 10:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233068AbjDUO6C (ORCPT ); Fri, 21 Apr 2023 10:58:02 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD58C13864 for ; Fri, 21 Apr 2023 07:57:59 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f176a16c03so12390275e9.2 for ; Fri, 21 Apr 2023 07:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682089078; x=1684681078; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=V0mXpk4d9JWbSCGcMj4zJbUAFEZYoqEXOABacpBndUs=; b=AIb++rAiw81lgPpBLMlrpdup3UxrmbSvFcKR8GEnl1QAQ5vxIJNX8f8Cf3cihNAvhi 3pLQE2vx1eR+wLtCZs4qxClL0pI9h1SBw8fAGqYSVLGZ9LEgIe08iVzESIE5a77gbhw1 91v9icu5tcQqx8lX8cQ6/sH7BbJq2jHnHRLuVrRN2bJscmmWL249nAIhSSzO8rLvv1hE L3XGXTBvP707p+eppsqGaSyLO8MpVdnQNlJkGc5kviqCLj4czw+IJe7GKKQvKt/jkzRx 9ob1FNu7HCqcMTfWeqUIuHKf9R0TbfSbCX1Lj95uA7hwd7eeasJR++1xi1pdqSf+A4oq Z6jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682089078; x=1684681078; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V0mXpk4d9JWbSCGcMj4zJbUAFEZYoqEXOABacpBndUs=; b=M+9fevnbYwEbmhkeIzcgspRSw+vVNThyV0xUN55Gknhp52z/Q3x+jQAi1rjXj3IZGz QVZfu1YAPIZVS5os63lMfp2VPs5UGL8fDuZVucIP2fFKczs5seVyj20u14ZEUGHioDEs TG9TE6w+EzuFvza9EyqnJHBxxt9v9x6/lawXtrugsVHO1OHwnMLJd7sY7az/sU6ccjcH MkdC840DJSOEyxfyiaEeL+VJFsqCdEyzVDGyMDVMe/mIhzJnQ78TgD9FkIu0cmlyXkMx k0QA4uzWpgDtWVppkXVQo/2I6Cqf8dXwGq/SAbtV5dCQcFEFEwcNiiJQMoFdWA6M9m9S Fmsg== X-Gm-Message-State: AAQBX9ewrzNRmQjcTMqPJ67H0wUU/9jn/8HFL7kccsUp15wVIvbz48PB t0vv46yJKZhwiN9vqhg5cL1zbrmCkpM= X-Google-Smtp-Source: AKy350YaPfVuHqbrTqPhDMef71xiq1fhXT9lfYokA8Qu7E47soNuJxAM8YGZRuyBttdzFzS0bvkDSg== X-Received: by 2002:a7b:c016:0:b0:3f1:6fba:b69a with SMTP id c22-20020a7bc016000000b003f16fbab69amr2298954wmb.11.1682089078080; Fri, 21 Apr 2023 07:57:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v21-20020a7bcb55000000b003f16f362ae7sm5041305wmj.21.2023.04.21.07.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 07:57:57 -0700 (PDT) Message-Id: <227aea031b588977f22f3f97faee981d79ade05c.1682089074.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Apr 2023 14:57:50 +0000 Subject: [PATCH v2 2/6] rebase -i: remove patch file after conflict resolution Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Stefan Haller , Phillip Wood , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When rebase stops for the user to resolve conflicts it writes a patch for the conflicting commit to .git/rebase-merge/patch. This file should be deleted when the rebase continues. As the path is now used in two different places rebase_path_patch() is added and used to obtain the path for the patch. Signed-off-by: Phillip Wood --- sequencer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sequencer.c b/sequencer.c index 5073ec5902b..c4a548f2c98 100644 --- a/sequencer.c +++ b/sequencer.c @@ -132,6 +132,11 @@ static GIT_PATH_FUNC(rebase_path_amend, "rebase-merge/amend") * the commit object name of the corresponding patch. */ static GIT_PATH_FUNC(rebase_path_stopped_sha, "rebase-merge/stopped-sha") +/* + * When we stop for the user to resolve conflicts this file contains + * the patch of the commit that is being picked. + */ +static GIT_PATH_FUNC(rebase_path_patch, "rebase-merge/patch") /* * For the post-rewrite hook, we make a list of rewritten commits and * their new sha1s. The rewritten-pending list keeps the sha1s of @@ -3490,7 +3495,6 @@ static int make_patch(struct repository *r, return -1; res |= write_rebase_head(&commit->object.oid); - strbuf_addf(&buf, "%s/patch", get_dir(opts)); memset(&log_tree_opt, 0, sizeof(log_tree_opt)); repo_init_revisions(r, &log_tree_opt, NULL); log_tree_opt.abbrev = 0; @@ -3498,7 +3502,7 @@ static int make_patch(struct repository *r, log_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH; log_tree_opt.disable_stdin = 1; log_tree_opt.no_commit_id = 1; - log_tree_opt.diffopt.file = fopen(buf.buf, "w"); + log_tree_opt.diffopt.file = fopen(rebase_path_patch(), "w"); log_tree_opt.diffopt.use_color = GIT_COLOR_NEVER; if (!log_tree_opt.diffopt.file) res |= error_errno(_("could not open '%s'"), buf.buf); @@ -4642,6 +4646,7 @@ static int pick_commits(struct repository *r, unlink(rebase_path_message()); unlink(rebase_path_stopped_sha()); unlink(rebase_path_amend()); + unlink(rebase_path_patch()); while (todo_list->current < todo_list->nr) { struct todo_item *item = todo_list->items + todo_list->current; From patchwork Fri Apr 21 14:57:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13220243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ABF5C77B71 for ; Fri, 21 Apr 2023 14:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233094AbjDUO6J (ORCPT ); Fri, 21 Apr 2023 10:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbjDUO6E (ORCPT ); Fri, 21 Apr 2023 10:58:04 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 003E9118EF for ; Fri, 21 Apr 2023 07:58:00 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-2f55ffdbaedso1186074f8f.2 for ; Fri, 21 Apr 2023 07:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682089079; x=1684681079; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=nOHV7xLXKCixg+Ul8Td3mK6ALffVlYyXoWTiaCQQRgc=; b=XfhQ8KxedBOE/f51VjZQdUloXUXJET+aN9fi043zJnNqWEne+xsrKYzFcF4r8h6Nbo SkRlkNKsCMkHTnn0diMPYtB5fSBRt8YkMACykERDs0Nww+cKeo2bB2if7iQgWXJrG11M l6qi8K8ax5hsX91D4DNtEoWO9kgyQbiB4KTN25ZJLRPS1iAG8Bv3MYgrlFWftfp1XVs+ SxFrunxgAJidjy6NPbL8kU0HiQVbCLQ4Y6Gq7XkGjVbTKyj0jAkykAF+/Xi5R0VWgLlP XSxhP+E77xBnCi0XRy7M/lvZqsLLlKDTYuQN7MSBdSs3nIvBIMh1rZ+cxXx6niWmr204 XQBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682089079; x=1684681079; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nOHV7xLXKCixg+Ul8Td3mK6ALffVlYyXoWTiaCQQRgc=; b=lYmzd63wfZwklZxwQQTa2WVUeRj+AAEe3RZELM+1S/ijFCTzimG4uz0zincWCDqntt ZKK/jBX3fYr6aDIYjcnTdgGRUu++PSZvlbwyACqMDQImQ4bccRrMQBO+tKka6uVZFL52 HLu3NJLR41SHW0UdF1kO5bpxdEteevQ1deBkWEcslNXofsbOV+60k5EdSDUs0OVvt+i9 Ah1a1Bi0595f7xOioAZhU4NdzxJ/gJmiBw+MoLLDbT+dEnSPLqVyrNzSk0NG+bbGmXK0 vq5/KapBbulnKEGqDyot+jrenBdp/Y6+5NlsCu5Qru5sjS2s7RyugPfXXjYf2ersy45K OR5w== X-Gm-Message-State: AAQBX9fXW6l+x5k4ly595Dn1jEtf9OUHh8Nh8qJnq38McgmMQTC25fXC wlKcQa9d/maVcvlaFxzjkPpMg1Ei3+E= X-Google-Smtp-Source: AKy350aHQse4Fm2i7kY+4mdUGKhwYD5OWUSPe8CPb49dh1SKXpQCTSIx3l9qyXiLDLt5ZYBtPOp1UQ== X-Received: by 2002:a5d:4d06:0:b0:2e5:d4f4:c43b with SMTP id z6-20020a5d4d06000000b002e5d4f4c43bmr4655587wrt.55.1682089078801; Fri, 21 Apr 2023 07:57:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n16-20020a05600c181000b003f046ad52efsm8325963wmp.31.2023.04.21.07.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 07:57:58 -0700 (PDT) Message-Id: <31bb644e769a085bd2db97cdb5aae78729efc52d.1682089075.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Apr 2023 14:57:51 +0000 Subject: [PATCH v2 3/6] sequencer: factor out part of pick_commits() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Stefan Haller , Phillip Wood , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood This is simplifies a change in a later commit. If a pick fails we now return the error at then end of the loop body rather than returning early but there is no change in behavior. Signed-off-by: Phillip Wood --- sequencer.c | 129 ++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/sequencer.c b/sequencer.c index c4a548f2c98..2d463818dd1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4628,6 +4628,72 @@ N_("Could not execute the todo command\n" " git rebase --edit-todo\n" " git rebase --continue\n"); +static int pick_one_commit(struct repository *r, + struct todo_list *todo_list, + struct replay_opts *opts, + int *check_todo) +{ + int res; + struct todo_item *item = todo_list->items + todo_list->current; + const char *arg = todo_item_get_arg(todo_list, item); + if (is_rebase_i(opts)) + opts->reflog_message = reflog_message( + opts, command_to_string(item->command), NULL); + + res = do_pick_commit(r, item, opts, is_final_fixup(todo_list), + check_todo); + if (is_rebase_i(opts) && res < 0) { + /* Reschedule */ + advise(_(rescheduled_advice), + get_item_line_length(todo_list, todo_list->current), + get_item_line(todo_list, todo_list->current)); + todo_list->current--; + if (save_todo(todo_list, opts)) + return -1; + } + if (item->command == TODO_EDIT) { + struct commit *commit = item->commit; + if (!res) { + if (!opts->verbose) + term_clear_line(); + fprintf(stderr, _("Stopped at %s... %.*s\n"), + short_commit_name(commit), item->arg_len, arg); + } + return error_with_patch(r, commit, + arg, item->arg_len, opts, res, !res); + } + if (is_rebase_i(opts) && !res) + record_in_rewritten(&item->commit->object.oid, + peek_command(todo_list, 1)); + if (res && is_fixup(item->command)) { + if (res == 1) + intend_to_amend(); + return error_failed_squash(r, item->commit, opts, + item->arg_len, arg); + } else if (res && is_rebase_i(opts) && item->commit) { + int to_amend = 0; + struct object_id oid; + + /* + * If we are rewording and have either + * fast-forwarded already, or are about to + * create a new root commit, we want to amend, + * otherwise we do not. + */ + if (item->command == TODO_REWORD && + !repo_get_oid(r, "HEAD", &oid) && + (oideq(&item->commit->object.oid, &oid) || + (opts->have_squash_onto && + oideq(&opts->squash_onto, &oid)))) + to_amend = 1; + + return res | error_with_patch(r, item->commit, + arg, item->arg_len, opts, + res, to_amend); + } + return res; +} + static int pick_commits(struct repository *r, struct todo_list *todo_list, struct replay_opts *opts) @@ -4683,66 +4749,9 @@ static int pick_commits(struct repository *r, } } if (item->command <= TODO_SQUASH) { - if (is_rebase_i(opts)) - opts->reflog_message = reflog_message(opts, - command_to_string(item->command), NULL); - - res = do_pick_commit(r, item, opts, - is_final_fixup(todo_list), - &check_todo); - if (is_rebase_i(opts) && res < 0) { - /* Reschedule */ - advise(_(rescheduled_advice), - get_item_line_length(todo_list, - todo_list->current), - get_item_line(todo_list, - todo_list->current)); - todo_list->current--; - if (save_todo(todo_list, opts)) - return -1; - } - if (item->command == TODO_EDIT) { - struct commit *commit = item->commit; - if (!res) { - if (!opts->verbose) - term_clear_line(); - fprintf(stderr, - _("Stopped at %s... %.*s\n"), - short_commit_name(commit), - item->arg_len, arg); - } - return error_with_patch(r, commit, - arg, item->arg_len, opts, res, !res); - } - if (is_rebase_i(opts) && !res) - record_in_rewritten(&item->commit->object.oid, - peek_command(todo_list, 1)); - if (res && is_fixup(item->command)) { - if (res == 1) - intend_to_amend(); - return error_failed_squash(r, item->commit, opts, - item->arg_len, arg); - } else if (res && is_rebase_i(opts) && item->commit) { - int to_amend = 0; - struct object_id oid; - - /* - * If we are rewording and have either - * fast-forwarded already, or are about to - * create a new root commit, we want to amend, - * otherwise we do not. - */ - if (item->command == TODO_REWORD && - !repo_get_oid(r, "HEAD", &oid) && - (oideq(&item->commit->object.oid, &oid) || - (opts->have_squash_onto && - oideq(&opts->squash_onto, &oid)))) - to_amend = 1; - - return res | error_with_patch(r, item->commit, - arg, item->arg_len, opts, - res, to_amend); - } + res = pick_one_commit(r, todo_list, opts, &check_todo); + if (!res && item->command == TODO_EDIT) + return 0; } else if (item->command == TODO_EXEC) { char *end_of_arg = (char *)(arg + item->arg_len); int saved = *end_of_arg; From patchwork Fri Apr 21 14:57:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13220244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1188C7618E for ; Fri, 21 Apr 2023 14:58:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233120AbjDUO6S (ORCPT ); Fri, 21 Apr 2023 10:58:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233065AbjDUO6H (ORCPT ); Fri, 21 Apr 2023 10:58:07 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B75F9EED for ; Fri, 21 Apr 2023 07:58:01 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3f1957e80a2so13293855e9.1 for ; Fri, 21 Apr 2023 07:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682089079; x=1684681079; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=U2MevsFjzCo/FdzgO3J99SpPyXyqksiZIEkZP51T2rs=; b=jEzm7ngR+2GSBIRYB6558eDnaIp5p3ZIkLybtdLrHXtnR1au7qxWCGWKbbjloiXTQk yP0ksD4aGl1XXpUqq11zK5LV9ROWU3PvRmvERVvU5Mv67VBSTfR2vpZpi4DMo377/KS3 dK0OMyDNyXuFfMmqYZlh6iwEflw9bMueF4Y8tc90BxEftZA1KgaiSaHV2e3W4ZPv9NMc QmWoOQnOn6Oa6JppDD/E1YBYrkgW+eS/njZjsgI9k2I33q6uAsL0lLf6suFgagdBKCWd 6oHGTIXIrTo8wOmmIQDKYYxY0VrOKSffQsi8GOR0QqX6gpsY0tbFxcS6CqMugVUiMQ4U 2fIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682089079; x=1684681079; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U2MevsFjzCo/FdzgO3J99SpPyXyqksiZIEkZP51T2rs=; b=DEpFnrKfEPH3N4ZU7cPeipJQqSEmfRV8566n5Mq+Z1hDXZ3JSnP0z9/u0+SsXIn1tS VmBC2Ypw+iQy3Bh/bl1gfGp9rjPbPRTbYPSRfOP+EYwlamIpulexr/cBE9rYP+AuItu4 7hC5YINAUyxi4u+8WncBKzsoy/Judxivopgl/DuDj5TcHwNyyOGu/a+oLiklMG5LvD6W 8okhUQnIRdZIoP4lVXSFfm7wrdSrxQbH/282M/dA8b28mlQGHssT8ONtr7DLyw+SHSjb Q0Qdm1KJz/Ez+90K6ZoKkHKXBjfcpgNNcaFImqVdEGSzGhNdT4ikpTbg9UDBpbLx2iYd 0hnA== X-Gm-Message-State: AAQBX9c01e6ghOvnyZ5JsNXFFRBcC0BH71bWIp8IMY2avPHBRE1zMJz3 eothJVrGWRMdj6RdvMENjeqKHHInmLg= X-Google-Smtp-Source: AKy350YRz9o54B6yIU/JPRuxiupE7Hksq3RmfSkccKtsLEkQMN2Km9shjhY0SGX+IjpDruIyVRiowg== X-Received: by 2002:a1c:ed01:0:b0:3f1:6f57:6fd1 with SMTP id l1-20020a1ced01000000b003f16f576fd1mr2229352wmh.9.1682089079595; Fri, 21 Apr 2023 07:57:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n20-20020a7bc5d4000000b003f17b96793dsm8351575wmk.37.2023.04.21.07.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 07:57:59 -0700 (PDT) Message-Id: <9356d14b09a468d8ef2884cd7d76e59ec5c16691.1682089075.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Apr 2023 14:57:52 +0000 Subject: [PATCH v2 4/6] rebase --continue: refuse to commit after failed command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Stefan Haller , Phillip Wood , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood If a commit cannot be picked because it would overwrite an untracked file then "git rebase --continue" should refuse to commit any staged changes as the commit was not picked. Do this by using the existing check for a missing author script in run_git_commit() which prevents "rebase --continue" from committing staged changes after failed exec commands. When fast-forwarding it is not necessary to write the author script as we're reusing an existing commit, not creating a new one. If a fast-forwarded commit is modified by an "edit" or "reword" command then the modification is committed with "git commit --amend" which reuses the author of the commit being amended so the author script is not needed. baf8ec8d3a (rebase -r: don't write .git/MERGE_MSG when fast-forwarding, 2021-08-20) changed run_git_commit() to allow a missing author script when rewording a commit. This changes extends that to allow a missing author script whenever the commit is being amended. If we're not fast-forwarding then we must remove the author script if the pick fails. Signed-off-by: Phillip Wood --- sequencer.c | 10 +++++----- t/t3404-rebase-interactive.sh | 8 ++++++++ t/t3430-rebase-merges.sh | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sequencer.c b/sequencer.c index 2d463818dd1..55bf0a72c3a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1055,7 +1055,7 @@ static int run_git_commit(const char *defmsg, if (is_rebase_i(opts) && ((opts->committer_date_is_author_date && !opts->ignore_date) || - !(!defmsg && (flags & AMEND_MSG))) && + !(flags & AMEND_MSG)) && read_env_script(&cmd.env)) { const char *gpg_opt = gpg_sign_opt_quoted(opts); @@ -2216,8 +2216,6 @@ static int do_pick_commit(struct repository *r, if (opts->allow_ff && !is_fixup(command) && ((parent && oideq(&parent->object.oid, &head)) || (!parent && unborn))) { - if (is_rebase_i(opts)) - write_author_script(msg.message); res = fast_forward_to(r, &commit->object.oid, &head, unborn, opts); if (res || command != TODO_REWORD) @@ -2324,9 +2322,10 @@ static int do_pick_commit(struct repository *r, command == TODO_REVERT) { res = do_recursive_merge(r, base, next, base_label, next_label, &head, &msgbuf, opts); - if (res < 0) + if (res < 0) { + unlink(rebase_path_author_script()); goto leave; - + } res |= write_message(msgbuf.buf, msgbuf.len, git_path_merge_msg(r), 0); } else { @@ -4141,6 +4140,7 @@ static int do_merge(struct repository *r, if (ret < 0) { error(_("could not even attempt to merge '%.*s'"), merge_arg_len, arg); + unlink(rebase_path_author_script()); goto leave_merge; } /* diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index ff0afad63e2..c1fe55dc2c1 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1288,6 +1288,12 @@ test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' test_must_fail git rebase --continue && test_cmp_rev HEAD F && rm file6 && + test_path_is_missing .git/rebase-merge/author-script && + echo changed >file1 && + git add file1 && + test_must_fail git rebase --continue 2>err && + grep "error: you have staged changes in your working tree" err && + git reset --hard HEAD && git rebase --continue && test_cmp_rev HEAD I ' @@ -1306,6 +1312,7 @@ test_expect_success 'rebase -i commits that overwrite untracked files (squash)' test_must_fail git rebase --continue && test_cmp_rev HEAD F && rm file6 && + test_path_is_missing .git/rebase-merge/author-script && git rebase --continue && test $(git cat-file commit HEAD | sed -ne \$p) = I && git reset --hard original-branch2 @@ -1324,6 +1331,7 @@ test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' ' test_must_fail git rebase --continue && test $(git cat-file commit HEAD | sed -ne \$p) = F && rm file6 && + test_path_is_missing .git/rebase-merge/author-script && git rebase --continue && test $(git cat-file commit HEAD | sed -ne \$p) = I ' diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index f03599c63b9..360ec787ffd 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -168,13 +168,15 @@ test_expect_success 'failed `merge -C` writes patch (may be rescheduled, too)' ' grep "^merge -C .* G$" .git/rebase-merge/done && grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo && test_path_is_file .git/rebase-merge/patch && + test_path_is_missing .git/rebase-merge/author-script && : fail because of merge conflict && rm G.t .git/rebase-merge/patch && git reset --hard conflicting-G && test_must_fail git rebase --continue && ! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo && - test_path_is_file .git/rebase-merge/patch + test_path_is_file .git/rebase-merge/patch && + test_path_is_file .git/rebase-merge/author-script ' test_expect_success 'failed `merge ` does not crash' ' From patchwork Fri Apr 21 14:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13220245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A109CC77B71 for ; Fri, 21 Apr 2023 14:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232698AbjDUO6U (ORCPT ); Fri, 21 Apr 2023 10:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233093AbjDUO6J (ORCPT ); Fri, 21 Apr 2023 10:58:09 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2884413FAE for ; Fri, 21 Apr 2023 07:58:02 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f192c23fffso5089505e9.3 for ; Fri, 21 Apr 2023 07:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682089080; x=1684681080; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=X6ZTi5DbeqtQ0CXMRhXm8T2Is7n6iq4nnCg5hmP9vXI=; b=PbwurQHiB4O1cp1PSCn9VPm02sm3XOddBUSrPTJwyglh2AQGiYhBcAUsxaEiTESqBU wnfPjHy2XlyQJ5ZypwxslZUtjFS16L3cTt0eHLlQfOA2lHWLn2gIcDPbhTZmc30V2wJn VKhQTmrVqSHnXns6/LUAxIJAvXCyhkGS+bVNaAJnBzHs0SDQYrbTqvqbVq+5ZrPIoM73 Um8gC2ZVKb4Kf4VDsZiZrMEMT2yFFmR9k6MG4AwuEugLmx6v+d+hIeAmPOXZFM/9a/uo ywFuhRlFiow0IkLAHdUyOShWcfdRVE9cHzjLWF9c8r+XV/Fa49qyIS2RVN3yTn/4ME1Z 681g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682089080; x=1684681080; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X6ZTi5DbeqtQ0CXMRhXm8T2Is7n6iq4nnCg5hmP9vXI=; b=knnN1JaW5pQh6oGAbP7xO9X7EXd3uA28F7kHlDA6wLAveYjrhmBgrSVB1rOo1f3mQg Vi6eYj8e0fN9l272joNbqt5/OneV3Tq/gRy7AldnUyMqdF96zeHjF0KK2OVVB3I97CAl rQgE31FqTR0NbUeRQBDjSWwlkjUelz/driVJNS7kNgYAPv/E1AtKZQOFveGkwwPwleiu IC5qbRdZM2n2Dpxv/xxVtocb+AEDiwD30yPm9uYl1lNGvT9ckgM9yTRVFt5P3pmq/f79 HLPpt+fiMKh4lksl/ZzOEO7tFZUtVWlk7ikAItUJwRPuXC9KsRjZCqGB2CtM5zITijbJ yzwg== X-Gm-Message-State: AAQBX9diIJN7HDBPEfsL/PSif2Hy9dAcZYR3VqjUHuVcUexFTvhRA+V6 uopaXv6pPLSO18SE5ridS0LC/zYrLhY= X-Google-Smtp-Source: AKy350YMW6IIX+ahmj9FM3v/b31gujc17VuC0Gdj0DNJSp2hHnygoXzs4FvoAbet/V8hTsDw8pFpwA== X-Received: by 2002:a7b:c3d8:0:b0:3f1:7972:429d with SMTP id t24-20020a7bc3d8000000b003f17972429dmr2189650wmj.18.1682089080339; Fri, 21 Apr 2023 07:58:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o10-20020a05600c510a00b003ee443bf0c7sm8482007wms.16.2023.04.21.07.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 07:57:59 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Apr 2023 14:57:53 +0000 Subject: [PATCH v2 5/6] rebase: fix rewritten list for failed pick Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Stefan Haller , Phillip Wood , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When rebasing commands are moved from the todo list in "git-rebase-todo" to the "done" file just before they are executed. This means that if a command fails because it would overwrite an untracked file it has to be added back into the todo list before the rebase stops for the user to fix the problem. Unfortunately the way this is done results in the failed pick being recorded as rewritten. Fix this by not calling error_with_patch() for failed commands. The pick has failed so there is nothing to commit and therefore we do not want to set up the message file for committing staged changes when the rebase continues. This change means we no-longer write a patch for the failed command or display the error message printed by error_with_patch(). As the command has failed the patch isn't really useful in that case and REBASE_HEAD is still written so the user can inspect the commit associated with the failed command. Unless the user has disabled it we print an advice message that is more helpful than the message from error_with_patch(). If the advice is disabled the user will still see the messages from the merge machinery detailing the problem. To simplify writing REBASE_HEAD in this case pick_one_commit() is modified to avoid duplicating the code that adds the failed command back into the todo list. Signed-off-by: Phillip Wood --- sequencer.c | 19 +++++++------------ t/t3404-rebase-interactive.sh | 12 ++++++++++++ t/t3430-rebase-merges.sh | 11 ++++++++--- t/t5407-post-rewrite-hook.sh | 11 +++++++++++ 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/sequencer.c b/sequencer.c index 55bf0a72c3a..db2daecb23e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4141,6 +4141,7 @@ static int do_merge(struct repository *r, error(_("could not even attempt to merge '%.*s'"), merge_arg_len, arg); unlink(rebase_path_author_script()); + unlink(git_path_merge_msg(r)); goto leave_merge; } /* @@ -4631,7 +4632,7 @@ N_("Could not execute the todo command\n" static int pick_one_commit(struct repository *r, struct todo_list *todo_list, struct replay_opts *opts, - int *check_todo) + int *check_todo, int* reschedule) { int res; struct todo_item *item = todo_list->items + todo_list->current; @@ -4644,12 +4645,8 @@ static int pick_one_commit(struct repository *r, check_todo); if (is_rebase_i(opts) && res < 0) { /* Reschedule */ - advise(_(rescheduled_advice), - get_item_line_length(todo_list, todo_list->current), - get_item_line(todo_list, todo_list->current)); - todo_list->current--; - if (save_todo(todo_list, opts)) - return -1; + *reschedule = 1; + return -1; } if (item->command == TODO_EDIT) { struct commit *commit = item->commit; @@ -4749,7 +4746,8 @@ static int pick_commits(struct repository *r, } } if (item->command <= TODO_SQUASH) { - res = pick_one_commit(r, todo_list, opts, &check_todo); + res = pick_one_commit(r, todo_list, opts, &check_todo, + &reschedule); if (!res && item->command == TODO_EDIT) return 0; } else if (item->command == TODO_EXEC) { @@ -4803,10 +4801,7 @@ static int pick_commits(struct repository *r, if (save_todo(todo_list, opts)) return -1; if (item->commit) - return error_with_patch(r, - item->commit, - arg, item->arg_len, - opts, res, 0); + write_rebase_head(&item->commit->object.oid); } else if (is_rebase_i(opts) && check_todo && !res && reread_todo_if_changed(r, todo_list, opts)) { return -1; diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c1fe55dc2c1..a657167befd 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1289,6 +1289,10 @@ test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' test_cmp_rev HEAD F && rm file6 && test_path_is_missing .git/rebase-merge/author-script && + test_path_is_missing .git/rebase-merge/patch && + test_path_is_missing .git/MERGE_MSG && + test_path_is_missing .git/rebase-merge/message && + test_path_is_missing .git/rebase-merge/stopped-sha && echo changed >file1 && git add file1 && test_must_fail git rebase --continue 2>err && @@ -1313,6 +1317,10 @@ test_expect_success 'rebase -i commits that overwrite untracked files (squash)' test_cmp_rev HEAD F && rm file6 && test_path_is_missing .git/rebase-merge/author-script && + test_path_is_missing .git/rebase-merge/patch && + test_path_is_missing .git/MERGE_MSG && + test_path_is_missing .git/rebase-merge/message && + test_path_is_missing .git/rebase-merge/stopped-sha && git rebase --continue && test $(git cat-file commit HEAD | sed -ne \$p) = I && git reset --hard original-branch2 @@ -1332,6 +1340,10 @@ test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' ' test $(git cat-file commit HEAD | sed -ne \$p) = F && rm file6 && test_path_is_missing .git/rebase-merge/author-script && + test_path_is_missing .git/rebase-merge/patch && + test_path_is_missing .git/MERGE_MSG && + test_path_is_missing .git/rebase-merge/message && + test_path_is_missing .git/rebase-merge/stopped-sha && git rebase --continue && test $(git cat-file commit HEAD | sed -ne \$p) = I ' diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 360ec787ffd..18a0bc8fafb 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -167,16 +167,21 @@ test_expect_success 'failed `merge -C` writes patch (may be rescheduled, too)' ' test_must_fail git rebase -ir HEAD && grep "^merge -C .* G$" .git/rebase-merge/done && grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo && - test_path_is_file .git/rebase-merge/patch && + test_path_is_missing .git/rebase-merge/patch && test_path_is_missing .git/rebase-merge/author-script && + test_path_is_missing .git/MERGE_MSG && + test_path_is_missing .git/rebase-merge/message && + test_path_is_missing .git/rebase-merge/stopped-sha && : fail because of merge conflict && - rm G.t .git/rebase-merge/patch && git reset --hard conflicting-G && test_must_fail git rebase --continue && ! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo && test_path_is_file .git/rebase-merge/patch && - test_path_is_file .git/rebase-merge/author-script + test_path_is_file .git/rebase-merge/author-script && + test_path_is_file .git/MERGE_MSG && + test_path_is_file .git/rebase-merge/message && + test_path_is_file .git/rebase-merge/stopped-sha ' test_expect_success 'failed `merge ` does not crash' ' diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 5f3ff051ca2..c490a5137fe 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -173,6 +173,17 @@ test_fail_interactive_rebase () { ) } +test_expect_success 'git rebase with failed pick' ' + test_fail_interactive_rebase "exec_>bar pick 1" --onto C A E && + rm bar && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<-EOF && + $(git rev-parse E) $(git rev-parse HEAD) + EOF + verify_hook_input +' + test_expect_success 'git rebase -i (unchanged)' ' git reset --hard D && clear_hook_input && From patchwork Fri Apr 21 14:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13220246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9854C77B76 for ; Fri, 21 Apr 2023 14:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232807AbjDUO6X (ORCPT ); Fri, 21 Apr 2023 10:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233099AbjDUO6K (ORCPT ); Fri, 21 Apr 2023 10:58:10 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334B510271 for ; Fri, 21 Apr 2023 07:58:03 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f178da21b2so19508365e9.1 for ; Fri, 21 Apr 2023 07:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682089081; x=1684681081; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=W9xmzU9qdl4RThmwjjggxusqHV1EPaesxJDrUbfabqc=; b=S2vF5wdHms24wsJiEHu6SLHENtpXijIKTR3+xIYn64VHgIXTkfc7ZW1Bdif0ouQepd Ss0qXI5ZLBiTbWPsMU5vG77YH/LlVaytIJaGgKzSH0Uua2lGvZMDrT5//twTzH/z0Bxt RFxniqi0kxiFQTQPXYuYOWvzyiMeL8S+2ukA8a5OblK3wXV4jMCjEEWEQrmfkWLSliEQ QdKlhLGDmt9WvlhYiFZDHZTcP0EDGY6NsL2fzu5YKdJzUT6NB/Vxo7imAqE+LSbM+3On oyBOHFiG+P0LriWpKwjCfpk5cD3AbV0fReu4ocHGbzPJdbUdye8Zof+VRRqViVv8A3CV 20eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682089081; x=1684681081; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W9xmzU9qdl4RThmwjjggxusqHV1EPaesxJDrUbfabqc=; b=YpPbqBPetzH7KEHyrOy5yAXcVQ65EBIuX0tF7VWqSZc6VWvSRuPrka+at7AI8cPiht ZUQetU4BA+rrkQZMNCes5uj2KcBh/vjOn7NJDuYsYLRghFN2JRCeMXMQUzs8z4EO3xb/ wYCkvTP91RxSjebsFr5ahAM/kryisbg7jsmh9zG7+vT2s3tEr6eVD9SRRejHO6PKl4t5 8O06RGSDlXKBfbfswxH3a/Li9qLYW2hPkspZxKZfe+AKA86SsXrR+LmIf1WVvMqgGjzr ZXgGKDT5OHvwElreU6/4/AkZRDaCIidfB9Il4cjlud4kODmD1ejmbi5dh9smkm7b3LXZ a3QA== X-Gm-Message-State: AAQBX9c0KhXCswuhnPHkBg0MeMHIROmWNNbeSgZ4Vqai+ziioER/sv5J IqH5UTW3Xhw6TnaBAaoDZk5sqR+sUbg= X-Google-Smtp-Source: AKy350Z2jg666TbKXOXvI/TpddQdMla1bM2wtjYtCow8N5sPznYZ91pOsFuT9VIywuaszCWT5LQLRA== X-Received: by 2002:a1c:7908:0:b0:3f1:6ead:e389 with SMTP id l8-20020a1c7908000000b003f16eade389mr2087078wme.30.1682089081078; Fri, 21 Apr 2023 07:58:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n16-20020adfe350000000b002c71b4d476asm4532611wrj.106.2023.04.21.07.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 07:58:00 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Apr 2023 14:57:54 +0000 Subject: [PATCH v2 6/6] rebase -i: fix adding failed command to the todo list Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Stefan Haller , Phillip Wood , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When rebasing commands are moved from the todo list in "git-rebase-todo" to the "done" file (which is used by "git status" to show the recently executed commands) just before they are executed. This means that if a command fails because it would overwrite an untracked file it has to be added back into the todo list before the rebase stops for the user to fix the problem. Unfortunately when a failed command is added back into the todo list the command preceding it is erroneously appended to the "done" file. This means that when rebase stops after "pick B" fails the "done" file contains pick A pick B pick A instead of pick A pick B Fix this by not updating the "done" file when adding a failed command back into the "git-rebase-todo" file. A couple of the existing tests are modified to improve their coverage as none of them trigger this bug or check the "done" file. Reported-by: Stefan Haller Signed-off-by: Phillip Wood --- sequencer.c | 12 ++++++------ t/t3404-rebase-interactive.sh | 27 +++++++++++++++++---------- t/t3430-rebase-merges.sh | 22 ++++++++++++++++------ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/sequencer.c b/sequencer.c index db2daecb23e..9769dde00e8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3379,7 +3379,8 @@ give_advice: return -1; } -static int save_todo(struct todo_list *todo_list, struct replay_opts *opts) +static int save_todo(struct todo_list *todo_list, struct replay_opts *opts, + int reschedule) { struct lock_file todo_lock = LOCK_INIT; const char *todo_path = get_todo_path(opts); @@ -3389,7 +3390,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts) * rebase -i writes "git-rebase-todo" without the currently executing * command, appending it to "done" instead. */ - if (is_rebase_i(opts)) + if (is_rebase_i(opts) && !reschedule) next++; fd = hold_lock_file_for_update(&todo_lock, todo_path, 0); @@ -3402,7 +3403,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts) if (commit_lock_file(&todo_lock) < 0) return error(_("failed to finalize '%s'"), todo_path); - if (is_rebase_i(opts) && next > 0) { + if (is_rebase_i(opts) && !reschedule && next > 0) { const char *done = rebase_path_done(); int fd = open(done, O_CREAT | O_WRONLY | O_APPEND, 0666); int ret = 0; @@ -4716,7 +4717,7 @@ static int pick_commits(struct repository *r, const char *arg = todo_item_get_arg(todo_list, item); int check_todo = 0; - if (save_todo(todo_list, opts)) + if (save_todo(todo_list, opts, reschedule)) return -1; if (is_rebase_i(opts)) { if (item->command != TODO_COMMENT) { @@ -4797,8 +4798,7 @@ static int pick_commits(struct repository *r, get_item_line_length(todo_list, todo_list->current), get_item_line(todo_list, todo_list->current)); - todo_list->current--; - if (save_todo(todo_list, opts)) + if (save_todo(todo_list, opts, reschedule)) return -1; if (item->commit) write_rebase_head(&item->commit->object.oid); diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index a657167befd..653c19bc9c8 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1276,18 +1276,23 @@ test_expect_success 'todo count' ' ' test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' - git checkout --force branch2 && + git checkout --force A && git clean -f && + cat >todo <<-EOF && + exec >file2 + pick $(git rev-parse B) B + pick $(git rev-parse C) C + pick $(git rev-parse D) D + exec cat .git/rebase-merge/done >actual + EOF ( - set_fake_editor && - FAKE_LINES="edit 1 2" git rebase -i A + set_replace_editor todo && + test_must_fail git rebase -i A ) && - test_cmp_rev HEAD F && - test_path_is_missing file6 && - >file6 && - test_must_fail git rebase --continue && - test_cmp_rev HEAD F && - rm file6 && + test_cmp_rev HEAD B && + head -n3 todo >expect && + test_cmp expect .git/rebase-merge/done && + rm file2 && test_path_is_missing .git/rebase-merge/author-script && test_path_is_missing .git/rebase-merge/patch && test_path_is_missing .git/MERGE_MSG && @@ -1299,7 +1304,9 @@ test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' grep "error: you have staged changes in your working tree" err && git reset --hard HEAD && git rebase --continue && - test_cmp_rev HEAD I + test_cmp_rev HEAD D && + tail -n3 todo >>expect && + test_cmp expect actual ' test_expect_success 'rebase -i commits that overwrite untracked files (squash)' ' diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 18a0bc8fafb..86f4e0e4d6f 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -128,14 +128,24 @@ test_expect_success 'generate correct todo list' ' ' test_expect_success '`reset` refuses to overwrite untracked files' ' - git checkout -b refuse-to-reset && + git checkout B && test_commit dont-overwrite-untracked && - git checkout @{-1} && - : >dont-overwrite-untracked.t && - echo "reset refs/tags/dont-overwrite-untracked" >script-from-scratch && + cat >script-from-scratch <<-EOF && + exec >dont-overwrite-untracked.t + pick $(git rev-parse B) B + reset refs/tags/dont-overwrite-untracked + pick $(git rev-parse C) C + exec cat .git/rebase-merge/done >actual + EOF test_config sequence.editor \""$PWD"/replace-editor.sh\" && - test_must_fail git rebase -ir HEAD && - git rebase --abort + test_must_fail git rebase -ir A && + test_cmp_rev HEAD B && + head -n3 script-from-scratch >expect && + test_cmp expect .git/rebase-merge/done && + rm dont-overwrite-untracked.t && + git rebase --continue && + tail -n3 script-from-scratch >>expect && + test_cmp expect actual ' test_expect_success '`reset` rejects trees' '