From patchwork Fri Jul 23 12:14:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 12396011 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=-12.8 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 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 2163BC432BE for ; Fri, 23 Jul 2021 12:14:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1EDD60ED4 for ; Fri, 23 Jul 2021 12:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234758AbhGWLeB (ORCPT ); Fri, 23 Jul 2021 07:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234612AbhGWLeA (ORCPT ); Fri, 23 Jul 2021 07:34:00 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B447EC061757 for ; Fri, 23 Jul 2021 05:14:33 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id o3-20020a05600c5103b029024c0f9e1a5fso3121804wms.4 for ; Fri, 23 Jul 2021 05:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=jAH3N7M82HZ3MrUhNbVmtE5vAv7GcKpkAAhbEgb1yGY=; b=fySswi2zjqOqc5RiyHdOftrUUTQDIilITamxV0hvTRUoCOv9BJ/Ehre+nQJPrdrulA oXZpASlu4cCwSz2MMVV9ln3IYV7HtcAmfrqmrnhsXMPniMU2G39ig3RGau9b1oFoiqUW PXljtVg3rYnnNIQJtDcYMBJZnVYqdC8QJ16/MuaexLLm1OaHnE1mkL2+9/S8lDlDKj80 WvtW3hjGXMZevk0i5TETig9ASivjV929cvKrB625J0Gl6Ro5gXQuCU6LLlNaR3fnsYAq rlFSDAs/xjzjQT6mWPoG9vR6amE/kySeugL8SZO6jZ9UIwc50FLXrrDkcF2OccMj3OJk bkhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=jAH3N7M82HZ3MrUhNbVmtE5vAv7GcKpkAAhbEgb1yGY=; b=TQx/WNXWH0/eFim+GsFNVjhBmKAnAHc7sd2ah8atXgoKcn31cisv0qzi/8HBYpcAa+ XtYOzqsHShBcJtPwCKCmrAWJw16NeYLu2a0yg3YsXwliK7iiHaqzhcvzsDhhSbuSAYKG lv33EYEhK7DhaPZPLTIDHXYPIvxgMW0gOWj+gVo0fEVFh4Upb+352NjwxLeW1t+YPa88 hiV+nAbxQfalRm0tcW5o9pf58tp6aZLlGR9UUbDX5pi/3Xjp3FPHx59ml2PVchN1GyzB 0VZTCcWHlyWpBASCFaNKJk6+IfwX9M7PxUWVnnsX5NM20YljfkyVm2qe5rYYio2E0wAC vDjQ== X-Gm-Message-State: AOAM531Tfwfb+oEhmDDcjM9r/r5HGeBjedZvBQ0Orp6YW91OVUz/OK/B vUnxmYakxlYRYOphQN565PrJCcUT7Cg= X-Google-Smtp-Source: ABdhPJw3oR5QPrIJx/6CINeRVBJWk/hEyWh3ccn3qPbU0LVAnyzoAkWm0Zik7K/dW2Vq8IKQov+CpQ== X-Received: by 2002:a7b:cc16:: with SMTP id f22mr2272783wmh.99.1627042472407; Fri, 23 Jul 2021 05:14:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w9sm27826039wmc.19.2021.07.23.05.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 05:14:32 -0700 (PDT) Message-Id: <85016e679eb77cbb17edc9b6849251893a5e9ec2.1627042470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Jul 2021 12:14:27 +0000 Subject: [PATCH 1/4] merge: add missing word "strategy" to a message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Denton Liu , Felipe Contreras , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain The variable 'best_strategy' holds the name of the merge strategy that resulted in fewer conflicts, if several strategies were tried. When that's the case but the best strategy was not the first one tried, we inform the user which strategy was the "best" one before recreating the merge and leaving the conflicted files in the tree. This informational message is missing the word "strategy", so it shows something like: Using the recursive to prepare resolving by hand. Fix that. Signed-off-by: Philippe Blain --- builtin/merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index a8a843b1f54..74797b6c7a6 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1715,7 +1715,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) else { printf(_("Rewinding the tree to pristine...\n")); restore_state(&head_commit->object.oid, &stash); - printf(_("Using the %s to prepare resolving by hand.\n"), + printf(_("Using the %s strategy to prepare resolving by hand.\n"), best_strategy); try_merge_strategy(best_strategy, common, remoteheads, head_commit); From patchwork Fri Jul 23 12:14:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 12396015 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=-12.8 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 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 0BC62C432BE for ; Fri, 23 Jul 2021 12:14:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9B1260ED4 for ; Fri, 23 Jul 2021 12:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234819AbhGWLeE (ORCPT ); Fri, 23 Jul 2021 07:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234612AbhGWLeB (ORCPT ); Fri, 23 Jul 2021 07:34:01 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AAECC061575 for ; Fri, 23 Jul 2021 05:14:34 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id e2so2126106wrq.6 for ; Fri, 23 Jul 2021 05:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=lF6XRer7oES/OwiaJHCWeMxdegSRO8OZ/owLXbNfJRU=; b=HjSzPSGu2rMZZJABEKRHFbLoOtIMrLoTcKC6oF61Jfn3qGmN+i9Cfe2iQZZ/hqGc2q jRA3n46yGyW4B8uSNbbUhqP96G+olch49DqvclOUJZGZutrKTHgQ3ftlcmmUQX5+1GUI hxlMoNkFZR2RmiN4EfxtvLjSsK70IyC1sg6L/oYuEiPfNKqSNlbKr/JVoAYWSj29ItEk 3PFqoAZGB89dMaW+ximUK7nB0+lTFg3bmIbpZA5oBplitgoBfuid9gmaG01QVmTpn1Tk sEH6Ghd7yF8D5ACd9JkdHBKXSvYDHoThjEpxzgaq6CgUQP0K1Pl9ZyhLY5tUInriApFB WQ7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=lF6XRer7oES/OwiaJHCWeMxdegSRO8OZ/owLXbNfJRU=; b=eb2hxu/4b0oruRYA+Cy1GUAL3noyfsuQISOzS+HvipR+E6mS3qpABjrTez42MEzH7D nR0cW8GOiBpWohxl/ABenJOLpuTJjoZWqDTciucmxuSnaOGlt8X9H2XG2BRH5xxhE+9B 7es7SxXMOGTAogGzCslZ0+4J8MNOoKc6mmA1sSizsA1jbh4hQjCvcmYmGmMP1f4z8dpO PA6OLIDramD7q86WbHOZkJHAKVeLAb2I9IM/PN4uL3A8UO/HwNXECHA6nU3Gfz55ohJK WKRPRUfk7TfR2uGGpoi/VfbM7KzYT2f9qpQpTnBSOMqJ/A3SLMIMiV7DulEmXdRHKEGN 6qeg== X-Gm-Message-State: AOAM533S0F743VUk7KqUzmli/u9FknkEEM5yryiFY8YOTMKod37yBj9Q /T2ixMC9JL4DOVnomPPW4znhPiwryYI= X-Google-Smtp-Source: ABdhPJzY/MoXmRiIXQmugAyWuE12cDqrqusJHaP1jV+eA9mYQdrmR6ENF6OuGMkz4Tl5ZR9R2HNHjw== X-Received: by 2002:adf:b318:: with SMTP id j24mr5195331wrd.361.1627042472987; Fri, 23 Jul 2021 05:14:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b12sm33240217wro.1.2021.07.23.05.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 05:14:32 -0700 (PDT) Message-Id: <5d3d95c9cb978ee02d9e39c5eb70b49ecdbd218f.1627042470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Jul 2021 12:14:28 +0000 Subject: [PATCH 2/4] Documentation: define 'MERGE_AUTOSTASH' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Denton Liu , Felipe Contreras , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain The documentation for 'git merge --abort' and 'git merge --quit' both mention the special ref 'MERGE_AUTOSTASH', but this ref is not formally defined anywhere. Mention it in the description of the '--autostash' option for 'git merge'. Signed-off-by: Philippe Blain --- Documentation/merge-options.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index eb0aabd396f..52565014c15 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -154,7 +154,8 @@ endif::git-pull[] --autostash:: --no-autostash:: Automatically create a temporary stash entry before the operation - begins, and apply it after the operation ends. This means + begins, record it in the special ref `MERGE_AUTOSTASH` + and apply it after the operation ends. This means that you can run the operation on a dirty worktree. However, use with care: the final stash application after a successful merge might result in non-trivial conflicts. From patchwork Fri Jul 23 12:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 12396013 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=-12.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 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 3CA00C4338F for ; Fri, 23 Jul 2021 12:14:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20D3360ED4 for ; Fri, 23 Jul 2021 12:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234818AbhGWLeD (ORCPT ); Fri, 23 Jul 2021 07:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234774AbhGWLeB (ORCPT ); Fri, 23 Jul 2021 07:34:01 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4CDCC061757 for ; Fri, 23 Jul 2021 05:14:34 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id z7so2081777wrn.11 for ; Fri, 23 Jul 2021 05:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=nmWVsTNt0irPKVLpD1ZQVBWsgSV971zvgmZmx6gv6Pg=; b=UVvXoLOnQ+4JMcYMjj4YYslD0dbhPUUgDGRD808R7MKjzLZq8y649diD7i7uPjzojx T7xw5z+p1B07zFXWV1JbTlLZAb44t5CsS6EZfZGGIvzsb3PGkLqBmjbzYva4wYp9n2B8 kE69E/dIkIf6TNTlr2vohJHL8hlBlD/ZtG6qVdFTbHVwzfLvBDKxO6N/38/4wqSEXjwT dkKuVgwrP/D9DsRAEfK4qYka6pcb3r2vapFSIGQosEcoLT6KW8QvDip6KfMiHf/6YDc5 uRQ0a2RWJY9FnsmeQln9dML+cocJ7Hqw9rS9w9RftEhAgevZJ0ySVoBC83Xzi5gOqlTx /ytA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=nmWVsTNt0irPKVLpD1ZQVBWsgSV971zvgmZmx6gv6Pg=; b=bOSo3+JL4Xy22h0KmXAJJJnm5Tfv+YKagB7bJPawkonBO+zRr0QH3/44HLFb7cpsD4 4FNGhQtJ0QpjWz5Wolc4qdZvolsZ9egBecCRHZulpHSLFuXZ3/CzRa3QUArF9Q8nfgKw OcEiVKRhWzgkj3ecuatSMU+uTH3RousAUz3Rq0XbCbAZNeJzYwk5BaRtjKto0n+NRFYO 7MuYA68MvC1cQPLpxSfTpPiXqpjFL0tpZsWWdKVc57PtGDeXgiAPCnByK3seymE7OmWM DWMVQlTjP+pIlWe3PRrYnQ+qOFm/jmbGcOFIkUDi+Ntmosu3dQXoNwj/g1kBLvIFpvNk 0+og== X-Gm-Message-State: AOAM530IgttIif6jtc3wr7x88Evdy7IntHVjgYepIR83KuoqWFP4FRRo IhIdnrB9uW3lWFNLjyUPLLTLX1qMv80= X-Google-Smtp-Source: ABdhPJwrU5Nm4HPcdLQY/ipkvobHNFEdXVcWtjmwyz04ctqBwioiP6gHzvpoYq6S7GmRXSNuHiidZg== X-Received: by 2002:a5d:4527:: with SMTP id j7mr5021201wra.137.1627042473616; Fri, 23 Jul 2021 05:14:33 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4sm8851658wmq.7.2021.07.23.05.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 05:14:33 -0700 (PDT) Message-Id: <86becf764243f129c980f073127ec3f08fd4477c.1627042470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Jul 2021 12:14:29 +0000 Subject: [PATCH 3/4] merge: apply autostash if fast-forward fails Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Denton Liu , Felipe Contreras , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Since 'git merge' learned '--autostash' in a03b55530a (merge: teach --autostash option, 2020-04-07), 'cmd_merge', in the fast-forward case, calls 'create_autostash' before calling 'checkout_fast_forward' if '--autostash' is given. However, if 'checkout_fast_forward' fails, the autostash is not applied to the working tree, nor saved in the stash list, since the code simply calls 'goto done'. Be more helpful to the user by applying the autostash in that case. An easy way to test a failing fast-forward is when we are merging a branch that has a tracked file that conflicts with an untracked file in the working tree. Signed-off-by: Philippe Blain --- builtin/merge.c | 1 + t/t7600-merge.sh | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/builtin/merge.c b/builtin/merge.c index 74797b6c7a6..788a6b0cd55 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1560,6 +1560,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) &head_commit->object.oid, &commit->object.oid, overwrite_ignore)) { + apply_autostash(git_path_merge_autostash(the_repository)); ret = 1; goto done; } diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 1cbc9715a81..216113d3537 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -122,6 +122,8 @@ test_expect_success 'setup' ' c0=$(git rev-parse HEAD) && cp file.1 file && git add file && + cp file.1 other && + git add other && test_tick && git commit -m "commit 1" && git tag c1 && @@ -711,6 +713,15 @@ test_expect_success 'fast-forward merge with --autostash' ' test_cmp result.1-5 file ' +test_expect_success 'failed fast-forward merge with --autostash' ' + git reset --hard c0 && + git merge-file file file.orig file.5 && + cp file.5 other && + test_must_fail git merge --autostash c1 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp file.5 file +' + test_expect_success 'octopus merge with --autostash' ' git reset --hard c1 && git merge-file file file.orig file.3 && From patchwork Fri Jul 23 12:14:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 12396017 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=-12.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 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 9F2AAC4320E for ; Fri, 23 Jul 2021 12:14:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BA8260E8B for ; Fri, 23 Jul 2021 12:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234612AbhGWLeF (ORCPT ); Fri, 23 Jul 2021 07:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234814AbhGWLeC (ORCPT ); Fri, 23 Jul 2021 07:34:02 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C949C061757 for ; Fri, 23 Jul 2021 05:14:35 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id b7so2113980wri.8 for ; Fri, 23 Jul 2021 05:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/R+kFhvXXcF2d2eDGqM1uycyvX7ErN+uwWtmnOkcRQE=; b=Yn6NHlGIgezlPw66vTojudmUF66avSEL06NejVZBcH2heRMlcVISIv/oyLMCeZtMAO wSTz0d0x2Gb5XMFHib5r2AVGFtaqogJ7lm4BEdfrxo88E1VI+GwcQcNRG63/g73/r/CD NlSB0LObgg/eAhqBtchj+pR6NVmAFpI01wRSd3qcJggOjncxXgNGBfKExcPjXypmkqxk sfG5YmG+Bv8N527TccpZd5DQUWk07DXWYsCUzOSiL8AxObt6GvNWUlfTjY3zahvjkdRB aTowWiTVcPqFGg5RAyJV1puMyK+DB/pQabRsgnBn9IBc+rz86ojEUH9ADd5EF8rAuUku 5O/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/R+kFhvXXcF2d2eDGqM1uycyvX7ErN+uwWtmnOkcRQE=; b=GF/mmgKC9RSovR+GEIaDEtTxgzyXmnLOwgNPHiIutOt8/mK+mwgsaBfMkUtqM2Kwfu EAAIqZRB5E/T/TtGmrLaqrPux7fgwHakduIzeCYl0hjaIQx4JCx4YdHZ2rKJ85zjTyDH 4bKmNujDXREsjYP0VgL3fdaRWuudnvBODz13EGBbzolRet09olG0ITTWmc1mBRn8/wXP JzhIdF6YkoyoPGk+H3zmNhCBplDjFNQBoDWG7BCFOgObdV8tEsY8ms6oIgVgVC0aUwtA Ec8dVOemrP++ouROKcVFPL+Qu1BaEDke56yO+tj/XneG98kOXJi7hbNXfVp+wHDm99ul KfjQ== X-Gm-Message-State: AOAM531eBwClo7QI6Q2bONBkulKAsX83LMivbOCBrfPcHiQ2EEJyPRRJ i+jbh1Zm4azmNDr6gfIS2GHNJYMyz+M= X-Google-Smtp-Source: ABdhPJw3jqlP14KijSFtXNr5MHfzlYCtCBq90HKvoLcCxpp6+iscAULysfbANRZLHXn6nqxNVP5fsA== X-Received: by 2002:a5d:6b8e:: with SMTP id n14mr4950058wrx.96.1627042474197; Fri, 23 Jul 2021 05:14:34 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p22sm3728165wmq.44.2021.07.23.05.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 05:14:33 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 23 Jul 2021 12:14:30 +0000 Subject: [PATCH 4/4] merge: apply autostash if merge strategy fails Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Denton Liu , Felipe Contreras , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Since 'git merge' learned '--autostash' in a03b55530a (merge: teach --autostash option, 2020-04-07), 'cmd_merge', once it is determined that we have to create a merge commit, calls 'create_autostash' if '--autostash' is given. As explained in a03b55530a, and made more abvious by the tests added in that commit, the autostash is then applied if the merge succeeds, either directly or by committing (after conflict resolution or if '--no-commit' was given), or if the merge is aborted with 'git merge --abort'. In some other cases, like the user calling 'git reset --merge' or 'git merge --quit', the autostash is not applied, but saved in the stash list. However, there exists a scenario that creates an autostash but does not apply nor save it to the stash list: if the chosen merge strategy completely fails to handle the merge, i.e. 'try_merge_strategy' returns 2. Apply the autostash in that case also. An easy way to test that is to try to merge more than two commits but explicitely ask for the 'recursive' merge strategy. Signed-off-by: Philippe Blain --- builtin/merge.c | 1 + t/t7600-merge.sh | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/builtin/merge.c b/builtin/merge.c index 788a6b0cd55..d44c14a21a3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1709,6 +1709,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) else fprintf(stderr, _("Merge with strategy %s failed.\n"), use_strategies[0]->name); + apply_autostash(git_path_merge_autostash(the_repository)); ret = 2; goto done; } else if (best_strategy == wt_strategy) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 216113d3537..2ef39d3088e 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -732,6 +732,14 @@ test_expect_success 'octopus merge with --autostash' ' test_cmp result.1-3-5-9 file ' +test_expect_success 'failed merge (exit 2) with --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.5 && + test_must_fail git merge -s recursive --autostash c2 c3 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp result.1-5 file +' + test_expect_success 'conflicted merge with --autostash, --abort restores stash' ' git reset --hard c3 && cp file.1 file &&