2 # Copyright (c) 2009 David Aguilar
4 # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
5 # git-difftool--helper script.
7 # This script exports GIT_EXTERNAL_DIFF and GIT_PAGER for use by git.
8 # GIT_DIFFTOOL_NO_PROMPT, GIT_DIFFTOOL_PROMPT, and GIT_DIFF_TOOL
9 # are exported for use by git-difftool--helper.
11 # Any arguments that are unknown to this script are forwarded to 'git diff'.
16 use File::Basename qw(dirname);
20 my $DIR = abs_path(dirname($0));
26 usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt]
34 $ENV{PATH} = "$DIR:$ENV{PATH}";
36 $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
42 if ($^O eq 'MSWin32' || $^O eq 'msys') {
50 my @command = (exe('git'), 'diff');
59 if ($arg eq '-t' || $arg eq '--tool') {
60 usage() if $#ARGV <= $idx;
61 $ENV{GIT_DIFF_TOOL} = $ARGV[$idx + 1];
65 if ($arg =~ /^--tool=/) {
66 $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
69 if ($arg eq '-g' || $arg eq '--gui') {
70 my $tool = Git::command_oneline('config',
73 $ENV{GIT_DIFF_TOOL} = $tool;
77 if ($arg eq '-y' || $arg eq '--no-prompt') {
78 $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
79 delete $ENV{GIT_DIFFTOOL_PROMPT};
82 if ($arg eq '--prompt') {
83 $ENV{GIT_DIFFTOOL_PROMPT} = 'true';
84 delete $ENV{GIT_DIFFTOOL_NO_PROMPT};
87 if ($arg eq '-h' || $arg eq '--help') {
97 # ActiveState Perl for Win32 does not implement POSIX semantics of
98 # exec* system call. It just spawns the given executable and finishes
99 # the starting program, exiting with code 0.
100 # system will at least catch the errors returned by git diff,
101 # allowing the caller of git difftool better handling of failures.
102 my $rc = system(generate_command());
103 exit($rc | ($rc >> 8));