git-svn: allow --version to work anywhere

Checking the version of the installed SVN libraries should not require a git repository at all. This matches the behavior of "git --version". Add a test for "git svn help" for the same behavior while we're at it, too. Signed-off-by: Eric Wong <e@80x24.org>

Eric Wong committed Jul 22, 2016 at 20:17 UTC c0071ae5dc1c610ab3791ece7ccf7d4772fde151
2 files changed +21 -2
git-svn.perl
+2 -2
@@ -339,7 +339,7 @@ if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
339 die "failed to open $ENV{GIT_DIR}: $!\n";
340 $ENV{GIT_DIR} = $1 if <$fh> =~ /^gitdir: (.+)$/;
341 }
342 -} else {
342 +} elsif ($cmd) {
343 my ($git_dir, $cdup);
344 git_cmd_try {
345 $git_dir = command_oneline([qw/rev-parse --git-dir/]);
@@ -356,7 +356,7 @@ if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
356
357 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
358
359 -read_git_config(\%opts);
359 +read_git_config(\%opts) if $ENV{GIT_DIR};
360 if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')) {
361 Getopt::Long::Configure('pass_through');
362 }
t/t9100-git-svn-basic.sh
+19
@@ -19,6 +19,25 @@ case "$GIT_SVN_LC_ALL" in
19 ;;
20 esac
21
22 +deepdir=nothing-above
23 +ceiling=$PWD
24 +
25 +test_expect_success 'git svn --version works anywhere' '
26 + mkdir -p "$deepdir" && (
27 + export GIT_CEILING_DIRECTORIES="$ceiling" &&
28 + cd "$deepdir" &&
29 + git svn --version
30 + )
31 +'
32 +
33 +test_expect_success 'git svn help works anywhere' '
34 + mkdir -p "$deepdir" && (
35 + export GIT_CEILING_DIRECTORIES="$ceiling" &&
36 + cd "$deepdir" &&
37 + git svn help
38 + )
39 +'
40 +
41 test_expect_success \
42 'initialize git svn' '
43 mkdir import &&