Skip to content

Commit 7c7584b

Browse files
davvidgitster
authored andcommitted
difftool: Handle finding mergetools/ in a path with spaces
Use the original File::Find implementation from bf73fc2 (difftool: print list of valid tools with '--tool-help', 2012-03-29) so that we properly handle mergetools/ being located in a path containing spaces. One small difference is that we avoid using a global variable by passing a reference to the list of tools. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1f22934 commit 7c7584b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

git-difftool.perl

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
use 5.008;
1414
use strict;
1515
use warnings;
16-
use File::Basename qw(basename dirname);
16+
use File::Basename qw(dirname);
1717
use File::Copy;
1818
use File::Compare;
19+
use File::Find;
1920
use File::stat;
2021
use File::Path qw(mkpath);
2122
use File::Temp qw(tempdir);
@@ -58,13 +59,27 @@ sub find_worktree
5859
return $worktree;
5960
}
6061

62+
sub filter_tool_scripts
63+
{
64+
my ($tools) = @_;
65+
if (-d $_) {
66+
if ($_ ne ".") {
67+
# Ignore files in subdirectories
68+
$File::Find::prune = 1;
69+
}
70+
} else {
71+
if ((-f $_) && ($_ ne "defaults")) {
72+
push(@$tools, $_);
73+
}
74+
}
75+
}
76+
6177
sub print_tool_help
6278
{
63-
my ($cmd, @found, @notfound);
79+
my ($cmd, @found, @notfound, @tools);
6480
my $gitpath = Git::exec_path();
6581

66-
my @files = map { basename($_) } glob("$gitpath/mergetools/*");
67-
my @tools = sort(grep { !m{^defaults$} } @files);
82+
find(sub { filter_tool_scripts(\@tools) }, "$gitpath/mergetools");
6883

6984
foreach my $tool (@tools) {
7085
$cmd = "TOOL_MODE=diff";
@@ -79,10 +94,10 @@ sub print_tool_help
7994
}
8095

8196
print "'git difftool --tool=<tool>' may be set to one of the following:\n";
82-
print "\t$_\n" for (@found);
97+
print "\t$_\n" for (sort(@found));
8398

8499
print "\nThe following tools are valid, but not currently available:\n";
85-
print "\t$_\n" for (@notfound);
100+
print "\t$_\n" for (sort(@notfound));
86101

87102
print "\nNOTE: Some of the tools listed above only work in a windowed\n";
88103
print "environment. If run in a terminal-only session, they will fail.\n";

0 commit comments

Comments
 (0)