Skip to content

Commit

Permalink
git-svn: proper detection of bare repositories
Browse files Browse the repository at this point in the history
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 <deskinm@umich.edu>
Acked-by: Eric Wong <normalperson@yhbt.net>
  • Loading branch information
Deskin Miller authored and Eric Wong committed Nov 14, 2008
1 parent 16fc08e commit fe4003f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 7 additions & 5 deletions git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ BEGIN
"but it is not a directory\n";
}
my $git_dir = delete $ENV{GIT_DIR};
chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
unless (length $cdup) {
die "Already at toplevel, but $git_dir ",
"not found '$cdup'\n";
}
my $cdup = undef;
git_cmd_try {
$cdup = command_oneline(qw/rev-parse --show-cdup/);
$git_dir = '.' unless ($cdup);
chomp $cdup if ($cdup);
$cdup = "." unless ($cdup && length $cdup);
} "Already at toplevel, but $git_dir not found\n";
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
unless (-d $git_dir) {
die "$git_dir still not found after going to ",
Expand Down
9 changes: 9 additions & 0 deletions t/t9100-git-svn-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' "
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
"

test_expect_success 'git-svn works in a bare repository' '
mkdir bare-repo &&
( cd bare-repo &&
git init --bare &&
GIT_DIR=. git svn init "$svnrepo" &&
git svn fetch ) &&
rm -rf bare-repo
'

test_done

0 comments on commit fe4003f

Please sign in to comment.