From patchwork Mon Apr 22 05:07:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910647 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 24DA1922 for ; Mon, 22 Apr 2019 05:07:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1587A28438 for ; Mon, 22 Apr 2019 05:07:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09B8D2847D; Mon, 22 Apr 2019 05:07:47 +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 A121828438 for ; Mon, 22 Apr 2019 05:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbfDVFHo (ORCPT ); Mon, 22 Apr 2019 01:07:44 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41409 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfDVFHo (ORCPT ); Mon, 22 Apr 2019 01:07:44 -0400 Received: by mail-pl1-f196.google.com with SMTP id d1so5246162plj.8 for ; Sun, 21 Apr 2019 22:07:43 -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=DPh8e7dGVsmC6NsPKDI2JOO/8WnAIRgcpwu2s66DnCI=; b=H+d3CCd0l8sEBEGCEColBpQa3OHDKmb1e7KUshoGM1ntlwdNeer5Ml/ogEFSHNL34j mUSlKDrrHR0OkqVCCKEZv7WePmLcOynl/Wt4wC6ggEfnMk8STtrFBX6C1Izhbgzt2Csc mwYBZkhKVZlN56HoBIhmB1aT4GM+HzQuBWJSPJ/LE0Q3VR3E6Qfm5yQRvhmsV4MiKum2 x0ewVsXz+8rAaNL2HMb/u4yiLkpwSOwKYhpqvSfNgQ0w11zY3VemlGHz9WZq9HPkgLK6 ouF/zRNjqjs0EPd0okLIDOVJfADj51+v9ddpme/MYL42hhCEiLROu4AGg2zSO9s4A9rE jRaQ== 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=DPh8e7dGVsmC6NsPKDI2JOO/8WnAIRgcpwu2s66DnCI=; b=lcTaERMlrhQdDsYLUoT9BRyRCS+H9BUw+QrKPf9KYWHanhD2Tb3yNplMJYsK5CLzEA bmS9Xx/zbu7KtOxjzHEDFhF6bgNbwaMgdRi3pVl87yanlcvBDWnXclvqgnffljDnY4ve 8rEgamb1Re9uEKhDTmD5h+C36ol4F+JrdPanXG5yZb9TYOfWjmgx56DmQv8aHyeIhw00 54U9IBjKva09wOClVVxeeae8MWXu30TRxHGOcuBOHAdDlCzGtF9DX/VFbkPhSkr+e7xI FJifcaiRgV58swieUn8O4QDrFaxYdvQX+5+WLczjQmO9lscfTgtKu7kGiJzfBjRdNCFE gKzw== X-Gm-Message-State: APjAAAXcZ35FnQZa/sJIkfgGvjCtW3qQ++oGzgdP7IHD9M1ymkeMAbQR fvulUCD/4j+RkZMPn9VzrqUKvDPQ X-Google-Smtp-Source: APXvYqxvDzymYj5fkDFzv3J0iL1ElfPAe93/tMCRBHmOH1lVJrcByODvUY2EcO46MOdz+NMGD9VDOw== X-Received: by 2002:a17:902:b481:: with SMTP id y1mr18437365plr.161.1555909663212; Sun, 21 Apr 2019 22:07:43 -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 m8sm20680760pgn.59.2019.04.21.22.07.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 22:07:42 -0700 (PDT) Date: Sun, 21 Apr 2019 22:07:41 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar Subject: [PATCH 1/5] t7610: add mergetool --gui tests Message-ID: <678f9b11fc7df7d3ee2050388574bcaea86af331.1555880168.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 Mon Apr 22 05:07:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910649 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 D564E1575 for ; Mon, 22 Apr 2019 05:07:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6C1B28438 for ; Mon, 22 Apr 2019 05:07:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB1532847D; Mon, 22 Apr 2019 05:07:49 +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 AB25228438 for ; Mon, 22 Apr 2019 05:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726632AbfDVFHr (ORCPT ); Mon, 22 Apr 2019 01:07:47 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45353 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbfDVFHq (ORCPT ); Mon, 22 Apr 2019 01:07:46 -0400 Received: by mail-pg1-f194.google.com with SMTP id y3so5287993pgk.12 for ; Sun, 21 Apr 2019 22:07:46 -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=Ff4P7+zKzV5dG7tIQ7SPdHsi9J/DXd84upfnCcVFo8M=; b=i8iLPy7fvnt9Qzkafo6pDjLybu6A42peHKHLUYtElxVjmf32EY90N5Y8zmHcHRVVG/ 4VZeFeKNBHeQP3JvyB781JmJQAAtpGnBgLDMbR3yTJpn483s5vI5aEPHX/W5Gv83Yf1m t8As2s5ri4wSvtxBSmt0AbzxvD8e8zXYZx/et78+fLnqCuobFrWWLrw/ozkFwAxX7QQg YyNJ5PsbRjtX4VT7vB+0GvjcG3Ddsd3OTaE/bf76/VASHrEKT7zIzurG9bRAk7pCRjXd YVkv4aJ/d3ynFxlo0+kTyoBPS14a0XSjn6pU6aJf6lVXo7ZPIFF1bULt9e95+i4s/Ffv HGUw== 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=Ff4P7+zKzV5dG7tIQ7SPdHsi9J/DXd84upfnCcVFo8M=; b=M7esjVAyvTpWUR9x8ARTtBYWzlYq5nd+7+cGgatYkXlDuazZp/npvurMeCfuNrJ2OF fXRwLPZLki4SeWmc5iz5EPLsWexYpOcFT9bf8Q84KiUpjS/dqcSmvpzYxALwjsqwO0Jy 63sdfSp4wdg+wHtMeIeYZt/ccYXgJXHrXzb626zQ0aOC9PYdK1ovtVXc7LxoFQFmkWHL DvFzKmONo7IQchr/plSvdWZf4jXYSDgwX7XtCQwPL4ah+0yPeeHHmT3QgfVjGXrDN/3h HddohOs/obes0LhewIyGNwPBjwEZ/otYDI7jCgG+On0M/nsQGhG5S9DC9SY1qQr3lDYN TU3Q== X-Gm-Message-State: APjAAAU5M+sj4wvkNA3V+eikQyST+3D7MbM0EXmp/vTLQZ/DCSqthMW7 3Si93Fod8yxvO4kp9bWHPOsY08dB X-Google-Smtp-Source: APXvYqydIxY3hM2bRboVMwQcPJybf8FOL2iyY17yytLQ21D3euSlfX9bdbXVEpRbdKU1gE6gsmoARA== X-Received: by 2002:a63:2943:: with SMTP id p64mr14264232pgp.151.1555909665652; Sun, 21 Apr 2019 22:07:45 -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 v19sm22362032pfa.138.2019.04.21.22.07.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 22:07:45 -0700 (PDT) Date: Sun, 21 Apr 2019 22:07:43 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar Subject: [PATCH 2/5] mergetool: use get_merge_tool function Message-ID: <692875cf4baaeee8b47fd7e95d0b787d1a08f64e.1555880168.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-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. Rewrite `get_merge_tool` to return whether or not the tool was guessed 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. Signed-off-by: Denton Liu --- Documentation/git-mergetool--lib.txt | 5 ++++- git-difftool--helper.sh | 2 +- git-mergetool--lib.sh | 6 ++++-- git-mergetool.sh | 11 +++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Documentation/git-mergetool--lib.txt b/Documentation/git-mergetool--lib.txt index 055550b2bc..c4f10209e0 100644 --- a/Documentation/git-mergetool--lib.txt +++ b/Documentation/git-mergetool--lib.txt @@ -28,7 +28,10 @@ to define the operation mode for the functions listed below. FUNCTIONS --------- get_merge_tool:: - returns a merge tool. + 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_cmd:: returns the custom command for a merge tool. diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 7bfb6737df..78a0446668 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -71,7 +71,7 @@ then then merge_tool="$GIT_DIFF_TOOL" else - merge_tool="$(get_merge_tool)" || exit + merge_tool="$(get_merge_tool | sed -e 's/^[a-z]*://')" || exit fi fi diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 83bf52494c..d5e2c6c5c6 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -403,14 +403,16 @@ get_merge_tool_path () { } get_merge_tool () { + 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" } mergetool_find_win32_cmd () { diff --git a/git-mergetool.sh b/git-mergetool.sh index 01b9ad59b2..6ad8024e46 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) + EOF fi merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)" merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)" From patchwork Mon Apr 22 05:07:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910651 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 520D31575 for ; Mon, 22 Apr 2019 05:07:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F80E28438 for ; Mon, 22 Apr 2019 05:07:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D192847D; Mon, 22 Apr 2019 05:07:52 +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 AFFEB28438 for ; Mon, 22 Apr 2019 05:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbfDVFHu (ORCPT ); Mon, 22 Apr 2019 01:07:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46386 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbfDVFHt (ORCPT ); Mon, 22 Apr 2019 01:07:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id 9so5127774pfj.13 for ; Sun, 21 Apr 2019 22:07:48 -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=iZNon4pwWMrbAHZdXAojQPwvxuBx2rScAuj7av8F4GI=; b=f0OW/+YeMUyPnMHIES1+QUB0E5q/nFvJEnxGoSjKMUgVfelSa1Ahyk5tSxe9rop89A sp/qPuYSGglbJeYKU2P/eFRo1V0Wd3fFee/mDSDskXafJr2eInhc7ed/RbcIEZv/Vr7W Flpny7x3n1zmulpB3TqSxv1nZScdFalmSlau0AIKadF4cFefaz1GWXBSg9eC/Yn6NIUK raM/ShsorGaEee9Vs3z/dz4CWcGRd4hfml6I6o8Sev8b6pywD3D0wRbRqNXIWBKFdrv3 0ARmXwEtFkpidKC1wbsNEcCgC/mUHFCbAh6ZYADC8vNgiEmlS/0pefHVyyK57NtDPfWn cZTQ== 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=iZNon4pwWMrbAHZdXAojQPwvxuBx2rScAuj7av8F4GI=; b=XMBFJZBKPE3bLwx2yIPYC8mUmnMiZhVUycg22pdsiSrHTG8cga4/sFZ7LjImS/YvSW YnPGXBht2QbA8ZtIfOJEKoqVapWECh7SNnCutokV9+J0TJSCiV9v/muL0NooodeSJXUU fd+waIo4ZFY6szWwmr4jek65pHL5jJdr1F19KCD6TsHB/27hs1tdMuQXvvVIlb1J2iCd 9wbDIU3JNBPpawyubsNdH20x5s0gp/X0IrGYDtBmJHPFm2o/BuV7za1O6WrvWWzkC40O ZXELR6RnrhzREcy86coO+fql/1UGRhGIkUy7Mqv+xeKx3YOGFb8k+e4UDuBptOYNB1fp TRgA== X-Gm-Message-State: APjAAAULFFKLTAKDTbXCTSRlL33iFKgZsndo3+Qwx1KT7OgGt2pEebbn WRwR8i4/P0ZO0dcR9VYk62Fo8Dvu X-Google-Smtp-Source: APXvYqzAJUOBs+T4aAt5yYg6r+eH0Yvbt+UzSTq3VSrBWFBlh7NAgm0narCCx763XOoLT3sooG1bvw== X-Received: by 2002:a65:4802:: with SMTP id h2mr15919618pgs.98.1555909668112; Sun, 21 Apr 2019 22:07:48 -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 i68sm17985230pfj.96.2019.04.21.22.07.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 22:07:47 -0700 (PDT) Date: Sun, 21 Apr 2019 22:07:45 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar Subject: [PATCH 3/5] mergetool: fallback to tool when guitool unavailable 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-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 d5e2c6c5c6..68a85f4a7b 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 Mon Apr 22 05:07:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910653 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 BE7EF922 for ; Mon, 22 Apr 2019 05:07:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF4F128438 for ; Mon, 22 Apr 2019 05:07:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A32062847D; Mon, 22 Apr 2019 05:07:54 +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 4827C28438 for ; Mon, 22 Apr 2019 05:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbfDVFHw (ORCPT ); Mon, 22 Apr 2019 01:07:52 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:44152 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbfDVFHv (ORCPT ); Mon, 22 Apr 2019 01:07:51 -0400 Received: by mail-pf1-f196.google.com with SMTP id y13so5134745pfm.11 for ; Sun, 21 Apr 2019 22:07:51 -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=41QDcfV9AIzS7+Sm1DXrVVTEzboK2sceEoUxTAMYkRs=; b=ci0JH7M4bWScJQE2oqOfc3ijOSTWIg+JzSl1niLuj7fbFp9CJcPU2c4Yh1DB6juNWI J7m6uJPTCB9/C4kcn5zD3KLL1erRYipkMmfGCCwwhXEWt1U7JVk7e6KwRga8nzkkhurR CYyDPBINud086gZJkl+OJTSep6jkHvz/lP4qTMoeBDo3ghHedbBymWSAZaMwXy5rs2nk jMZZjdWDxLFH7g5yPScla14G5B+uHSJ9An/Og2H0hMUWllTV/+tmFjPjsyN6SjkeQAFL C4D7m7t5G59SOnYItVMZSmR7K/UViNBwjSsoyY1tt3+xa8gHBTcVylAW6fo9wGu8vk0k 77zA== 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=41QDcfV9AIzS7+Sm1DXrVVTEzboK2sceEoUxTAMYkRs=; b=lN0bMlGB4RNDJcGGF/EF4nuwpqeFBFNJsK8s7SF54mTecBWZjj0Spoec/wHy36JCf3 +xkS0mjCw+R/0lWTc3pepLFNtW3fdYY4LRCK7xBaEzF8My7EUhdy0Vej012X/pFqHZSh l6i3sC7o2dfldxzVfGQkC8cDzUgxAS5A3jQP28TtN0WS3dikKuyx/z/mqb+eoBrZAcUW aarLD9LLy1igECl2ngOaB/LHRxswQijsjHkjiTqY2O8e31euWly6XAQv0rHW0P/K96us fxl3eJ3CHmFjE9kaP5m/ljcVMn827G2EExKWuTkhR8jtJRaIuQ7HJf77opP6likO5Sd6 JF4w== X-Gm-Message-State: APjAAAVC/vdrNEcfM/ip/2z5CAOD/YX3SwCNN95W7MGHhG6070+ByY4k cKNqaeBUy0MYAeSHEbgmzH4ms7T0 X-Google-Smtp-Source: APXvYqz+rpUw5Sw92kEee1GS0CmhETAQnLBjtSmE7fUNyvVTlgT+nJDNX5e3Ab5nep5/SxZIY9i2vQ== X-Received: by 2002:a62:6985:: with SMTP id e127mr18239166pfc.188.1555909670550; Sun, 21 Apr 2019 22:07:50 -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 p128sm21728216pfp.30.2019.04.21.22.07.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 22:07:50 -0700 (PDT) Date: Sun, 21 Apr 2019 22:07:48 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar Subject: [PATCH 4/5] difftool: make --gui, --tool and --extcmd exclusive 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-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 | 11 ++++++++++- t/t7800-difftool.sh | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index a3ea60ea71..5ad39c9172 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -690,7 +690,7 @@ static int run_file_diff(int prompt, const char *prefix, int cmd_difftool(int argc, const char **argv, const char *prefix) { int use_gui_tool = 0, dir_diff = 0, prompt = -1, symlinks = 0, - tool_help = 0; + tool_help = 0, count = 0; static char *difftool_cmd = NULL, *extcmd = NULL; struct option builtin_difftool_options[] = { OPT_BOOL('g', "gui", &use_gui_tool, @@ -731,6 +731,15 @@ 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) + count++; + if (difftool_cmd) + count++; + if (extcmd) + count++; + if (count > 1) + die(_("--gui, --tool and --extcmd are 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 Mon Apr 22 05:07:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910655 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 C8A171575 for ; Mon, 22 Apr 2019 05:07:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B951F28471 for ; Mon, 22 Apr 2019 05:07:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB57428438; Mon, 22 Apr 2019 05:07:58 +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 31ED528438 for ; Mon, 22 Apr 2019 05:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbfDVFH5 (ORCPT ); Mon, 22 Apr 2019 01:07:57 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34346 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbfDVFHy (ORCPT ); Mon, 22 Apr 2019 01:07:54 -0400 Received: by mail-pl1-f195.google.com with SMTP id y6so5271421plt.1 for ; Sun, 21 Apr 2019 22:07:53 -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=0KTpRHTjr7oYFFL0SWVcKqRFgrLeuwKMknb41hpuZqQ=; b=PM5KUcIqWShRc9lvmd4BPfP7iBHHUB2VIMnx2XjswuazVWqHfkhDEqt2hrkz00Ym0g QQl9GT1j0ikFWghuhaM4ny/L5rKxEjwl2KF0Hxk4SVqCAKNE0ARUPPwgOgIZYCQjRBxi 5e3e3IW2j5UGZd46PF4Y+0BMRtaGSpSZQpoLGsT2P/YiGM8jmciuPYjvWpSCRbqebzX0 4+9VIQAK4cqKKkqSuhnht8bxbOUDriDCCAnXkZLTDp5LH98btcefwl33O5h5ZLNQ+vS/ Mpuha2iT/A8CWDuLn0lHO/C4StxCmC7nZhWuHo2prAoyF9ozPzY/slBM2zoYEuj+Ppbo /yzg== 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=0KTpRHTjr7oYFFL0SWVcKqRFgrLeuwKMknb41hpuZqQ=; b=Jgtfc3kmJs5r0I86JbS/Nea7Fe6Spx+4hySHqpl1BnrVBOPDlPgZSyZ53Bj836uVxZ r4VWJ/2DvrczMDTHQ5GMG3z4m+9gfNSC4G+sMa+UGEZNT2zkOgjOqCoL7Fhjm1/oZO5K ta7/ZmFVGWPZgCDJy1GGZ9lZa8RB7ISRncLOgAXz86UT7JlqHTemMXtrVCQBGKAbEJdV iouiFHfwyiittV8UTKvSxl5ebs2TqXsZPzHYaZxFJLvEWeLyiei5l2xRh2mLhoSqw8J1 VXuyvlprpenZUmuTEdKyFY6HqXWiu4jLocTr9H/Fy03npDm30TEzr5jZWKtRUOpF3cBn gCag== X-Gm-Message-State: APjAAAVTs8OtoXYkx5Uhvnn4j7f6wbRtIcSouvzAEkjdAHoz11Vx+CFr SA8QeVkGY1ocTVRV4PTw5V1Hwv75 X-Google-Smtp-Source: APXvYqwUKy5G4UDABtg0UeDLI0JWAhsBGUuN6xLMlcW7Vin2oMkWuEg2cEqiwZDwslZq+4y/42iW2w== X-Received: by 2002:a17:902:6bc2:: with SMTP id m2mr18236825plt.194.1555909673032; Sun, 21 Apr 2019 22:07:53 -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 b16sm16013449pfo.168.2019.04.21.22.07.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 22:07:52 -0700 (PDT) Date: Sun, 21 Apr 2019 22:07:50 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar Subject: [PATCH 5/5] difftool: fallback on merge.guitool 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-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 5ad39c9172..67f26502c5 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; @@ -740,8 +734,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (count > 1) die(_("--gui, --tool and --extcmd are 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 '