From patchwork Sun Jun 19 06:50:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 12886554 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 2DF89C433EF for ; Sun, 19 Jun 2022 06:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234080AbiFSGul (ORCPT ); Sun, 19 Jun 2022 02:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230412AbiFSGuc (ORCPT ); Sun, 19 Jun 2022 02:50:32 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E06C0B1C2 for ; Sat, 18 Jun 2022 23:50:30 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id c21so10623100wrb.1 for ; Sat, 18 Jun 2022 23:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eMYu1f5s0ZlNeir2jCvyf9PKMMh08qeDUrXCYegKz+U=; b=e/pbqeqpvijHazW7v0MP1NM2CAGX5kNmlhqQQ1JjdB7xN3U5D997SHP87rz3JJYvkW IbhAsRxknpEiwusQmnVlbzbsRVZ+CzA5qrjzEWf9hEbUm6eBiueLb1YSvbaqsfjd+Njq ayM42POnqnBPC3AdCxx2792ia1aRocCO0IQKzJxmt1Y3L6K2MHUQoQeLmWLaFyNfzfMq txzPWoPmmkR5QhbwBtfgGO6nxb6OlVvQ+O/P6uNnvtsQBd+ZTQ7s8IEzQtQY9364W+RS 8UrhMIqTH1BBGrsRbK9kVSHGwjI/GDGHnXLOMjIWLterdncj5yRh+5HSj9akWuYsTlPQ ggdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eMYu1f5s0ZlNeir2jCvyf9PKMMh08qeDUrXCYegKz+U=; b=bS66/Yqp8u1LnUWjxja7E1D/7LxpQ3W8SulEnNc8785TuPQ9WW7M2znMTtv8knRQOe UJdhop2K7GCtDJYAR+qDVN/A8IINIkl4R9atmLsyN6vao8sL3OU9vavCJkc6Dok6xJUX xpwdWiQy5DhN+wFS2F8xyXrIumA5UPXVLYeeDHgGlv2OYrFbgQcU+VMdDPdC0U46x1rv OUWyYKela38CE337JJOe5EVUa2hNUVoBwY1NSJYl4lzXVIfntRQGxPdJYXHnmz0nxt29 XwTZINnW+yO36pQ0lzKTTIWrazVGA5xIKkKIzWOTnW2U5UTpsjRMdhL2XjCcFi3fegFk 5p5g== X-Gm-Message-State: AJIora+1+zUUVrSMKVM2iShP3onKBqfCtTiDWFWrs0CZvztGQkmpiMSL EaW8wyCRmrSO3wqJLq5EI770ZmxCzpThgQ== X-Google-Smtp-Source: AGRyM1ssFNPQiifym60Z+hcMQG506BAa+ZhFrciGhvVElh59OZvbQnrXGGuWno3J9spnW8sOk059yw== X-Received: by 2002:a5d:4d8f:0:b0:210:3e14:ff27 with SMTP id b15-20020a5d4d8f000000b002103e14ff27mr16614772wru.81.1655621429016; Sat, 18 Jun 2022 23:50:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n10-20020adffe0a000000b0021b5861eaf7sm6629098wrr.3.2022.06.18.23.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 23:50:27 -0700 (PDT) Message-Id: <6147e72c3097fec85d6202a600d06b1ad222b49a.1655621424.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 19 Jun 2022 06:50:19 +0000 Subject: [PATCH v2 1/6] t6424: make sure a failed merge preserves local changes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Elijah Newren , Junio C Hamano Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Junio C Hamano From: Junio C Hamano We do make sure that an attempt to merge with various forms of local changes will "fail", but the point of stopping the merge is so that we refrain from discarding uncommitted local changes that could be precious. Add a few more checks for each case to make sure the local changes are left intact. Signed-off-by: Junio C Hamano --- t/t6424-merge-unrelated-index-changes.sh | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/t/t6424-merge-unrelated-index-changes.sh b/t/t6424-merge-unrelated-index-changes.sh index 89dd544f388..b6e424a427b 100755 --- a/t/t6424-merge-unrelated-index-changes.sh +++ b/t/t6424-merge-unrelated-index-changes.sh @@ -71,7 +71,9 @@ test_expect_success 'ff update' ' git merge E^0 && test_must_fail git rev-parse HEAD:random_file && - test "$(git diff --name-only --cached E)" = "random_file" + test "$(git diff --name-only --cached E)" = "random_file" && + test_path_is_file random_file && + git rev-parse --verify :random_file ' test_expect_success 'ff update, important file modified' ' @@ -83,6 +85,8 @@ test_expect_success 'ff update, important file modified' ' git add subdir/e && test_must_fail git merge E^0 && + test_path_is_file subdir/e && + git rev-parse --verify :subdir/e && test_path_is_missing .git/MERGE_HEAD ' @@ -93,6 +97,8 @@ test_expect_success 'resolve, trivial' ' touch random_file && git add random_file && test_must_fail git merge -s resolve C^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -103,6 +109,8 @@ test_expect_success 'resolve, non-trivial' ' touch random_file && git add random_file && test_must_fail git merge -s resolve D^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -113,6 +121,8 @@ test_expect_success 'recursive' ' touch random_file && git add random_file && test_must_fail git merge -s recursive C^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -145,9 +155,12 @@ test_expect_success 'recursive, when file has staged changes not matching HEAD n mkdir subdir && test_seq 1 10 >subdir/a && git add subdir/a && + git rev-parse --verify :subdir/a >expect && # We have staged changes; merge should error out test_must_fail git merge -s recursive E^0 2>err && + git rev-parse --verify :subdir/a >actual && + test_cmp expect actual && test_i18ngrep "changes to the following files would be overwritten" err ' @@ -158,9 +171,12 @@ test_expect_success 'recursive, when file has staged changes matching what a mer mkdir subdir && test_seq 1 11 >subdir/a && git add subdir/a && + git rev-parse --verify :subdir/a >expect && # We have staged changes; merge should error out test_must_fail git merge -s recursive E^0 2>err && + git rev-parse --verify :subdir/a >actual && + test_cmp expect actual && test_i18ngrep "changes to the following files would be overwritten" err ' @@ -171,7 +187,9 @@ test_expect_success 'octopus, unrelated file touched' ' touch random_file && git add random_file && test_must_fail git merge C^0 D^0 && - test_path_is_missing .git/MERGE_HEAD + test_path_is_missing .git/MERGE_HEAD && + git rev-parse --verify :random_file && + test_path_exists random_file ' test_expect_success 'octopus, related file removed' ' @@ -181,6 +199,8 @@ test_expect_success 'octopus, related file removed' ' git rm b && test_must_fail git merge C^0 D^0 && + test_path_is_missing b && + test_must_fail git rev-parse --verify :b && test_path_is_missing .git/MERGE_HEAD ' @@ -189,8 +209,12 @@ test_expect_success 'octopus, related file modified' ' git checkout B^0 && echo 12 >>a && git add a && + git rev-parse --verify :a >expect && test_must_fail git merge C^0 D^0 && + test_path_is_file a && + git rev-parse --verify :a >actual && + test_cmp expect actual && test_path_is_missing .git/MERGE_HEAD ' @@ -201,6 +225,8 @@ test_expect_success 'ours' ' touch random_file && git add random_file && test_must_fail git merge -s ours C^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -211,6 +237,8 @@ test_expect_success 'subtree' ' touch random_file && git add random_file && test_must_fail git merge -s subtree E^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' From patchwork Sun Jun 19 06:50:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12886555 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 329E7C433EF for ; Sun, 19 Jun 2022 06:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234132AbiFSGum (ORCPT ); Sun, 19 Jun 2022 02:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbiFSGue (ORCPT ); Sun, 19 Jun 2022 02:50:34 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F4D1BF45 for ; Sat, 18 Jun 2022 23:50:32 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id l126-20020a1c2584000000b0039c1a10507fso4233357wml.1 for ; Sat, 18 Jun 2022 23:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=lt/vUZ0XFMcRtCAMMiib2k753yfBvnatGiqQvguXEkE=; b=WHXXJ9tLFrdBM0SNESqi809OnUYy2+bTIAAk8auPKp8uA3MJZpg9/YJKVazl4M5qF2 zEZk8PXm4Q94n7hwDpgdn2jkZnNE1265QSgZVTVu/WTH4cTddmOh8eyBcHBOgHpVA0gJ F/k28CGA3UHCmsXLLw5f43A0TI4Ay9+Jey3qrVoPa2F7oxCvhOjkNBBwDwnwL4JEpex4 BqhL6BVA5gCGC4u7O0pyZroWfQdNMBMNuvb6OAwcK4uA4cH3qNwHMm8WrmgDxV6ca4J4 i7AEDdJCihweTv2nx9MtWRoV8fARIFvkLxx1dvvWzd0WA+zYG0i1tOXxCdkPYAuxzasc wj/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=lt/vUZ0XFMcRtCAMMiib2k753yfBvnatGiqQvguXEkE=; b=hbDXvfdxZopi4M1MeVdlYXwHZgLc3HicdDWrBuPbYXTY6iIdaj51FjPKGRQKNEeIG/ 6ewI8wtvkPiHGxU8vSet7/s/XLyzzilIU8rSk8G9DmqpmndO+KuAXfxpiTO+30TpxaMJ h8sE5Z5Gpb0p0gzHq/U0ccyrlOcOlCpHA6i2jgths1UZ2MOh/ACvMHZ48mhmJQZ0WhIN LVmwp82yUOiilDmvMSbllTwGfY39Jid0wP4TE+Ffq8fLudUW97GXMqXTNcLKOPLNDc1L O+7+uiwHJrI4uj2Naw93MB5nTcPpmydDSns27flDNATHcoZboVOA14EyCAMazpwOvnDz JZRA== X-Gm-Message-State: AOAM532dNVZ5SDF8VZ4WBdh1UUHLEiK27yy3LSwQyW6E2wHUI0lloW58 SZG7g1O4DVGMOfZE8gotatrnIi9BXCCHPA== X-Google-Smtp-Source: ABdhPJzDgGTOIbrNJmD8FcOVl4tgWuCDqs3+2twHEabeIJmaCYaEArtysHpKS6CnpyGMWB5cNEhvsA== X-Received: by 2002:a05:600c:a41:b0:39c:1512:98bd with SMTP id c1-20020a05600c0a4100b0039c151298bdmr29368983wmq.88.1655621430623; Sat, 18 Jun 2022 23:50:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0021b8208fa51sm5788331wru.80.2022.06.18.23.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 23:50:29 -0700 (PDT) Message-Id: <230d84f09c8b75d15168d5ff8205b543fa8ca91d.1655621424.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 19 Jun 2022 06:50:20 +0000 Subject: [PATCH v2 2/6] merge: remove unused variable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren restore_state() had a local variable sb that is not used, and in fact, was never used even in the original commit that introduced it, 1c7b76be7d ("Build in merge", 2008-07-07). Remove it. Signed-off-by: Elijah Newren --- builtin/merge.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index f178f5a3ee1..00de224a2da 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -375,7 +375,6 @@ static void reset_hard(const struct object_id *oid, int verbose) static void restore_state(const struct object_id *head, const struct object_id *stash) { - struct strbuf sb = STRBUF_INIT; const char *args[] = { "stash", "apply", NULL, NULL }; if (is_null_oid(stash)) @@ -391,7 +390,6 @@ static void restore_state(const struct object_id *head, */ run_command_v_opt(args, RUN_GIT_CMD); - strbuf_release(&sb); refresh_cache(REFRESH_QUIET); } From patchwork Sun Jun 19 06:50:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12886557 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 C0CDFC43334 for ; Sun, 19 Jun 2022 06:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234202AbiFSGuq (ORCPT ); Sun, 19 Jun 2022 02:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbiFSGuh (ORCPT ); Sun, 19 Jun 2022 02:50:37 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E07EFE0E2 for ; Sat, 18 Jun 2022 23:50:33 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id g4so10585617wrh.11 for ; Sat, 18 Jun 2022 23:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=yjOZrvuBpyzsHEWRQuFab+xPmXI5ogEOTch0eMzF0fk=; b=dCDq4kafsheay63onrlyzW3dFL3oHcniKdcq5YkdMNZrcublJrtJKIAbtkI8ISkzcL S68kchehYh7tMNMyLR83wuB9mP2F0lfTf7hfDfzFAiTRNtiVu1/c72zXSNWrak9Zg0Kp CmgVSptM/B5v4SY9chjFuXsQ7emCMPdFY4WX8CliLz7C3TBFG9BfT2NSY8QWjpTRqcBu fNR6K9qo7xgZSRDo7K305BQk8NY3t8sxNaDNjwIsuTZ2VhYdT2hzNsC7XmgfBeJYyl4k DKcXFwxXO8Ou8TAuVdgoiWiDIi0MugEWxsyEvgwwQ4eBnp/hK1eHQ3gf3hYzsCuF8LvP TlkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=yjOZrvuBpyzsHEWRQuFab+xPmXI5ogEOTch0eMzF0fk=; b=MPfHbIoQv9YOCVx0JXw8im9KBlBES5P7cx08LYfvHA3c6vZwkWSANkuvoVSMGUWeFd b07q/lWoDGTVneXKdXEcUdst/puSAipkskd24EJfsBDOOFncknHArHVOCIxnJLrfYJ0E mHJcUQ2suG1370xhmqmCR+Y2pF2d4PN/xjMybUgUyiT1hPFEE+RB53ttqpHG2xMQe7/l oTc9WPM13xrR5bQUFV1Ncqsc4hVrPscQ7/AcUC0uyLsOnRvVNEzLHjWIqRh2uCCoftWa 0hFP6zWcCc82lbWQ4Gs5GesFDtJ5G1rR/aR8YCfALXdVo1PG39r6eNDYRtIdLmipbogm VLpw== X-Gm-Message-State: AJIora9J096N2cTr7/s9ARB3FaFZbSyrszIoUu62qV3Fs9W2t9ApAwxl Mx233N6btZaPESlTz3+H/XNYpbr77NXoHA== X-Google-Smtp-Source: AGRyM1uAfHC8asy8yNtTKb+38SULqZGIp/fZtAhGB5CI54zwsQsu9fLJW3zk+zC73YmZ2zBOQ49vOw== X-Received: by 2002:a05:6000:1862:b0:216:3c40:6708 with SMTP id d2-20020a056000186200b002163c406708mr16852454wri.101.1655621432117; Sat, 18 Jun 2022 23:50:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v11-20020a5d4b0b000000b0020d07d90b71sm9200599wrq.66.2022.06.18.23.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 23:50:31 -0700 (PDT) Message-Id: <89e5e633241e45a0c4b18289ab2fafdaabc8191e.1655621424.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 19 Jun 2022 06:50:21 +0000 Subject: [PATCH v2 3/6] merge: fix save_state() to work when there are racy-dirty files Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren When there are racy-dirty files, but no files are modified, `git stash create` exits with unsuccessful status. This causes merge to fail. Refresh the index first to avoid this problem. Signed-off-by: Elijah Newren --- builtin/merge.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builtin/merge.c b/builtin/merge.c index 00de224a2da..8ce4336dd3f 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -313,8 +313,16 @@ static int save_state(struct object_id *stash) int len; struct child_process cp = CHILD_PROCESS_INIT; struct strbuf buffer = STRBUF_INIT; + struct lock_file lock_file = LOCK_INIT; + int fd; int rc = -1; + fd = repo_hold_locked_index(the_repository, &lock_file, 0); + refresh_cache(REFRESH_QUIET); + if (0 <= fd) + repo_update_index_if_able(the_repository, &lock_file); + rollback_lock_file(&lock_file); + strvec_pushl(&cp.args, "stash", "create", NULL); cp.out = -1; cp.git_cmd = 1; From patchwork Sun Jun 19 06:50:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12886556 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 2582AC433EF for ; Sun, 19 Jun 2022 06:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234197AbiFSGuo (ORCPT ); Sun, 19 Jun 2022 02:50:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234076AbiFSGuh (ORCPT ); Sun, 19 Jun 2022 02:50:37 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9371CB1CC for ; Sat, 18 Jun 2022 23:50:35 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id w17so10582251wrg.7 for ; Sat, 18 Jun 2022 23:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=AAEHqAyh6Hw2t1Qs24FsOj3XLBmYcT9ZZul30+M6APM=; b=AF6KLnzaoGy+T2r9T86eFcqDu25kjVZiu1E13o73tuoaNn0LpkuKzhoZ/nXecZEQIX vwZE3yPAstKfnKQhBALwKvWXDf38o9BvRnkhQH2gp2VzdRsP770tVsWlwqKlGLDBRnrf 6L+mz+a34oZ7xw7CTjyOiKgvJiy4JC+TBkdW++fPwOkqVOIDWQ1tgfHlSpy8gscfCpvO 6thojNPwm14Kowb/5LpAKnAaYEzwM9EZ+2KsKkBiCf72LY+Oetgk3uzlP2KltTf88Rvd Jis1ri3RjPUXMzoKpPiYE3vB+ifAGQ3XfsxHB11WYH4Vu2wWc9m25u6eWREFKo3apnxU 6yCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=AAEHqAyh6Hw2t1Qs24FsOj3XLBmYcT9ZZul30+M6APM=; b=gS48kZQ5ljoqPP0N0fmEEuA5Qp6bcRqxHJ92rxljApNpZzSGP/wuwDv8Ay7bJV4FVA c+kgE0RlTCg+LuO4Cwf+K1PwHOTN+/UKBVNdeaYIqoAfXp9Im+TrqRcMiYlzYMZxqvJP XKb8f6ka2jMYwWnN8LyVAfDHjbh4EdDLB9VAwUdLQV8ciu+l1SvTSfvLNDFBdYJ58L8P uNqmokU7OvfHQC0WKttO3pPLJar3+8w4JusQK4v75RHf8Nj1bNMCHnG0IjoUB+AypRM3 DWWIBKHV4cgl5Nm6Ow0GXtTQRA2xlgjgmmzhZu0FdAzDv5ZzEB/SDqOhudhNx9ggqZk5 Tu9A== X-Gm-Message-State: AJIora8c7uIb4aM5qQPSCLcp4qBX5pWNiRYGWyp2nE+972oqY3or8blX 3V689l93NrTBu6fPsbSiqjFe8seJeg/z5g== X-Google-Smtp-Source: AGRyM1veeDmRlOgfBDdiWnNbPXFkynLFwoNQyaPhXWhzWeJhul4SkXDKdQ21cDkJxek2z+4WGU8aoQ== X-Received: by 2002:a05:6000:156c:b0:218:5691:e72b with SMTP id 12-20020a056000156c00b002185691e72bmr16658172wrz.95.1655621433848; Sat, 18 Jun 2022 23:50:33 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o18-20020a5d6852000000b0021552eebde6sm9259374wrw.32.2022.06.18.23.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 23:50:32 -0700 (PDT) Message-Id: <4a8b7c9e06df36444b94b929b2558f40e3f72e81.1655621424.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 19 Jun 2022 06:50:22 +0000 Subject: [PATCH v2 4/6] merge: make restore_state() restore staged state too Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren merge can be invoked with uncommitted changes, including staged changes. merge is responsible for restoring this state if some of the merge strategies make changes. However, it was not restoring staged changes due to the lack of the "--index" option to "git stash apply". Add the option to fix this shortcoming. Signed-off-by: Elijah Newren --- builtin/merge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 8ce4336dd3f..2dc56fab70b 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -383,14 +383,14 @@ static void reset_hard(const struct object_id *oid, int verbose) static void restore_state(const struct object_id *head, const struct object_id *stash) { - const char *args[] = { "stash", "apply", NULL, NULL }; + const char *args[] = { "stash", "apply", "--index", NULL, NULL }; if (is_null_oid(stash)) return; reset_hard(head, 1); - args[2] = oid_to_hex(stash); + args[3] = oid_to_hex(stash); /* * It is OK to ignore error here, for example when there was From patchwork Sun Jun 19 06:50:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12886559 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 2EB5FC43334 for ; Sun, 19 Jun 2022 06:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234325AbiFSGus (ORCPT ); Sun, 19 Jun 2022 02:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234081AbiFSGui (ORCPT ); Sun, 19 Jun 2022 02:50:38 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79696E0F1 for ; Sat, 18 Jun 2022 23:50:37 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id e25so6740700wrc.13 for ; Sat, 18 Jun 2022 23:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/zXXJ+VLNRVlaNZDh3xjYisvuWdRriNBfD/lORGYTOY=; b=ZC03jYmPoR/47M2SjwivGzf72vOuUG14nLX+btkhnj+33avLesyN1LfFdPepw2N+fN xoeHqcSBQWvJIsanNp6xRhHNt8y2H3/1gVg9mpw3CsPJWmGs0+PVyehE0vhfcpjmEefq FSfJFZxfULHtGBy9wTukvNftw0z7gS9lI2of2IYI0Fg0CTXeOcM5LA9o0v0lyAzF4mfc t2YaB+tfEO4weSajl2WmEvFipDUz+4tEFPMk1ygkI/QDwXTB/yKoTw8nZcwOvcodEpMb C0js5ySIcrpsVNmyJYBfslnqazhfTUd0xKKblhCZrH+qpygTaxok7hAEa914fYcbpdS3 sjZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/zXXJ+VLNRVlaNZDh3xjYisvuWdRriNBfD/lORGYTOY=; b=m6t7x6JwaXe4Dp9lf9yy0bpAdIS/h8P8AQIz5irFHD1bCa+9+tw+7V64VfcbmTmA5H CYlPgUXyvclIx961CQP8k0+B7slEq3rRiTRPV0VQCIJ6sIp/x/kDBjJGMXlQdzJ2K44E rXh7C+b09jpd3v835mKLvL5ftwiPnCkA9bdOhDoNfmDUMma3wvuJrkSkdocS+LXxkMM4 yHQ73cqcacXZXBlehHfIQvZslr6WME+4dkBu1AkZTkZO0VW5b+OZBoncvw1PO5+cbpBf ymlAXxKVFkH6kGNPQ5faK9STBhy3OiygAjJWnYod+n1JUfRiILpKUGj/r6uJK13vUPHZ WnZQ== X-Gm-Message-State: AJIora/T6eJQBN68zehiKjmBHXqvHGZwBKO0OGjsQGI8ZJaP7/0W1QSm VdOX/XJJOIAmqXu5Ur+W0iLXIqScodHavQ== X-Google-Smtp-Source: AGRyM1sm0S+7cA+RUCwRcyRK9brTEwFQqaOL8xELAihioAma2G8PWkPgyM9pJyq0X00L9IivSHtvsg== X-Received: by 2002:a5d:6606:0:b0:21b:84af:5360 with SMTP id n6-20020a5d6606000000b0021b84af5360mr6684657wru.340.1655621435744; Sat, 18 Jun 2022 23:50:35 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bk10-20020a0560001d8a00b0021a05379fd3sm9218491wrb.30.2022.06.18.23.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 23:50:34 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 19 Jun 2022 06:50:23 +0000 Subject: [PATCH v2 5/6] merge: ensure we can actually restore pre-merge state Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Merge strategies can fail -- not just have conflicts, but give up and say that they are unable to handle the current type of merge. However, they can also make changes to the index and working tree before giving up; merge-octopus does this, for example. Currently, we do not expect the individual strategies to clean up after themselves, but instead expect builtin/merge.c to do so. For it to be able to, it needs to save the state before trying the merge strategy so it can have something to restore to. Therefore, remove the shortcut bypassing the save_state() call. Signed-off-by: Elijah Newren --- builtin/merge.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 2dc56fab70b..aaee8f6a553 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1663,12 +1663,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * tree in the index -- this means that the index must be in * sync with the head commit. The strategies are responsible * to ensure this. + * + * Stash away the local changes so that we can try more than one. */ - if (use_strategies_nr == 1 || - /* - * Stash away the local changes so that we can try more than one. - */ - save_state(&stash)) + if (save_state(&stash)) oidclr(&stash); for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) { From patchwork Sun Jun 19 06:50:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12886558 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 2EF2CC433EF for ; Sun, 19 Jun 2022 06:50:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234302AbiFSGur (ORCPT ); Sun, 19 Jun 2022 02:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234083AbiFSGuj (ORCPT ); Sun, 19 Jun 2022 02:50:39 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39924B1C2 for ; Sat, 18 Jun 2022 23:50:38 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id g4so10585617wrh.11 for ; Sat, 18 Jun 2022 23:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Agsq2Wf9D/YaxwlLDiCGryUih1KGDxKwRg1Umh8QQUI=; b=he8EVVlIGMdbBWcNiwhRHNHPKYvmCxRPMta0UtfYKAkLG7cMdcgRlFRahghuQ8Sknx YKr8Ag2HifoALxWIooeP0Gb9vOgOdM7JqdYQVgigbaWlCW9iy4ZH2jp3UoGrAgVOPuW0 Ua9Uj6B9atgorAJFkCET352rvc9jdjh4UqtkiiZOmA0K+gQymU9S665dIJIgNV3DDl1R aD0ZQhzEEgSsgzeUJkg1otW3XDAkbrKi9w7JcA2oT2GQ2gNMyAD80zXg+FJm7dCtuGfx UQaGwk7ZDLDefcKH2EnBXW8J8uNuWoWjDHGtAM2jPKg0B3pDCYkCotCdogiJrEF4v9bn DxCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Agsq2Wf9D/YaxwlLDiCGryUih1KGDxKwRg1Umh8QQUI=; b=fgu2IB+HG3lKlCttFg3y4pzNt8nCdDTscMrPlj61OCDhL1OFfDD5ShJebOJYgZ1a5p UmRLvpzxVj7TJeoZTOC3y7ehMj2AbAq/w5bLmzKTzgccwE6mZc3iL6WOzEgTr1FGr/Q4 tTSVhoIXlbQrmof+switFoZo+vTz32mKmgWHbz22m4CzBCvxhhwD5WwUOxaOStqkdCjV t55pb2YBqjI8ohgwt5ghoXxZthecPbPkUjsikoUq1zBkmMknGUnc47gWhBf2SspTJy8O dkjpA7ZhH0KRbV5XqlQ0mKMoqQ63oYrF/cck7zWg9SEDFvfzuZFQlBx28sVYbWoOfwSl 5uCA== X-Gm-Message-State: AJIora8PN2snTQMaGqwG2N56yB4dRTNtHRiFOP08G0J7qjcTXKVBdPzv HOPOGoVPT21o4IqUI7mILAfDCUA2DKndRA== X-Google-Smtp-Source: AGRyM1uW2RBe1cMRQGbrl7hPvtocNFtB2VDXuvdxmJQTxeS1614k/WtNyhtbLvgwiTZ4+g2un8F0uQ== X-Received: by 2002:a5d:5c04:0:b0:21a:23e0:6ba3 with SMTP id cc4-20020a5d5c04000000b0021a23e06ba3mr17269686wrb.71.1655621437366; Sat, 18 Jun 2022 23:50:37 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y6-20020a5d6206000000b0021350f7b22esm10008722wru.109.2022.06.18.23.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 23:50:36 -0700 (PDT) Message-Id: <0783b48c121fe74051c13e7d9118d1a5b7cb9aa9.1655621424.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 19 Jun 2022 06:50:24 +0000 Subject: [PATCH v2 6/6] merge: do not exit restore_state() prematurely Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Previously, if the user: * Had no local changes before starting the merge * A merge strategy makes changes to the working tree/index but returns with exit status 2 Then we'd call restore_state() to clean up the changes and either let the next merge strategy run (if there is one), or exit telling the user that no merge strategy could handle the merge. Unfortunately, restore_state() did not clean up the changes as expected; that function was a no-op if the stash was a null, and the stash would be null if there were no local changes before starting the merge. So, instead of "Rewinding the tree to pristine..." as the code claimed, restore_state() would leave garbage around in the index and working tree (possibly including conflicts) for either the next merge strategy or for the user after aborting the merge. And in the case of aborting the merge, the user would be unable to run "git merge --abort" to get rid of the unintended leftover conflicts, because the merge control files were not written as it was presumed that we had restored to a clean state already. Fix the main problem by making sure that restore_state() only skips the stash application if the stash is null rather than skipping the whole function. However, there is a secondary problem -- since merge.c forks subprocesses to do the cleanup, the in-memory index is left out-of-sync. While there was a refresh_cache(REFRESH_QUIET) call that attempted to correct that, that function would not handle cases where the previous merge strategy added conflicted entries. We need to drop the index and re-read it to handle such cases. (Alternatively, we could stop forking subprocesses and instead call some appropriate function to do the work which would update the in-memory index automatically. For now, just do the simple fix.) Reported-by: ZheNing Hu Signed-off-by: Elijah Newren --- builtin/merge.c | 10 ++++++---- t/t7607-merge-state.sh | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 t/t7607-merge-state.sh diff --git a/builtin/merge.c b/builtin/merge.c index aaee8f6a553..a21dece1b55 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -385,11 +385,11 @@ static void restore_state(const struct object_id *head, { const char *args[] = { "stash", "apply", "--index", NULL, NULL }; - if (is_null_oid(stash)) - return; - reset_hard(head, 1); + if (is_null_oid(stash)) + goto refresh_cache; + args[3] = oid_to_hex(stash); /* @@ -398,7 +398,9 @@ static void restore_state(const struct object_id *head, */ run_command_v_opt(args, RUN_GIT_CMD); - refresh_cache(REFRESH_QUIET); +refresh_cache: + if (discard_cache() < 0 || read_cache() < 0) + die(_("could not read index")); } /* This is called when no merge was necessary. */ diff --git a/t/t7607-merge-state.sh b/t/t7607-merge-state.sh new file mode 100755 index 00000000000..655478cd0b3 --- /dev/null +++ b/t/t7607-merge-state.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +test_description="Test that merge state is as expected after failed merge" + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +. ./test-lib.sh + +test_expect_success 'set up custom strategy' ' + test_commit --no-tag "Initial" base base && +git show-ref && + + for b in branch1 branch2 branch3 + do + git checkout -b $b main && + test_commit --no-tag "Change on $b" base $b + done && + + git checkout branch1 && + test_must_fail git merge branch2 branch3 && + git diff --exit-code --name-status && + test_path_is_missing .git/MERGE_HEAD +' + +test_done