Skip to content

Commit 6e5121f

Browse files
deskinEric Wong
authored andcommitted
git-svn: proper detection of bare repositories
When in a bare repository (or .git, for that matter), git-svn would fail to initialise properly, since git rev-parse --show-cdup would not output anything. However, git rev-parse --show-cdup actually returns an error code if it's really not in a git directory. Fix the issue by checking for an explicit error from git rev-parse, and setting $git_dir appropriately if instead it just does not output. Signed-off-by: Deskin Miller <[email protected]> Acked-by: Eric Wong <[email protected]>
1 parent aab5720 commit 6e5121f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

git-svn.perl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ BEGIN
223223
"but it is not a directory\n";
224224
}
225225
my $git_dir = delete $ENV{GIT_DIR};
226-
chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
227-
unless (length $cdup) {
228-
die "Already at toplevel, but $git_dir ",
229-
"not found '$cdup'\n";
230-
}
226+
my $cdup = undef;
227+
git_cmd_try {
228+
$cdup = command_oneline(qw/rev-parse --show-cdup/);
229+
$git_dir = '.' unless ($cdup);
230+
chomp $cdup if ($cdup);
231+
$cdup = "." unless ($cdup && length $cdup);
232+
} "Already at toplevel, but $git_dir not found\n";
231233
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
232234
unless (-d $git_dir) {
233235
die "$git_dir still not found after going to ",

t/t9100-git-svn-basic.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' "
265265
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
266266
"
267267

268+
test_expect_success 'git-svn works in a bare repository' '
269+
mkdir bare-repo &&
270+
( cd bare-repo &&
271+
git init --bare &&
272+
GIT_DIR=. git svn init "$svnrepo" &&
273+
git svn fetch ) &&
274+
rm -rf bare-repo
275+
'
276+
268277
test_done

0 commit comments

Comments
 (0)