Add initial support for many promisor remotes
[gitweb.git] / builtin / difftool.c
index 5fa83f481efe3b8315463ad7a84a54edacae97bc..16eb8b70ea33eb00516d7ab035a90df9728d5296 100644 (file)
@@ -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;
@@ -688,7 +682,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,
@@ -712,6 +706,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()
        };
 
@@ -725,12 +720,21 @@ 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);
+       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);
+       } else if (dir_diff)
+               die(_("--dir-diff is incompatible with --no-index"));
+
+       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);