Code

git-difftool: Add '--gui' for selecting a GUI tool
[git.git] / git-difftool.perl
index 948ff7f6fd2dacc41f10b2b92f6ad752001ea3be..8c836e4c76528e52b010dd37e904f132d5386000 100755 (executable)
@@ -15,13 +15,16 @@ use warnings;
 use Cwd qw(abs_path);
 use File::Basename qw(dirname);
 
+require Git;
+
 my $DIR = abs_path(dirname($0));
 
 
 sub usage
 {
        print << 'USAGE';
-usage: git difftool [--tool=<tool>] [-y|--no-prompt] ["git diff" options]
+usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt]
+                    ["git diff" options]
 USAGE
        exit 1;
 }
@@ -63,6 +66,14 @@ sub generate_command
                        $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
                        next;
                }
+               if ($arg eq '-g' || $arg eq '--gui') {
+                       my $tool = Git::command_oneline('config',
+                                                       'diff.guitool');
+                       if (length($tool)) {
+                               $ENV{GIT_DIFF_TOOL} = $tool;
+                       }
+                       next;
+               }
                if ($arg eq '-y' || $arg eq '--no-prompt') {
                        $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
                        delete $ENV{GIT_DIFFTOOL_PROMPT};
@@ -82,4 +93,11 @@ sub generate_command
 }
 
 setup_environment();
-exec(generate_command());
+
+# ActiveState Perl for Win32 does not implement POSIX semantics of
+# exec* system call. It just spawns the given executable and finishes
+# the starting program, exiting with code 0.
+# system will at least catch the errors returned by git diff,
+# allowing the caller of git difftool better handling of failures.
+my $rc = system(generate_command());
+exit($rc | ($rc >> 8));