diff options
author | David Aguilar <davvid@gmail.com> | 2009-01-16 00:00:02 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-01-17 21:40:57 -0800 |
commit | 5c38ea31f345d08f37685cf4f50c599a7af56bcf (patch) | |
tree | 1eefc0e0c9b34a6a594f64c81abe7c76fe203148 /contrib/difftool/git-difftool | |
parent | 3d279863dedf6c07eefe307b27fb3a08e519140f (diff) | |
download | git-5c38ea31f345d08f37685cf4f50c599a7af56bcf.tar.gz git-5c38ea31f345d08f37685cf4f50c599a7af56bcf.tar.xz |
contrib: add 'git difftool' for launching common merge tools
'git difftool' is a git command that allows you to compare and edit files
between revisions using common merge tools. 'git difftool' does what
'git mergetool' does but its use is for non-merge situations such as
when preparing commits or comparing changes against the index.
It uses the same configuration variables as 'git mergetool' and
provides the same command-line interface as 'git diff'.
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/difftool/git-difftool')
-rwxr-xr-x | contrib/difftool/git-difftool | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/contrib/difftool/git-difftool b/contrib/difftool/git-difftool new file mode 100755 index 000000000..1fc087c5f --- /dev/null +++ b/contrib/difftool/git-difftool @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +# Copyright (c) 2009 David Aguilar +# +# This is a wrapper around the GIT_EXTERNAL_DIFF-compatible +# git-difftool-helper script. This script exports +# GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and +# GIT_NO_PROMPT and GIT_MERGE_TOOL for use by git-difftool-helper. +# Any arguments that are unknown to this script are forwarded to 'git diff'. + +use strict; +use warnings; +use Cwd qw(abs_path); +use File::Basename qw(dirname); + +my $DIR = abs_path(dirname($0)); + + +sub usage +{ + print << 'USAGE'; + +usage: git difftool [--no-prompt] [--tool=tool] ["git diff" options] +USAGE + exit 1; +} + +sub setup_environment +{ + $ENV{PATH} = "$DIR:$ENV{PATH}"; + $ENV{GIT_PAGER} = ''; + $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool-helper'; +} + +sub exe +{ + my $exe = shift; + return defined $ENV{COMSPEC} ? "$exe.exe" : $exe; +} + +sub generate_command +{ + my @command = (exe('git'), 'diff'); + my $skip_next = 0; + my $idx = -1; + for my $arg (@ARGV) { + $idx++; + if ($skip_next) { + $skip_next = 0; + next; + } + if ($arg eq '-t' or $arg eq '--tool') { + usage() if $#ARGV <= $idx; + $ENV{GIT_MERGE_TOOL} = $ARGV[$idx + 1]; + $skip_next = 1; + next; + } + if ($arg =~ /^--tool=/) { + $ENV{GIT_MERGE_TOOL} = substr($arg, 7); + next; + } + if ($arg eq '--no-prompt') { + $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; + next; + } + if ($arg eq '-h' or $arg eq '--help') { + usage(); + } + push @command, $arg; + } + return @command +} + +setup_environment(); +exec(generate_command()); |