git-add: introduce --edit (to edit the diff vs. the index)
[git/dscho.git] / git-difftool.perl
blob0deda3a0e41511bb1b71d30d335b4909e8719169
1 #!/usr/bin/env perl
2 # Copyright (c) 2009 David Aguilar
4 # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
5 # git-difftool-helper script. This script exports
6 # GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and
7 # GIT_DIFFTOOL_NO_PROMPT and GIT_DIFF_TOOL for use by git-difftool-helper.
8 # Any arguments that are unknown to this script are forwarded to 'git diff'.
10 use strict;
11 use warnings;
12 use Cwd qw(abs_path);
13 use File::Basename qw(dirname);
15 my $DIR = abs_path(dirname($0));
18 sub usage
20 print << 'USAGE';
21 usage: git difftool [--tool=<tool>] [--no-prompt] ["git diff" options]
22 USAGE
23 exit 1;
26 sub setup_environment
28 $ENV{PATH} = "$DIR:$ENV{PATH}";
29 $ENV{GIT_PAGER} = '';
30 $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool-helper';
33 sub exe
35 my $exe = shift;
36 return defined $ENV{COMSPEC} ? "$exe.exe" : $exe;
39 sub generate_command
41 my @command = (exe('git'), 'diff');
42 my $skip_next = 0;
43 my $idx = -1;
44 for my $arg (@ARGV) {
45 $idx++;
46 if ($skip_next) {
47 $skip_next = 0;
48 next;
50 if ($arg eq '-t' or $arg eq '--tool') {
51 usage() if $#ARGV <= $idx;
52 $ENV{GIT_DIFF_TOOL} = $ARGV[$idx + 1];
53 $skip_next = 1;
54 next;
56 if ($arg =~ /^--tool=/) {
57 $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
58 next;
60 if ($arg eq '--no-prompt') {
61 $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
62 next;
64 if ($arg eq '-h' or $arg eq '--help') {
65 usage();
67 push @command, $arg;
69 return @command
72 setup_environment();
73 exec(generate_command());