From patchwork Thu Mar 14 11:25:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 10852633 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 AA5E617E6 for ; Thu, 14 Mar 2019 11:25:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9284628B0F for ; Thu, 14 Mar 2019 11:25:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 868A02A23A; Thu, 14 Mar 2019 11:25:07 +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 2619629AE9 for ; Thu, 14 Mar 2019 11:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727216AbfCNLZG (ORCPT ); Thu, 14 Mar 2019 07:25:06 -0400 Received: from mail-ed1-f50.google.com ([209.85.208.50]:43231 "EHLO mail-ed1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbfCNLZF (ORCPT ); Thu, 14 Mar 2019 07:25:05 -0400 Received: by mail-ed1-f50.google.com with SMTP id m35so4268232ede.10 for ; Thu, 14 Mar 2019 04:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=i+cWzBxcspPIbLQatGZXn0iceHlZ+TVbiKM0EY+YiwU=; b=gwTllcNuRj+/BYLIbt8UQwV2u1Lw8U49iIVQzf6LjRb769+FnLBDoAQE27yKZG6Br5 Okgm+ZfNeNh6yEhPStK5iEhsM4J8no4QTb0yp4oMmFGu+C+NK7gs3f3Bi5ohbw17NkOB vB3SGGpWniCfzcM0J/6hTmOjY8Fq1ESkPKVsVtV9NdMw5yd804IjCvXxmKzhmPCfYhyu FTjN9noGdu0o7Q/LwrSB1NIbPejoNEXj8pLS4MlqQp0QPIdyvXk+8hEEbZfow15TrMHJ QkXFN24mQeiWnzOrr7hIQXJ96zLSsJclSUi/YZwOo2VVH6afgrga2LRZPJCdsgTCUv4C dKJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=i+cWzBxcspPIbLQatGZXn0iceHlZ+TVbiKM0EY+YiwU=; b=k3CbB3Le7cY0SbOf6zYpcUOSj4KaQpcCRY/wtQUoedu402MwWcWlqOCB4S4jDmg+9F HLRm1mVAsZ4VAwTU6oMpUnyQNs7R7Nif5UcHUbWydJOH3gNitgImy/6YKRU8/z3AH2IK t0PTjbQN/WjTNc8Rhm0xVmRZBP37BN8bAllAYewpz4N3GQZDNPLU3psMa0X5cwAEt3u3 LOyH5+AGNrC8WNcuomEeX859TeZvqqbeOivWippsDe7DyCBdt3zhRjwISgSnH+UCG6Pm IQQCe4sgqE/5e/d4RzRc5bVI/a4VmnmzByTZhel/oWMDjAdVCcwm0BhyP8Oor1/kZGnA nQIg== X-Gm-Message-State: APjAAAUZinpmekvZweJmh3EXNDai9FUM1+J44R2XlSdRrBT3+G+l7QsR p4exN/w397ojlfwlGozwV/+41Gec X-Google-Smtp-Source: APXvYqy40jAm/TzHurXi1lXKuLatMNggICKWEbHN0u7JpxGRGtZjHyiHFT2yvI5mkTIe5ejW/M2FlQ== X-Received: by 2002:aa7:db14:: with SMTP id t20mr11037683eds.231.1552562703865; Thu, 14 Mar 2019 04:25:03 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g3sm1380266edh.83.2019.03.14.04.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 04:25:03 -0700 (PDT) Date: Thu, 14 Mar 2019 04:25:03 -0700 (PDT) X-Google-Original-Date: Thu, 14 Mar 2019 11:24:59 GMT Message-Id: <2ad91f19c5b8c7e043e5944a1c075ad23612b59d.1552562701.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 1/3] difftool: remove obsolete (and misleading) comment Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin We will always spawn something from `git difftool`, so we will always have to set `GIT_DIR` and `GIT_WORK_TREE`. Signed-off-by: Johannes Schindelin --- builtin/difftool.c | 1 - 1 file changed, 1 deletion(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index a3ea60ea71..31eece0c8d 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -727,7 +727,6 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (tool_help) return print_tool_help(); - /* NEEDSWORK: once we no longer spawn anything, remove this */ setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1); setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1); From patchwork Thu Mar 14 11:25:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 10852637 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 3B8296C2 for ; Thu, 14 Mar 2019 11:25:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25C4228B0F for ; Thu, 14 Mar 2019 11:25:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19BFE29C7A; Thu, 14 Mar 2019 11:25:10 +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 9FDC828B0F for ; Thu, 14 Mar 2019 11:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727323AbfCNLZI (ORCPT ); Thu, 14 Mar 2019 07:25:08 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:37474 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbfCNLZH (ORCPT ); Thu, 14 Mar 2019 07:25:07 -0400 Received: by mail-ed1-f66.google.com with SMTP id m12so4286146edv.4 for ; Thu, 14 Mar 2019 04:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=keEllI8Z+5TnkM5sMC9FDHveweVpHAtNpyF3b/Fi6VI=; b=MPZyR70jWJKa8n9TJp/27RZ/i6e9qIKxduA+hd9IGoerB/Fwpa3SeqRm1ENmWahQOC 0gNwckXcmsJe8kR0J8kgiQIloRtN54fI/HyXmApFXjr+VxPkSdvFp2HWDEREXDSt5AM0 k5jFQNrNtnriRVZ+FWk9cZPaCHPvFN/ZNU3IBomWxRUc0D/dyAGGEunR3e1Q6z8AriI7 qGVDCEfagIEUkFUu2Z8Vd7vPwyVim4uUqeA+MOHQZ3pO+2AnJmjDqOZBi1DFy7fTWbjf VzHgXo0TjdHqe41yWgKoZudWVE8VLSCsaXXyhKMYDl2S4Wt2pDdCCcMA5ssdGDivOC7K clvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=keEllI8Z+5TnkM5sMC9FDHveweVpHAtNpyF3b/Fi6VI=; b=tX99KPUjt20RoLZJTVr67+eStHEeO6KLgAmQXzmdRoRK/c1As8cYrhjmU2A1aVVGcg VMyxK6xICui9fpkS7LnKQf1LriBFyYn5UX2PwdVgyn+WtRWV1nEtLFKYTIVuS4cLvafy fhn1pSGxAAWZD0JFCrGGHdk51sdvlaquAdznHnf+l40Wx8eYFwzHaZABpP5O/Eb0UHLg bHSk+WL+aNB/stnCa9JRmJZbfqbQqnckf2+mar7Sj5aaBvcAS7MxLBzrGwfdbv7S5UkE wokD/cjtam14RZw1lWoAJKeQFfh5DIa46y9YNYSD3v3v4Rlbh4XGfa8Yh2xfv00joRBi PqRQ== X-Gm-Message-State: APjAAAV6q2QCCpbWhBJbRkVuqdCx3pLghZQnxPf6iarn0sF6XHRNVFeY F9VpTSn/X2OD3/ZOrz4UYOMtnQMV X-Google-Smtp-Source: APXvYqwQbhdspq5Wf8OizWL4WRVcM+58o4Pwhu4ejvvaxqDfwo4AffTxW7OwHjl3qVu/INi8M63c3g== X-Received: by 2002:a50:9ea8:: with SMTP id a37mr3010015edf.147.1552562704678; Thu, 14 Mar 2019 04:25:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e27sm1390131eda.52.2019.03.14.04.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 04:25:04 -0700 (PDT) Date: Thu, 14 Mar 2019 04:25:04 -0700 (PDT) X-Google-Original-Date: Thu, 14 Mar 2019 11:25:00 GMT Message-Id: <10775638ad8f2ef9b64b8dbaf71b80d8546e81d8.1552562701.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 2/3] parse-options: make OPT_ARGUMENT() more useful Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin `OPT_ARGUMENT()` is intended to keep the specified long option in `argv` and not to do anything else. However, it would make a lot of sense for the caller to know whether this option was seen at all or not. For example, we want to teach `git difftool` to work outside of any Git worktree, but only when `--no-index` was specified. Note: nothing in Git uses OPT_ARGUMENT(). Even worse, looking through the commit history, one can easily see that nothing even ever used it, apart from the regression test. So not only do we make `OPT_ARGUMENT()` more useful, we are also about to introduce its first real user! Signed-off-by: Johannes Schindelin --- Documentation/technical/api-parse-options.txt | 4 +++- parse-options.c | 2 ++ parse-options.h | 4 ++-- t/helper/test-parse-options.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt index 2b036d7838..2e2e7c10c6 100644 --- a/Documentation/technical/api-parse-options.txt +++ b/Documentation/technical/api-parse-options.txt @@ -198,8 +198,10 @@ There are some macros to easily define options: The filename will be prefixed by passing the filename along with the prefix argument of `parse_options()` to `prefix_filename()`. -`OPT_ARGUMENT(long, description)`:: +`OPT_ARGUMENT(long, &int_var, description)`:: Introduce a long-option argument that will be kept in `argv[]`. + If this option was seen, `int_var` will be set to one (except + if a `NULL` pointer was passed). `OPT_NUMBER_CALLBACK(&var, description, func_ptr)`:: Recognize numerical options like -123 and feed the integer as diff --git a/parse-options.c b/parse-options.c index cec74522e5..1d57802da0 100644 --- a/parse-options.c +++ b/parse-options.c @@ -286,6 +286,8 @@ static enum parse_opt_result parse_long_opt( optname(options, flags)); if (*rest) continue; + if (options->value) + *(int *)options->value = options->defval; p->out[p->cpidx++] = arg - 2; return PARSE_OPT_DONE; } diff --git a/parse-options.h b/parse-options.h index 7d83e2971d..c3d45ba1ac 100644 --- a/parse-options.h +++ b/parse-options.h @@ -138,8 +138,8 @@ struct option { { OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) } #define OPT_END() { OPTION_END } -#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \ - (h), PARSE_OPT_NOARG} +#define OPT_ARGUMENT(l, v, h) { OPTION_ARGUMENT, 0, (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, NULL, 1 } #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } #define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0) #define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \ diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index cc88fba057..2232b2f79e 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -132,7 +132,7 @@ int cmd__parse_options(int argc, const char **argv) OPT_NOOP_NOARG(0, "obsolete"), OPT_STRING_LIST(0, "list", &list, "str", "add str to list"), OPT_GROUP("Magic arguments"), - OPT_ARGUMENT("quux", "means --quux"), + OPT_ARGUMENT("quux", NULL, "means --quux"), OPT_NUMBER_CALLBACK(&integer, "set integer to NUM", number_callback), { OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b", From patchwork Thu Mar 14 11:25:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 10852639 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 59BBD6C2 for ; Thu, 14 Mar 2019 11:25:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F06F28B0F for ; Thu, 14 Mar 2019 11:25:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F2D929C7A; Thu, 14 Mar 2019 11:25: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 B54BB28B0F for ; Thu, 14 Mar 2019 11:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727286AbfCNLZI (ORCPT ); Thu, 14 Mar 2019 07:25:08 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40652 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbfCNLZH (ORCPT ); Thu, 14 Mar 2019 07:25:07 -0400 Received: by mail-ed1-f68.google.com with SMTP id r23so4267114edm.7 for ; Thu, 14 Mar 2019 04:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qxBbwpZtFh52JXVvfU/nmTSvIHgnFZm+hFSiGVY2MSs=; b=XJVe+3izz5UV95ezkft0/2qczcfAfeIl/wmtc56tZqBu+81qMEMsxRlNCVLfJRINGh +TasJfr6bdwFqR6u2PXZWbPuHzy04RMY0ohZnbtObKGQ0vyZbuxmgm656a1wCHM9GXq9 sRKXjCiTM8C7aO9nO1sqkKbjYy+0W+UL1A327gGsH05lo3KDLBWkXRomRIIwuz0fVvPV XJYv+U1gW/H/o5M5iFWKOWCN1mi87pKfuXoGGeroGoPSxay2CGdhMWg/Z8tTpLBpBJh7 mWyiwAc1HykCvaQp3Tn5cFAO8b4ilY0OgsCpNbjmCWiQkNyZe2sANUduTWHambgx86dv Vwog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qxBbwpZtFh52JXVvfU/nmTSvIHgnFZm+hFSiGVY2MSs=; b=egnlfVsRZ5BeI3+mUUU6n8sDwLt++iYuRSkGiqUZNN4qAV9l3pRZ6upWC9xkljBJdL bQOh2xb/LfqT4S88A0Tf2D/tDrkwfCGAKI54aNcPQqKUC1yXo8jCQGwXhORKWYzModaE 6lryb5I+uj0DfJR6h/xeBFv1t9tv008NzbeiEu8WGjMAn1Q24RH2da6DP32EjjnYMJqS mE3PQ1NL8X8oOzpLUA1h1CNAyjrIgQvLLT6oOhgzMJQhT4wccfa2nVSQEAN6ZBt2akd+ X73q+fvXvosqxLOZljMgiw2fo5hReoo9DNglBGlEGxxpQHAiqKZqy/7rXx0s5FUg1XNe V26w== X-Gm-Message-State: APjAAAXnQpig7HgIP1fge34mNeKaqKdz7RYNNxWTgVgKZudIV1zObfI2 MfxZUMKM1jVBqtjnQBpSsDxoW9vz X-Google-Smtp-Source: APXvYqzdDJN8Fk6SFZnXX5h5byNHY6ZolCKLHEx2VjCa4uZF5VZ66h3ScuJcVgIPqdNGe8CVT0wTzg== X-Received: by 2002:a17:906:4c82:: with SMTP id q2mr455472eju.215.1552562705643; Thu, 14 Mar 2019 04:25:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d17sm1024672ejm.35.2019.03.14.04.25.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 04:25:04 -0700 (PDT) Date: Thu, 14 Mar 2019 04:25:04 -0700 (PDT) X-Google-Original-Date: Thu, 14 Mar 2019 11:25:01 GMT Message-Id: <8cca9f800c2ce269a2ae644e4c15dc4115d3b0e2.1552562701.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 3/3] difftool: allow running outside Git worktrees with --no-index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin As far as this developer can tell, the conversion from a Perl script to a built-in caused the regression in the difftool that it no longer runs outside of a Git worktree (with `--no-index`, of course). It is a bit embarrassing that it took over two years after retiring the Perl version to discover this regression, but at least we now know, and can do something, about it. This fixes https://github.com/git-for-windows/git/issues/2123 Signed-off-by: Johannes Schindelin --- builtin/difftool.c | 13 ++++++++++--- git.c | 2 +- t/t7800-difftool.sh | 10 ++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index 31eece0c8d..4fff1e83f9 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, no_index = 0; static char *difftool_cmd = NULL, *extcmd = NULL; struct option builtin_difftool_options[] = { OPT_BOOL('g', "gui", &use_gui_tool, @@ -714,6 +714,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) "tool returns a non - zero exit code")), OPT_STRING('x', "extcmd", &extcmd, N_("command"), N_("specify a custom command for viewing diffs")), + OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")), OPT_END() }; @@ -727,8 +728,14 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (tool_help) return print_tool_help(); - setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1); - setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1); + if (!no_index && !startup_info->have_repository) + die(_("difftool requires worktree or --no-index")); + + if (!no_index){ + setup_work_tree(); + 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 && diff_gui_tool && *diff_gui_tool) setenv("GIT_DIFF_TOOL", diff_gui_tool, 1); diff --git a/git.c b/git.c index 2014aab6b8..46365ed86a 100644 --- a/git.c +++ b/git.c @@ -491,7 +491,7 @@ static struct cmd_struct commands[] = { { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, { "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT }, { "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT }, - { "difftool", cmd_difftool, RUN_SETUP | NEED_WORK_TREE }, + { "difftool", cmd_difftool, RUN_SETUP_GENTLY }, { "fast-export", cmd_fast_export, RUN_SETUP }, { "fetch", cmd_fetch, RUN_SETUP }, { "fetch-pack", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT }, diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index bb9a7f4ff9..480dd0633f 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -705,4 +705,14 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' test_cmp expect actual ' +test_expect_success 'outside worktree' ' + echo 1 >1 && + echo 2 >2 && + test_expect_code 1 nongit git \ + -c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \ + difftool --no-prompt --no-index ../1 ../2 >actual && + echo "../1 ../2" >expect && + test_cmp expect actual +' + test_done