Merge branch 'dl/difftool-mergetool'
authorJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 07:45:30 +0000 (16:45 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 07:45:30 +0000 (16:45 +0900)
Update "git difftool" and "git mergetool" so that the combinations
of {diff,merge}.{tool,guitool} configuration variables serve as
fallback settings of each other in a sensible order.

* dl/difftool-mergetool:
difftool: fallback on merge.guitool
difftool: make --gui, --tool and --extcmd mutually exclusive
mergetool: fallback to tool when guitool unavailable
mergetool--lib: create gui_mode function
mergetool: use get_merge_tool function
t7610: add mergetool --gui tests
t7610: unsuppress output

1  2 
builtin/difftool.c
git-mergetool--lib.sh
t/t7800-difftool.sh
index 04ffa1d943d6e3a22eb919a21ad775c0bb29a6db,2205de1214695f1741dd9a46002183328807de0e..53188df71438ad83186bcae37a8742704ae048a5
@@@ -726,17 -720,15 +720,20 @@@ int cmd_difftool(int argc, const char *
        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);
 +      }
  
-       if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
-               setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);
+       if (use_gui_tool + !!difftool_cmd + !!extcmd > 1)
+               die(_("--gui, --tool and --extcmd are mutually exclusive"));
+       if (use_gui_tool)
+               setenv("GIT_MERGETOOL_GUI", "true", 1);
        else if (difftool_cmd) {
                if (*difftool_cmd)
                        setenv("GIT_DIFF_TOOL", difftool_cmd, 1);
Simple merge
index 480dd0633fd3e979aecca82784d38642232d44b4,48b74c04346eb061ed414dbb254543a11f87886f..6bac9ed180e7342b34401b2d6af9e83b4472f08d
@@@ -705,14 -721,12 +721,22 @@@ test_expect_success SYMLINKS 'difftool 
        test_cmp expect actual
  '
  
 +test_expect_success 'outside worktree' '
 +      echo 1 >1 &&
 +      echo 2 >2 &&
 +      test_expect_code 1 nongit git \
 +              -c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \
 +              difftool --no-prompt --no-index ../1 ../2 >actual &&
 +      echo "../1 ../2" >expect &&
 +      test_cmp expect actual
 +'
 +
+ test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive' '
+       difftool_test_setup &&
+       test_must_fail git difftool --gui --tool=test-tool &&
+       test_must_fail git difftool --gui --extcmd=cat &&
+       test_must_fail git difftool --tool=test-tool --extcmd=cat &&
+       test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
+ '
  test_done