2 # Copyright (c) 2009, 2010 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'.
17 use File
::Basename
qw(dirname);
21 my $DIR = abs_path
(dirname
($0));
27 usage
: git difftool
[-t
|--tool
=<tool
>] [-x
|--extcmd
=<cmd
>]
28 [-y
|--no-prompt
] [-g
|--gui
]
36 $ENV{PATH
} = "$DIR:$ENV{PATH}";
38 $ENV{GIT_EXTERNAL_DIFF
} = 'git-difftool--helper';
44 if ($^O
eq 'MSWin32' || $^O
eq 'msys') {
52 my @command = (exe
('git'), 'diff');
62 if ($arg eq '-t' || $arg eq '--tool') {
63 usage
() if $#ARGV <= $idx;
64 $ENV{GIT_DIFF_TOOL
} = $ARGV[$idx + 1];
68 if ($arg =~ /^--tool=/) {
69 $ENV{GIT_DIFF_TOOL
} = substr($arg, 7);
72 if ($arg eq '-x' || $arg eq '--extcmd') {
73 usage
() if $#ARGV <= $idx;
74 $ENV{GIT_DIFFTOOL_EXTCMD
} = $ARGV[$idx + 1];
78 if ($arg =~ /^--extcmd=/) {
79 $ENV{GIT_DIFFTOOL_EXTCMD
} = substr($arg, 9);
82 if ($arg eq '-g' || $arg eq '--gui') {
84 my $tool = Git
::command_oneline
('config',
87 $ENV{GIT_DIFF_TOOL
} = $tool;
92 if ($arg eq '-y' || $arg eq '--no-prompt') {
96 if ($arg eq '--prompt') {
105 if ($prompt eq 'yes') {
106 $ENV{GIT_DIFFTOOL_PROMPT
} = 'true';
107 } elsif ($prompt eq 'no') {
108 $ENV{GIT_DIFFTOOL_NO_PROMPT
} = 'true';
115 # ActiveState Perl for Win32 does not implement POSIX semantics of
116 # exec* system call. It just spawns the given executable and finishes
117 # the starting program, exiting with code 0.
118 # system will at least catch the errors returned by git diff,
119 # allowing the caller of git difftool better handling of failures.
120 my $rc = system(generate_command
());
121 exit($rc | ($rc >> 8));