From patchwork Tue Apr 23 08:53:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10912345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A0911708 for ; Tue, 23 Apr 2019 08:54:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A7921FFEB for ; Tue, 23 Apr 2019 08:54:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E9C5286F2; Tue, 23 Apr 2019 08:54:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07F4E1FFEB for ; Tue, 23 Apr 2019 08:54:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726586AbfDWIyC (ORCPT ); Tue, 23 Apr 2019 04:54:02 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38634 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbfDWIyC (ORCPT ); Tue, 23 Apr 2019 04:54:02 -0400 Received: by mail-pg1-f196.google.com with SMTP id j26so7262532pgl.5 for ; Tue, 23 Apr 2019 01:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=edS0/w9kqCKhoefxLNmTwht+sSOhW/i7QMD6DcixPO0=; b=qIjT5m1csQ2n1mvTnYbs5zHMlmiDnwKq8ydM5rVA5LkLn79higGcLbPhmQ173NGhkI hLUSxJGXxEzbLZTjrWiRXUqfSbwSryQHI2VXVBQReANmm6zPhgKjpTDTP2SkIE4sF1YV /quwGMtppemWcWMbUkLfCa+pk0MRZLxrZOrixJvdvTInTYm8zwtfsIewco4q+sUPEwKr y2cA2PKfElV38QOHLG4LmJU0PgNT/NHDZGk4Ro0ytg0+ticEn29SHEiiaESOXZBAa2xY cwzSDveZm0R4mLyuDm91VxtJRnM2FYeh8LY+bISYYDYNWTO5Cdyy11n7YDi8UROzJMIJ NEEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=edS0/w9kqCKhoefxLNmTwht+sSOhW/i7QMD6DcixPO0=; b=bOb4wwkPiLYOxWxF8d3MTavRBiLPOVkNIA36+/Ub+rxcZ5bNWyTDOGc43yxCHNUlLL D+Xr047N5aH9oQ3sUG2OcJdrNC8E3Jq1eouu3i/suYbkIlFAn46u0DFw+yY5xyJqvkpw nvprhe3irbTSJKG+hTS6EMr/I5cNUd1QI4QU9bPRwkG4VY9xdLHvPGkUnlcwoZ3c+2Bh 1Jt19QS9hbsm3redwak9ujpi+bXyV9GkuS+QSjk/1CuUiEcsdO3n9fJT/SYLNjy0IST2 n5JJkqW5zI/m6x/I9njnUe53wS6ewSIb9eGEy1hgKEd6usMMMgQh+zmSNfPd98UCtsWU YmcQ== X-Gm-Message-State: APjAAAUTDlDfISzYlGcV7+WRf5kT5bmS317FwG+wzo05BbGrsOQf2wKs 08ZY7mZoS0ElKKlKAlau4R6vIJXm X-Google-Smtp-Source: APXvYqwXYCTDXsRJPF0j7ZEQSBL3cMFDKBQq5Tde8jDImyUgsncBqSgNFCvQV9ia8yMG95ZSErv6tA== X-Received: by 2002:a63:82c6:: with SMTP id w189mr3107737pgd.444.1556009641099; Tue, 23 Apr 2019 01:54:01 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id p20sm12803366pgj.86.2019.04.23.01.54.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 01:54:00 -0700 (PDT) Date: Tue, 23 Apr 2019 01:53:58 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar , Jeff Hostetler , Eric Sunshine Subject: [PATCH v2 1/5] t7610: add mergetool --gui tests Message-ID: <678f9b11fc7df7d3ee2050388574bcaea86af331.1556009181.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In 063f2bdbf7 (mergetool: accept -g/--[no-]gui as arguments, 2018-10-24), mergetool was taught the --gui option but no tests were added to ensure that it was working properly. Add a test to ensure that it works. Signed-off-by: Denton Liu --- t/t7610-mergetool.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index a9fb971615..5f37d7a1ff 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -145,6 +145,28 @@ test_expect_success 'custom mergetool' ' git commit -m "branch1 resolved with mergetool" ' +test_expect_success 'gui mergetool' ' + test_config merge.guitool myguitool && + test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" && + test_config mergetool.myguitool.trustExitCode true && + test_when_finished "git reset --hard" && + git checkout -b test$test_count branch1 && + git submodule update -N && + test_must_fail git merge master >/dev/null 2>&1 && + ( yes "" | git mergetool --gui both >/dev/null 2>&1 ) && + ( yes "" | git mergetool -g file1 file1 ) && + ( yes "" | git mergetool --gui file2 "spaced name" >/dev/null 2>&1 ) && + ( yes "" | git mergetool --gui subdir/file3 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool --gui file11 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool --gui file12 >/dev/null 2>&1 ) && + ( yes "l" | git mergetool --gui submod >/dev/null 2>&1 ) && + test "$(cat file1)" = "gui master updated" && + test "$(cat file2)" = "gui master new" && + test "$(cat subdir/file3)" = "gui master new sub" && + test "$(cat submod/bar)" = "branch1 submodule" && + git commit -m "branch1 resolved with mergetool" +' + test_expect_success 'mergetool crlf' ' test_when_finished "git reset --hard" && # This test_config line must go after the above reset line so that From patchwork Tue Apr 23 08:54:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10912349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB5EF112C for ; Tue, 23 Apr 2019 08:54:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA907205C0 for ; Tue, 23 Apr 2019 08:54:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB6122870B; Tue, 23 Apr 2019 08:54:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49CD7205C0 for ; Tue, 23 Apr 2019 08:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbfDWIyF (ORCPT ); Tue, 23 Apr 2019 04:54:05 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39537 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbfDWIyE (ORCPT ); Tue, 23 Apr 2019 04:54:04 -0400 Received: by mail-pg1-f193.google.com with SMTP id l18so7127837pgj.6 for ; Tue, 23 Apr 2019 01:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ePwyvtQ/RMMAbauV9MluWrhq+B6KA/MOgosWmhMQUDI=; b=F1qBCH/5Yr+BCxe/pWzttq6EUc+WmIoxBlWx83ztVsQ8sEqvynSE8vv7L3KNbFasRv dSTKBco1EA49M+5g43/pD/6mYbDi6N3NnsKcqRJRWrnBXWK7MigCIPZ5LeUjpnXKSyc3 c2aT9qOSVkjgw/dqqRXh4vT1L4vP4CfWXcPQnhwk9hvwR8QIY+pTbXEg8XYL/HzA5LSm H7EBxmixvU3C7SrWfCrDZApuCdOOmVQ2QiK3QehSsxrK5AJGSRzPXkUt4xahgbhIqgTR BizDMZ870edrQH4E5sX6alRmcjfY1dr4UXweMpo9vvbNJLPyEcOrdGPXbPR3aX2QShEL BUkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ePwyvtQ/RMMAbauV9MluWrhq+B6KA/MOgosWmhMQUDI=; b=cbD9CgqVU16wwqmtB7kW/aXAJ7Omr7Zem64YZ61zDftuqkr/omwt4/P1eghPknFHbb P/cJDpuwHjqQ6GgZCJckFcH5R7J1A2sTmrmuZbygRYs/WvpD1k4Z4mpDJWtLTe3eykbD QCzjD0/9l7m84JJTUFiv1byuWiNVeo15+i/wkupNFIosx3TwxdDfaezLRbh1yhLhQN7t 6ry2yWU04aFgX6+PCS1I/IhjLETb6t9/uifs6DnA0zFnDL+Wm7lfBQDAy1s4hwwssac6 BO9qy9weH6pzJBb7hDbL6VWjc7k4clZ4J9rj8/HZr6Ha5JY1IT/GlKyFUU9FU6C7wpJm uwaA== X-Gm-Message-State: APjAAAXGO5wJl0sOxPLHn0MEUWF/oJCplRH96b2dCkd7o4k8bAe6Zdi0 iYwW8skRGWZxDNnXUnUH1URQL5O3 X-Google-Smtp-Source: APXvYqwkqMb/x6MYDVCAEOQfhvaYNTuUtRcAngwUKjKT1rw8J/PV1nmW3th7pgvr7nork1T+0bd9WA== X-Received: by 2002:a65:5049:: with SMTP id k9mr22762123pgo.229.1556009643788; Tue, 23 Apr 2019 01:54:03 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id 1sm8305809pgm.10.2019.04.23.01.54.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 01:54:03 -0700 (PDT) Date: Tue, 23 Apr 2019 01:54:01 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar , Jeff Hostetler , Eric Sunshine Subject: [PATCH v2 2/5] mergetool: use get_merge_tool_guessed function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In git-mergetool, the logic for getting which merge tool to use is duplicated in git-mergetool--lib, except for the fact that it needs to know whether the tool was guessed or not. Write `get_merge_tool_guessed` to return whether or not the tool was guessed in addition to the actual tool and make git-mergetool call this function instead of duplicating the logic. Also, let `$GIT_MERGETOOL_GUI` be set to determine whether or not the guitool will be selected. Make `get_merge_tool` use this function internally so that code duplication is reduced. Signed-off-by: Denton Liu --- After thinking about it for a while, I realised that if it was easy to find one (albeit old) public project using our code, there should be many others who we don't know about that will also be using our code. Let's save them the trouble and just introduce a new function instead of changing the behaviour of the old one. --- Documentation/git-mergetool--lib.txt | 9 ++++++++- git-mergetool--lib.sh | 12 +++++++++--- git-mergetool.sh | 11 +++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Documentation/git-mergetool--lib.txt b/Documentation/git-mergetool--lib.txt index 055550b2bc..343268d885 100644 --- a/Documentation/git-mergetool--lib.txt +++ b/Documentation/git-mergetool--lib.txt @@ -27,8 +27,15 @@ to define the operation mode for the functions listed below. FUNCTIONS --------- +get_merge_tool_guessed:: + returns '$is_guessed:$merge_tool'. '$is_guessed' is 'true' if + the tool was guessed, else 'false'. '$merge_tool' is the merge + tool to use. '$GIT_MERGETOOL_GUI' may be set to 'true' to search + for the appropriate guitool. + get_merge_tool:: - returns a merge tool. + returns a merge tool. '$GIT_MERGETOOL_GUI' may be set to 'true' + to search for the appropriate guitool. get_merge_tool_cmd:: returns the custom command for a merge tool. diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 83bf52494c..5eedb1a08a 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -402,15 +402,21 @@ get_merge_tool_path () { echo "$merge_tool_path" } -get_merge_tool () { +get_merge_tool_guessed () { + is_guessed=false # Check if a merge tool has been configured - merge_tool=$(get_configured_merge_tool) + merge_tool=$(get_configured_merge_tool $GIT_MERGETOOL_GUI) # Try to guess an appropriate merge tool if no tool has been set. if test -z "$merge_tool" then merge_tool=$(guess_merge_tool) || exit + is_guessed=true fi - echo "$merge_tool" + echo "$is_guessed:$merge_tool" +} + +get_merge_tool () { + get_merge_tool_guessed | sed -e 's/^[a-z]*://' } mergetool_find_win32_cmd () { diff --git a/git-mergetool.sh b/git-mergetool.sh index 01b9ad59b2..63e4da1b2f 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -449,14 +449,9 @@ main () { if test -z "$merge_tool" then - # Check if a merge tool has been configured - merge_tool=$(get_configured_merge_tool $gui_tool) - # Try to guess an appropriate merge tool if no tool has been set. - if test -z "$merge_tool" - then - merge_tool=$(guess_merge_tool) || exit - guessed_merge_tool=true - fi + IFS=':' read guessed_merge_tool merge_tool <<-EOF + $(GIT_MERGETOOL_GUI=$gui_tool get_merge_tool_guessed) + EOF fi merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)" merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)" From patchwork Tue Apr 23 08:54:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10912351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99525112C for ; Tue, 23 Apr 2019 08:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 893AD286F2 for ; Tue, 23 Apr 2019 08:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D8D52870B; Tue, 23 Apr 2019 08:54:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07B31286F2 for ; Tue, 23 Apr 2019 08:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbfDWIyH (ORCPT ); Tue, 23 Apr 2019 04:54:07 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43659 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbfDWIyH (ORCPT ); Tue, 23 Apr 2019 04:54:07 -0400 Received: by mail-pf1-f196.google.com with SMTP id w26so311290pfj.10 for ; Tue, 23 Apr 2019 01:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jkfqGmJW8BSP1Wx4Koqve/6G35eKRpMydPM9Se/SFrg=; b=MzbpyQ1XrIksoPt54sZZ1PmtBhu447w5NnRfa6TfKg5mTFjK2oCOOZKBen7mVqD45U lrxUBwc+JH4P7EOve0vzmt2goMs5NVmoNunoGCH2LrH3x0t81ROUstz6M5Hv+N9Mm9UO VzQq7qIx8JgySUKiLB8YBgttnQpkhfzvfSlOOzG2fcKbbFgQED2+nToMyF3fMtKmrxSx WS+AvAgS0Zprt450cjoYa5/Z3MRf2+EFbR3NY88Lsya4bL3doZfQzA2Nqv2oZdQJ3KG3 aDIZnCZLlW69zNX2BNCgbP5ZKVPpBYh1VNpZemgxWqPEGe6SLkYJ5GWQPsi0hZo9BvKB h7rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jkfqGmJW8BSP1Wx4Koqve/6G35eKRpMydPM9Se/SFrg=; b=J1tHJmmg8wyH5YDlStujgGxhwp0kNwvWSjXlAKfEvN0yds1Ukgqw7wv6Y0t0u/Z1V0 I8XvBUiDjmFDehi63/Tu3w8zBsYq+7vVJQGBRLY6rOaV/uWUdFMpeCbEBlZl1L2L89qy 2+QRfdWn+TKuVUt47jwtX8Bof+YhNXzTFLNElUwXrjUejoCk46AXRwf37fA2XsMGI1rD uvmWkfyX6FTTiCeLThDp8aF2fFbLBGkykLBNz3v3fh8ck1KU1yeQICvlUZXaBKO5PmwE uDLaRVkc2aX3Ph8VLk9rok3ooZFIL21O+leeOcgAQm7udw2KC7ssu56WbPvOZhmSz8Qv jHLw== X-Gm-Message-State: APjAAAVVIinshqsO5LGzExU/Glbrfhotl/FkPE5gQ5juA04wmdRJqk0J VcUBTZlwPeCGxYbxKsuN8mgevUIQ X-Google-Smtp-Source: APXvYqwOrwTdFOUNT7OjgeUVFQHdtuDVIqMtJuv3xjVQw2sdZm3hfz8e8GYCFG1vwuW5B2nIZVQuaw== X-Received: by 2002:a63:ed10:: with SMTP id d16mr7018365pgi.75.1556009646418; Tue, 23 Apr 2019 01:54:06 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id q24sm21867226pgm.16.2019.04.23.01.54.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 01:54:05 -0700 (PDT) Date: Tue, 23 Apr 2019 01:54:04 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar , Jeff Hostetler , Eric Sunshine Subject: [PATCH v2 3/5] mergetool: fallback to tool when guitool unavailable Message-ID: <24db1afeeee66894172cceaad9ffa170b75c62ff.1556009181.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In git-difftool, if the tool is called with --gui but `diff.guitool` is not set, it falls back to `diff.tool`. Make git-mergetool also fallback from `merge.guitool` to `merge.tool` if the former is undefined. If git-difftool were to use `get_configured_mergetool`, it would also get the fallback behaviour in the following precedence: 1. diff.guitool 2. merge.guitool 3. diff.tool 4. merge.tool Signed-off-by: Denton Liu --- Documentation/git-mergetool.txt | 4 +++- git-mergetool--lib.sh | 27 ++++++++++++++++++--------- t/t7610-mergetool.sh | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt index 0c7975a050..6b14702e78 100644 --- a/Documentation/git-mergetool.txt +++ b/Documentation/git-mergetool.txt @@ -83,7 +83,9 @@ success of the resolution after the custom tool has exited. --gui:: When 'git-mergetool' is invoked with the `-g` or `--gui` option the default merge tool will be read from the configured - `merge.guitool` variable instead of `merge.tool`. + `merge.guitool` variable instead of `merge.tool`. If + `merge.guitool` is not set, we will fallback to the tool + configured under `merge.tool`. --no-gui:: This overrides a previous `-g` or `--gui` setting and reads the diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 5eedb1a08a..6f477ae77d 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -350,20 +350,29 @@ guess_merge_tool () { } get_configured_merge_tool () { - # If first argument is true, find the guitool instead - if test "$1" = true + is_gui="$1" + sections="merge" + keys="tool" + + if diff_mode then - gui_prefix=gui + sections="diff $sections" fi - # Diff mode first tries diff.(gui)tool and falls back to merge.(gui)tool. - # Merge mode only checks merge.(gui)tool - if diff_mode + if "$is_gui" = true then - merge_tool=$(git config diff.${gui_prefix}tool || git config merge.${gui_prefix}tool) - else - merge_tool=$(git config merge.${gui_prefix}tool) + keys="guitool $keys" fi + + IFS=' ' + for key in $keys + do + for section in $sections + do + merge_tool=$(git config $section.$key) && break 2 + done + done + if test -n "$merge_tool" && ! valid_tool "$merge_tool" then echo >&2 "git config option $TOOL_MODE.${gui_prefix}tool set to unknown tool: $merge_tool" diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 5f37d7a1ff..bc2c9eaa30 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -167,6 +167,25 @@ test_expect_success 'gui mergetool' ' git commit -m "branch1 resolved with mergetool" ' +test_expect_success 'gui mergetool without merge.guitool set fallsback to merge.tool' ' + test_when_finished "git reset --hard" && + git checkout -b test$test_count branch1 && + git submodule update -N && + test_must_fail git merge master >/dev/null 2>&1 && + ( yes "" | git mergetool --gui both >/dev/null 2>&1 ) && + ( yes "" | git mergetool -g file1 file1 ) && + ( yes "" | git mergetool --gui file2 "spaced name" >/dev/null 2>&1 ) && + ( yes "" | git mergetool --gui subdir/file3 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool --gui file11 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool --gui file12 >/dev/null 2>&1 ) && + ( yes "l" | git mergetool --gui submod >/dev/null 2>&1 ) && + test "$(cat file1)" = "master updated" && + test "$(cat file2)" = "master new" && + test "$(cat subdir/file3)" = "master new sub" && + test "$(cat submod/bar)" = "branch1 submodule" && + git commit -m "branch1 resolved with mergetool" +' + test_expect_success 'mergetool crlf' ' test_when_finished "git reset --hard" && # This test_config line must go after the above reset line so that From patchwork Tue Apr 23 08:54:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10912353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AA471575 for ; Tue, 23 Apr 2019 08:54:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFCDC1FFEB for ; Tue, 23 Apr 2019 08:54:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E408E28701; Tue, 23 Apr 2019 08:54:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D68C1FFEB for ; Tue, 23 Apr 2019 08:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbfDWIyK (ORCPT ); Tue, 23 Apr 2019 04:54:10 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41017 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbfDWIyJ (ORCPT ); Tue, 23 Apr 2019 04:54:09 -0400 Received: by mail-pf1-f193.google.com with SMTP id 188so7126265pfd.8 for ; Tue, 23 Apr 2019 01:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=n09q9uk++BnQGLaO7ISBMXJQYpqeJfefi3fy5n5GfUI=; b=pjcS+rqPQdBORUYqZy73YiMGscqlYamdNvzVavZ8/oloHXfEoBQPFdpFnrtTbPWU2e fPNHn2zif5RiDUCiobhyDhfywjywFf5ioaW5AQ0avfniq7fC9IyBWy5fkdhyw+SmCXAu yqJmNCgclZfFt9vEWlVGj4uNsOnMGVJTmEVCXycmWZaw9uOiOhZhqKguY2jVNsmHfvex 5ETo+pvq6CywxABPbbOfLbQBdY8lI3uqRYrw/qti76q6z0R8sn2BUVYSwkeHPKnW3lED 21nH/nd8AWXLOT2Tj+7u+dC8kgf2LOV/qU63MktbdkmoqKbfgKu/vWA85MHFqEubkfCy 3TiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=n09q9uk++BnQGLaO7ISBMXJQYpqeJfefi3fy5n5GfUI=; b=dBbfpRQiSMsCniI3JjRwOjRxXFY5Xk+mLyJAO3eh2dG7R/OkCxs7QJfdgBO7ewj7X8 U+pClFYmFuvxgc57VlZQCxFh3Omil6RUHt43unMvI5hx6v28cSsEEiRvgRPdkuScw+ng E8v1jVUklOsfuSI2BHPj5Uk9AIqYt/UiQXiN4tgzvmo0BSiQjN8vVnACpuw4u7gxNvb4 B6aBKOERtZYxCfLZ/s7HD6bIBq8Yi+CK0ndg0qQkb6/+SozlsU0SBq2JydESGxY4Ej4E HBFk7+qZy23Q3H51FPWAa/6aPzO927CnCrgBKtl6XT6jyFaS9jTu0q/TMH/kh1gnvCxS o4Sg== X-Gm-Message-State: APjAAAXi7U9TmRm1Ocpo4Zh+kIaiDi41I5el5xyYRvb32mSYelYbJwtE LRgqPai6kf6tVkLnX/9VGKrFtYFR X-Google-Smtp-Source: APXvYqwwjZ4M2KecKlASXM+QgL5QNaBVn2vOZs/IYaUnTLgQwe6LQd6xnof24QN/LQAPa0X2gzv+bw== X-Received: by 2002:a63:1055:: with SMTP id 21mr4848928pgq.200.1556009649012; Tue, 23 Apr 2019 01:54:09 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id w3sm28344296pfn.179.2019.04.23.01.54.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 01:54:08 -0700 (PDT) Date: Tue, 23 Apr 2019 01:54:06 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar , Jeff Hostetler , Eric Sunshine Subject: [PATCH v2 4/5] difftool: make --gui, --tool and --extcmd mutually exclusive Message-ID: <6f65b5c9134639eabd1abaf32af95c228a58e465.1556009181.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In git-difftool, these options specify which tool to ultimately run. As a result, they are logically conflicting. Explicitly disallow these options from being used together. Signed-off-by: Denton Liu --- builtin/difftool.c | 3 +++ t/t7800-difftool.sh | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/builtin/difftool.c b/builtin/difftool.c index a3ea60ea71..65bba90338 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -731,6 +731,9 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1); setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1); + if (use_gui_tool + !!difftool_cmd + !!extcmd > 1) + die(_("--gui, --tool and --extcmd are mutually exclusive")); + if (use_gui_tool && diff_gui_tool && *diff_gui_tool) setenv("GIT_DIFF_TOOL", diff_gui_tool, 1); else if (difftool_cmd) { diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index bb9a7f4ff9..107f31213d 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -705,4 +705,12 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' test_cmp expect actual ' +test_expect_success 'difftool --gui, --tool and --extcmd are exclusive' ' + difftool_test_setup && + test_must_fail git difftool --gui --tool=test-tool && + test_must_fail git difftool --gui --extcmd=cat && + test_must_fail git difftool --tool=test-tool --extcmd=cat && + test_must_fail git difftool --gui --tool=test-tool --extcmd=cat +' + test_done From patchwork Tue Apr 23 08:54:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10912355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88F131575 for ; Tue, 23 Apr 2019 08:54:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79DE91FFEB for ; Tue, 23 Apr 2019 08:54:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DF09286F2; Tue, 23 Apr 2019 08:54:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F38F71FFEB for ; Tue, 23 Apr 2019 08:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbfDWIyM (ORCPT ); Tue, 23 Apr 2019 04:54:12 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36952 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbfDWIyM (ORCPT ); Tue, 23 Apr 2019 04:54:12 -0400 Received: by mail-pg1-f193.google.com with SMTP id e6so7265264pgc.4 for ; Tue, 23 Apr 2019 01:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YZgysgXEhpqkUO8cf301jh4x0JoX/GnOM6QKUIXwyDo=; b=gKPWbbmVLRyeK8FnH45uH8qxJORMZ1GKMaqViuDgOsEvaE2AUzrtqW8XYEFPey35nB y1WveefYh5yd0Q1H41m0UEzEjwngDUDEZZl/p5NYT48+BoiqO7WDRMwG0Dwg2LpKhADN fgkudxQ3qOUNwDZLsLQRDztq9c7X93VfBn9QnvpVf/7Zo/V2WDEXUksxLFFtGsfUUCvD +xknqhFWmBOLw3zL4P8m9vIZ4CE4fDgC3K3IOXxw4K5ifPTRMCG9Q5jBzelbS8r7yAtV nKbDDBLWfPs907PypG8eInijKf5PYmN5IaETcjz/MrBNLyYf4ry/QtjBHZUgkUVTG+Z7 AkPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YZgysgXEhpqkUO8cf301jh4x0JoX/GnOM6QKUIXwyDo=; b=pzjO8snqGEFMLZcPLLsDVrTe6Y8OKsW6XJBQ0iSpxybPLbazBkHhtWInE/tjWzRoKP IArpnDVJIReaA2drFNF0BdzTRSqUVCq9zAD4CpJ4k4ykL9oTrsJ+IMoQw+bUA8UzrJzo mkYlBs7Y2zG7s1a6V0GuE0Kd7f3t3OyQR8ZjdqLB7GkkybSe3Y+i2DTKMw/C/OZjUEgV Ci4ivENfh2/wc+lf+5xJMdX1mwbsV5F0MjKA4O2LPnUul2AxmMucYFgWiqwdZuwM9MCH oTwsm/fRpIh6pnY1VOqRG3UXNPt6puQ4DTH/dp4/N0dZzoRj4CgBIxnEfNBIzLmst+Mn 7ZYQ== X-Gm-Message-State: APjAAAWiJNIEXVGsMLqbBm8N0Zq28dtgdwQQuEwnLd6V1lq7qoqwIvFI EyTzLyvbsyxuy2M2gQftHajIj1tM X-Google-Smtp-Source: APXvYqxXUS6fPDik2jbdXsJYR84QuELj41eOn/tFWFORVV8VCdgx6eACJ8ymEeRE/xoWYdMqbTE/RA== X-Received: by 2002:a63:f115:: with SMTP id f21mr23313807pgi.65.1556009651669; Tue, 23 Apr 2019 01:54:11 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id s79sm27477370pfa.31.2019.04.23.01.54.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 01:54:10 -0700 (PDT) Date: Tue, 23 Apr 2019 01:54:09 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar , Jeff Hostetler , Eric Sunshine Subject: [PATCH v2 5/5] difftool: fallback on merge.guitool Message-ID: <5a24772219f405c93a54310d3e81a7c0e71c350e.1556009181.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In git-difftool.txt, it says 'git difftool' falls back to 'git mergetool' config variables when the difftool equivalents have not been defined. However, when `diff.guitool` is missing, it doesn't fallback to anything. Make git-difftool fallback to `merge.guitool` when `diff.guitool` is missing. Signed-off-by: Denton Liu --- Documentation/git-difftool.txt | 4 +++- builtin/difftool.c | 10 ++-------- t/t7800-difftool.sh | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index 96c26e6aa8..484c485fd0 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -90,7 +90,9 @@ instead. `--no-symlinks` is the default on Windows. When 'git-difftool' is invoked with the `-g` or `--gui` option the default diff tool will be read from the configured `diff.guitool` variable instead of `diff.tool`. The `--no-gui` - option can be used to override this setting. + option can be used to override this setting. If `diff.guitool` + is not set, we will fallback in the order of `merge.guitool`, + `diff.tool`, `merge.tool` until a tool is found. --[no-]trust-exit-code:: 'git-difftool' invokes a diff tool individually on each file. diff --git a/builtin/difftool.c b/builtin/difftool.c index 65bba90338..10660639c0 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -24,7 +24,6 @@ #include "object-store.h" #include "dir.h" -static char *diff_gui_tool; static int trust_exit_code; static const char *const builtin_difftool_usage[] = { @@ -34,11 +33,6 @@ static const char *const builtin_difftool_usage[] = { static int difftool_config(const char *var, const char *value, void *cb) { - if (!strcmp(var, "diff.guitool")) { - diff_gui_tool = xstrdup(value); - return 0; - } - if (!strcmp(var, "difftool.trustexitcode")) { trust_exit_code = git_config_bool(var, value); return 0; @@ -734,8 +728,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (use_gui_tool + !!difftool_cmd + !!extcmd > 1) die(_("--gui, --tool and --extcmd are mutually exclusive")); - if (use_gui_tool && diff_gui_tool && *diff_gui_tool) - setenv("GIT_DIFF_TOOL", diff_gui_tool, 1); + if (use_gui_tool) + setenv("GIT_MERGETOOL_GUI", "true", 1); else if (difftool_cmd) { if (*difftool_cmd) setenv("GIT_DIFF_TOOL", difftool_cmd, 1); diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 107f31213d..ae90701a12 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -279,11 +279,27 @@ test_expect_success 'difftool + mergetool config variables' ' echo branch >expect && git difftool --no-prompt branch >actual && test_cmp expect actual && + git difftool --gui --no-prompt branch >actual && + test_cmp expect actual && # set merge.tool to something bogus, diff.tool to test-tool test_config merge.tool bogus-tool && test_config diff.tool test-tool && git difftool --no-prompt branch >actual && + test_cmp expect actual && + git difftool --gui --no-prompt branch >actual && + test_cmp expect actual && + + # set merge.tool, diff.tool to something bogus, merge.guitool to test-tool + test_config diff.tool bogus-tool && + test_config merge.guitool test-tool && + git difftool --gui --no-prompt branch >actual && + test_cmp expect actual && + + # set merge.tool, diff.tool, merge.guitool to something bogus, diff.guitool to test-tool + test_config merge.guitool bogus-tool && + test_config diff.guitool test-tool && + git difftool --gui --no-prompt branch >actual && test_cmp expect actual '