difftool --no-index: error out on --dir-diff (and don't crash)

In `--no-index` mode, we now no longer require a worktree nor a repository. But some code paths in `difftool` expect those to be present. The most notable such code path is the `--dir-diff` one: we use the existing checkout machinery to copy the files, and that machinery looks up replacement refs, looks at alternate ODBs, wants to use the worktree path, etc. Rather than running into segmentation faults, let's die with an informative error message. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed May 8, 2019 at 14:52 UTC f3a3a021c716b46ed35e6b7171bbff4d8042da68
1 file changed +2 -1
builtin/difftool.c
+2 -1
@@ -735,7 +735,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
735 setup_work_tree();
736 setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
737 setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
738 - }
738 + } else if (dir_diff)
739 + die(_("--dir-diff is incompatible with --no-index"));
740
741 if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
742 setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);