Skip to content

Commit bc93ceb

Browse files
barrywardellEric Wong
authored andcommitted
git-svn: Simplify calculation of GIT_DIR
Since git-rev-parse already checks for the $GIT_DIR environment variable and that it returns an actual git repository, there is no need to repeat the checks again here. This also fixes a problem where git-svn did not work in cases where .git was a file with a gitdir: link. [ew: squashed test case, delay setting GIT_DIR until after `git rev-parse --cdup` to fix t9101, (thanks to Junio)] Signed-off-by: Barry Wardell <[email protected]> Signed-off-by: Eric Wong <[email protected]>
1 parent 1b67bef commit bc93ceb

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

git-svn.perl

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ BEGIN
6161
command_oneline([qw/rev-parse --show-prefix/], STDERR => 0)
6262
} || '';
6363

64-
my $git_dir_user_set = 1 if defined $ENV{GIT_DIR};
65-
$ENV{GIT_DIR} ||= '.git';
6664
$Git::SVN::Ra::_log_window_size = 100;
6765

6866
if (! exists $ENV{SVN_SSH} && exists $ENV{GIT_SSH}) {
@@ -327,27 +325,20 @@ package main;
327325
};
328326

329327
# make sure we're always running at the top-level working directory
330-
unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
331-
unless (-d $ENV{GIT_DIR}) {
332-
if ($git_dir_user_set) {
333-
die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
334-
"but it is not a directory\n";
335-
}
336-
my $git_dir = delete $ENV{GIT_DIR};
337-
my $cdup = undef;
338-
git_cmd_try {
339-
$cdup = command_oneline(qw/rev-parse --show-cdup/);
340-
$git_dir = '.' unless ($cdup);
341-
chomp $cdup if ($cdup);
342-
$cdup = "." unless ($cdup && length $cdup);
343-
} "Already at toplevel, but $git_dir not found\n";
344-
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
345-
unless (-d $git_dir) {
346-
die "$git_dir still not found after going to ",
347-
"'$cdup'\n";
348-
}
349-
$ENV{GIT_DIR} = $git_dir;
350-
}
328+
if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
329+
$ENV{GIT_DIR} ||= ".git";
330+
} else {
331+
my ($git_dir, $cdup);
332+
git_cmd_try {
333+
$git_dir = command_oneline([qw/rev-parse --git-dir/]);
334+
} "Unable to find .git directory\n";
335+
git_cmd_try {
336+
$cdup = command_oneline(qw/rev-parse --show-cdup/);
337+
chomp $cdup if ($cdup);
338+
$cdup = "." unless ($cdup && length $cdup);
339+
} "Already at toplevel, but $git_dir not found\n";
340+
$ENV{GIT_DIR} = $git_dir;
341+
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
351342
$_repository = Git->repository(Repository => $ENV{GIT_DIR});
352343
}
353344

t/t9100-git-svn-basic.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,13 @@ test_expect_success 'git-svn works in a bare repository' '
306306
git svn fetch ) &&
307307
rm -rf bare-repo
308308
'
309+
test_expect_success 'git-svn works in in a repository with a gitdir: link' '
310+
mkdir worktree gitdir &&
311+
( cd worktree &&
312+
git svn init "$svnrepo" &&
313+
git init --separate-git-dir ../gitdir &&
314+
git svn fetch ) &&
315+
rm -rf worktree gitdir
316+
'
309317

310318
test_done

0 commit comments

Comments
 (0)