@@ -690,7 +690,7 @@ static int run_file_diff(int prompt, const char *prefix,
690690int cmd_difftool (int argc , const char * * argv , const char * prefix )
691691{
692692 int use_gui_tool = 0 , dir_diff = 0 , prompt = -1 , symlinks = 0 ,
693- tool_help = 0 ;
693+ tool_help = 0 , no_index = 0 ;
694694 static char * difftool_cmd = NULL , * extcmd = NULL ;
695695 struct option builtin_difftool_options [] = {
696696 OPT_BOOL ('g' , "gui" , & use_gui_tool ,
@@ -714,6 +714,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
714714 "tool returns a non - zero exit code" )),
715715 OPT_STRING ('x' , "extcmd" , & extcmd , N_ ("command" ),
716716 N_ ("specify a custom command for viewing diffs" )),
717+ OPT_ARGUMENT ("no-index" , & no_index , N_ ("passed to `diff`" )),
717718 OPT_END ()
718719 };
719720
@@ -727,9 +728,15 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
727728 if (tool_help )
728729 return print_tool_help ();
729730
730- /* NEEDSWORK: once we no longer spawn anything, remove this */
731- setenv (GIT_DIR_ENVIRONMENT , absolute_path (get_git_dir ()), 1 );
732- setenv (GIT_WORK_TREE_ENVIRONMENT , absolute_path (get_git_work_tree ()), 1 );
731+ if (!no_index && !startup_info -> have_repository )
732+ die (_ ("difftool requires worktree or --no-index" ));
733+
734+ if (!no_index ){
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+ } else if (dir_diff )
739+ die (_ ("--dir-diff is incompatible with --no-index" ));
733740
734741 if (use_gui_tool && diff_gui_tool && * diff_gui_tool )
735742 setenv ("GIT_DIFF_TOOL" , diff_gui_tool , 1 );
0 commit comments