From patchwork Wed Dec 23 04:53:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11987633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02D15C433E6 for ; Wed, 23 Dec 2020 04:54:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC8EC222BB for ; Wed, 23 Dec 2020 04:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726611AbgLWEyo (ORCPT ); Tue, 22 Dec 2020 23:54:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726161AbgLWEyo (ORCPT ); Tue, 22 Dec 2020 23:54:44 -0500 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 006ABC0613D6 for ; Tue, 22 Dec 2020 20:54:03 -0800 (PST) Received: by mail-ot1-x32a.google.com with SMTP id n42so8093028ota.12 for ; Tue, 22 Dec 2020 20:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dyvmaPCxLk5NQVePYe35ajFLiHM1EkOVf4XY4jRtgtA=; b=Nd3GpFXt5PPqI13YFKu+4zEVCYJt4jSXB5N/IYFN+UsnQX8WHkjBbOhbKD3rz/R/3b ecHb5BY0o0qJAHNAQqhimQ6aGnHIHhZ6S5+EQqZDtYPc9RhCfW0ZXETVkjtYJoYPM42t wpHJo7teVyRUQeeWZf+bsQ1DsZLzqg5uqNn+CGwNUOcMKW05tVYy/kihpHTWexP+T0Va zrZvw21rno0wD4rpAFWy7IX1TMProIYTHWoFRjJyElj99qXswIdtgHKN99knwfMlFe7j TeqZ9SpYAGK5QFr0aVqfjUZ2JRV8/dhD5672EfGlqtXQ/U9amgPu5IFkaag7QI0QRj9q 9U4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dyvmaPCxLk5NQVePYe35ajFLiHM1EkOVf4XY4jRtgtA=; b=m+imkwQ9N/DWTGwQKKDhsFGjKClKRibroTsn2JAWCtCiKTIppmBhPD5WXzdJW6DcYI /wI/HZCInr1xEuFGM3wD6PFgjRZLBw7Iikrj065xyKOiqFsJmofO8izQVomgAyMiyzmE FrVAPObiLBXN61qJaolBq1YRqYU/Lm5GrF54EclAD19mXJehAqEkVJU5RJjvs+cfIspE 1fvibp9k0FalbCLNK24QtL2ygQ/Jq1buzs6kl6PAOT7ISPZsU3rT8mYEAhfjbVJHfH/N cL+QKX6ZRQ09F/FSE7PRtwwqHyoOdyCnun9mIjjZuD2NLCJ2AVENlWNRIcdIYu/YDNoF ctVQ== X-Gm-Message-State: AOAM532BcrVfxKfb7v/dZs6SZ23yTCFBD64RIG+m1hqleiwZcovFeKBZ wq/Sf07H180Oj/UrAcJb/yAblSrKLwXMjw== X-Google-Smtp-Source: ABdhPJxtyCCWA5M9aAz2IoGiwQFsjrIF+3vr3IOQUsoWTI+UUvqij5zmFBtma8Fv8HQiG63KwZ2miQ== X-Received: by 2002:a05:6830:916:: with SMTP id v22mr18647055ott.257.1608699242104; Tue, 22 Dec 2020 20:54:02 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id s24sm1505779oij.20.2020.12.22.20.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 20:54:01 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , David Aguilar , Johannes Sixt , Seth House , Felipe Contreras Subject: [PATCH v5 1/1] mergetool: add automerge configuration Date: Tue, 22 Dec 2020 22:53:58 -0600 Message-Id: <20201223045358.100754-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc1 In-Reply-To: <20201223045358.100754-1-felipe.contreras@gmail.com> References: <20201223045358.100754-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The purpose of mergetools is to resolve conflicts when git cannot automatically do so. In order to do that git has added markers in the specific areas that need resolving, which the user must manually fix. The tool is supposed to help with that. However, by passing the original BASE, LOCAL, and REMOTE files, many changes without conflict are presented to the user when in fact nothing needs to be done for those. We can fix that by propagating the final version of the file with the automatic merge to all the panes of the mergetool (BASE, LOCAL, and REMOTE), and only make them differ on the places where there are actual conflicts. As most people will want the new behavior, we enable it by default. Users that do not want the new behavior can set the new configuration mergetool.autoMerge to false. See Seth House's blog post [1] for the idea, and the rationale. [1] https://www.eseth.org/2020/mergetools.html Original-idea-by: Seth House Signed-off-by: Felipe Contreras --- Documentation/config/mergetool.txt | 3 +++ git-mergetool.sh | 17 +++++++++++++++++ t/t7610-mergetool.sh | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt index 16a27443a3..7ce6d0d3ac 100644 --- a/Documentation/config/mergetool.txt +++ b/Documentation/config/mergetool.txt @@ -61,3 +61,6 @@ mergetool.writeToTemp:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. + +mergetool.autoMerge:: + Remove lines without conflicts from all the files. Defaults to `true`. diff --git a/git-mergetool.sh b/git-mergetool.sh index e3f6d543fb..f4db0cac8d 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -239,6 +239,17 @@ checkout_staged_file () { fi } +auto_merge () { + git merge-file --diff3 --marker-size=7 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3" + if test -s "$DIFF3" + then + sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE" + sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL" + sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE" + fi + rm -- "$DIFF3" +} + merge_file () { MERGED="$1" @@ -274,6 +285,7 @@ merge_file () { BASE=${BASE##*/} fi + DIFF3="$MERGETOOL_TMPDIR/${BASE}_DIFF3_$$$ext" BACKUP="$MERGETOOL_TMPDIR/${BASE}_BACKUP_$$$ext" LOCAL="$MERGETOOL_TMPDIR/${BASE}_LOCAL_$$$ext" REMOTE="$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext" @@ -322,6 +334,11 @@ merge_file () { checkout_staged_file 2 "$MERGED" "$LOCAL" checkout_staged_file 3 "$MERGED" "$REMOTE" + if test "$(git config --bool mergetool.autoMerge)" != "false" + then + auto_merge + fi + if test -z "$local_mode" || test -z "$remote_mode" then echo "Deleted merge conflict for '$MERGED':" diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 70afdd06fa..ccabd04823 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -828,4 +828,22 @@ test_expect_success 'mergetool -Oorder-file is honored' ' test_cmp expect actual ' +test_expect_success 'mergetool automerge' ' + test_config mergetool.automerge true && + test_when_finished "git reset --hard" && + git checkout -b test${test_count}_b master && + test_write_lines >file1 base "" a && + git commit -a -m "base" && + test_write_lines >file1 base "" c && + git commit -a -m "remote update" && + git checkout -b test${test_count}_a HEAD~ && + test_write_lines >file1 local "" b && + git commit -a -m "local update" && + test_must_fail git merge test${test_count}_b && + yes "" | git mergetool file1 && + test_write_lines >expect local "" c && + test_cmp expect file1 && + git commit -m "test resolved with mergetool" +' + test_done From patchwork Sun Dec 27 20:58:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth House X-Patchwork-Id: 11990713 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52C2DC433E6 for ; Sun, 27 Dec 2020 21:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CC9F2255F for ; Sun, 27 Dec 2020 21:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726232AbgL0U70 (ORCPT ); Sun, 27 Dec 2020 15:59:26 -0500 Received: from out03.mta.xmission.com ([166.70.13.233]:46476 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726198AbgL0U7Z (ORCPT ); Sun, 27 Dec 2020 15:59:25 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ktd7k-004xb5-DC for git@vger.kernel.org; Sun, 27 Dec 2020 13:58:44 -0700 Received: from mta5.zcs.xmission.com ([166.70.13.69]) by in02.mta.xmission.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ktd7j-00FgVW-Dv for git@vger.kernel.org; Sun, 27 Dec 2020 13:58:43 -0700 Received: from localhost (localhost [127.0.0.1]) by mta5.zcs.xmission.com (Postfix) with ESMTP id 475F112806B1; Sun, 27 Dec 2020 13:58:43 -0700 (MST) X-Amavis-Modified: Mail body modified (using disclaimer) - mta5.zcs.xmission.com Received: from mta5.zcs.xmission.com ([127.0.0.1]) by localhost (mta5.zcs.xmission.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xIqAkVjApdIa; Sun, 27 Dec 2020 13:58:43 -0700 (MST) Received: from localhost.localdomain (unknown [139.60.10.209]) by mta5.zcs.xmission.com (Postfix) with ESMTPSA id EC35212807DC; Sun, 27 Dec 2020 13:58:42 -0700 (MST) From: Seth House To: git@vger.kernel.org Cc: Seth House Date: Sun, 27 Dec 2020 13:58:35 -0700 Message-Id: <20201227205835.502556-3-seth@eseth.com> X-Mailer: git-send-email 2.30.0.rc0.dirty In-Reply-To: <20201227205835.502556-1-seth@eseth.com> References: <20201223045358.100754-1-felipe.contreras@gmail.com> <20201227205835.502556-1-seth@eseth.com> MIME-Version: 1.0 X-XM-SPF: eid=1ktd7j-00FgVW-Dv;;;mid=<20201227205835.502556-3-seth@eseth.com>;;;hst=in02.mta.xmission.com;;;ip=166.70.13.69;;;frm=seth@eseth.com;;;spf=none X-SA-Exim-Connect-IP: 166.70.13.69 X-SA-Exim-Mail-From: seth@eseth.com Subject: [PATCH v6 2/2] mergetool: Add per-tool support for the autoMerge flag X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Keep the global mergetool flag and add a per-tool override flag so that users may enable the flag for one tool and disable it for another. Signed-off-by: Seth House --- Documentation/config/mergetool.txt | 3 +++ git-mergetool.sh | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt index 43af7a96f9..7f32281a61 100644 --- a/Documentation/config/mergetool.txt +++ b/Documentation/config/mergetool.txt @@ -21,6 +21,9 @@ mergetool..trustExitCode:: if the file has been updated, otherwise the user is prompted to indicate the success of the merge. +mergetool..autoMerge:: + Automatically resolve conflicts that don't require user intervention. + mergetool.meld.hasOutput:: Older versions of `meld` do not support the `--output` option. Git will attempt to detect whether `meld` supports `--output` diff --git a/git-mergetool.sh b/git-mergetool.sh index 6e86d3b492..81df301734 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -323,7 +323,10 @@ merge_file () { checkout_staged_file 2 "$MERGED" "$LOCAL" checkout_staged_file 3 "$MERGED" "$REMOTE" - if test "$(git config --bool mergetool.autoMerge)" = "true" + if test "$( + git config --get --bool "mergetool.$merge_tool.automerge" || + git config --get --bool "mergetool.automerge" || + echo true)" = true then git merge-file --diff3 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3" sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"