@@ -690,7 +690,7 @@ static int run_file_diff(int prompt, const char *prefix,
690
690
int cmd_difftool (int argc , const char * * argv , const char * prefix )
691
691
{
692
692
int use_gui_tool = 0 , dir_diff = 0 , prompt = -1 , symlinks = 0 ,
693
- tool_help = 0 ;
693
+ tool_help = 0 , no_index = 0 ;
694
694
static char * difftool_cmd = NULL , * extcmd = NULL ;
695
695
struct option builtin_difftool_options [] = {
696
696
OPT_BOOL ('g' , "gui" , & use_gui_tool ,
@@ -714,6 +714,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
714
714
"tool returns a non - zero exit code" )),
715
715
OPT_STRING ('x' , "extcmd" , & extcmd , N_ ("command" ),
716
716
N_ ("specify a custom command for viewing diffs" )),
717
+ OPT_ARGUMENT ("no-index" , & no_index , N_ ("passed to `diff`" )),
717
718
OPT_END ()
718
719
};
719
720
@@ -727,9 +728,15 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
727
728
if (tool_help )
728
729
return print_tool_help ();
729
730
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" ));
733
740
734
741
if (use_gui_tool && diff_gui_tool && * diff_gui_tool )
735
742
setenv ("GIT_DIFF_TOOL" , diff_gui_tool , 1 );
0 commit comments