From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 0/3] Allow difftool to be run outside of Git worktrees
Date: Thu, 14 Mar 2019 04:25:02 -0700 (PDT) [thread overview]
Message-ID: <pull.163.v2.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.163.git.gitgitgadget@gmail.com>
It was reported in https://github.com/git-for-windows/git/issues/2123 that
git difftool --no-index fails to work outside worktrees, even if it should
work.
I fear this is a regression I introduced over two years ago (!) when I
converted the Perl script to C.
At least now that I know about the bug, I can fix it.
Changes since v1:
* Instead of ad-hoc parsing to look for --no-index, the OPT_ARGUMENT() was
enhanced and not has its first real user! After all those lonely, long
years (11 years, 1 month and 11 days), what a wonderful thing to
celebrate on π day.
* The test now uses the nongit helper.
* The test uses test_cmp to make diagnosing regressions easier.
Johannes Schindelin (3):
difftool: remove obsolete (and misleading) comment
parse-options: make OPT_ARGUMENT() more useful
difftool: allow running outside Git worktrees with --no-index
Documentation/technical/api-parse-options.txt | 4 +++-
builtin/difftool.c | 14 ++++++++++----
git.c | 2 +-
parse-options.c | 2 ++
parse-options.h | 4 ++--
t/helper/test-parse-options.c | 2 +-
t/t7800-difftool.sh | 10 ++++++++++
7 files changed, 29 insertions(+), 9 deletions(-)
base-commit: e902e9bcae2010bc42648c80ab6adc6c5a16a4a5
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-163%2Fdscho%2Fdifftool-no-index-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-163/dscho/difftool-no-index-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/163
Range-diff vs v1:
1: 2ad91f19c5 = 1: 2ad91f19c5 difftool: remove obsolete (and misleading) comment
-: ---------- > 2: 10775638ad parse-options: make OPT_ARGUMENT() more useful
2: 9f6eb60eee ! 3: 8cca9f800c difftool: allow running outside Git worktrees with --no-index
@@ -22,24 +22,24 @@
{
int use_gui_tool = 0, dir_diff = 0, prompt = -1, symlinks = 0,
- tool_help = 0;
-+ tool_help = 0, i, no_index = 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,
+@@
+ "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()
+ };
+
@@
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);
-+ for (i = 0; i < argc; i++)
-+ if (!strcmp(argv[i], "--"))
-+ break;
-+ else if (!strcmp(argv[i], "--no-index")) {
-+ no_index = 1;
-+ break;
-+ }
-+
+ if (!no_index && !startup_info->have_repository)
+ die(_("difftool requires worktree or --no-index"));
+
@@ -73,13 +73,13 @@
'
+test_expect_success 'outside worktree' '
-+ mkdir outside &&
-+ echo 1 >outside/1 &&
-+ echo 2 >outside/2 &&
-+ test_expect_code 1 env GIT_CEILING_DIRECTORIES="$(pwd)" git \
++ echo 1 >1 &&
++ echo 2 >2 &&
++ test_expect_code 1 nongit git \
+ -c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \
-+ -C outside difftool --no-prompt --no-index 1 2 >out &&
-+ test "1 2" = "$(cat out)"
++ difftool --no-prompt --no-index ../1 ../2 >actual &&
++ echo "../1 ../2" >expect &&
++ test_cmp expect actual
+'
+
test_done
--
gitgitgadget
next prev parent reply other threads:[~2019-03-14 11:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-13 19:20 [PATCH 0/2] Allow difftool to be run outside of Git worktrees Johannes Schindelin via GitGitGadget
2019-03-13 19:20 ` [PATCH 2/2] difftool: allow running outside Git worktrees with --no-index Johannes Schindelin via GitGitGadget
2019-03-13 20:46 ` Jeff King
2019-03-14 12:16 ` Johannes Schindelin
2019-03-15 3:08 ` Jeff King
2019-03-13 19:20 ` [PATCH 1/2] difftool: remove obsolete (and misleading) comment Johannes Schindelin via GitGitGadget
2019-03-14 11:25 ` Johannes Schindelin via GitGitGadget [this message]
2019-03-14 11:25 ` [PATCH v2 1/3] " Johannes Schindelin via GitGitGadget
2019-03-14 11:25 ` [PATCH v2 3/3] difftool: allow running outside Git worktrees with --no-index Johannes Schindelin via GitGitGadget
2019-03-15 3:17 ` Jeff King
2019-03-15 13:20 ` Johannes Schindelin
2019-03-14 11:25 ` [PATCH v2 2/3] parse-options: make OPT_ARGUMENT() more useful Johannes Schindelin via GitGitGadget
2019-03-15 3:15 ` Jeff King
2019-03-15 13:24 ` Johannes Schindelin
2019-03-18 2:47 ` Junio C Hamano
2019-03-18 21:04 ` Jeff King
2019-03-19 0:25 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.163.v2.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).