@matheusbsbs / matheus-bagliano / commits / fe4003f630
Fork 0

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 <deskinm@umich.edu> Acked-by: Eric Wong <normalperson@yhbt.net>

Deskin Miller committed Nov 6, 2008 at 00:07 UTC fe4003f6308b88bcc44a989f12e1baddd97f22d4
2 files changed +16 -5
git-svn.perl
+7 -5
@@ -223,11 +223,13 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
223 "but it is not a directory\n";
224 }
225 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";
233 chdir $cdup or die "Unable to chdir up to '$cdup'\n";
234 unless (-d $git_dir) {
235 die "$git_dir still not found after going to ",
t/t9100-git-svn-basic.sh
+9
@@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' "
265 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
266 "
267
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 +
277 test_done