@matheusbsbs / matheus-bagliano / commits / 4aacaeb3dc
Fork 0

git svn: fix shallow clone when upstream revision is too new

Thanks to Ka-Hing Cheung for the initial bug report and patch: > git-svn uses $ra->get_latest_revnum to find out the latest > revision, but that can be problematic, because get_latest_revnum > returns the latest revnum in the entire repository, not > restricted by whatever URL you used to construct $ra. So if you > do git svn clone -r HEAD svn://blah/blah/trunk, it won't work if > the latest checkin is in one of the branches (it will try to > fetch a rev that doesn't exist in trunk, making the clone > useless). Relying on SVN::Core::INVALID_REVNUM (-1) as the "start" argument to SVN::Ra::get_log() proved unreliable with http(s) URLs so the result of SVN::Ra::get_latest_revnum() is used as the "start" argument instead. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jul 20, 2009 at 02:06 UTC 4aacaeb3dc82bb6479e70e120053dc27a399460e
2 files changed +31
git-svn.perl
+1
@@ -1647,6 +1647,7 @@ sub fetch_all {
1647 my $ra = Git::SVN::Ra->new($url);
1648 my $uuid = $ra->get_uuid;
1649 my $head = $ra->get_latest_revnum;
1650 + $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] });
1651 my $base = defined $fetch ? $head : 0;
1652
1653 # read the max revs for wildcard expansion (branches/*, tags/*)
t/t9142-git-svn-shallow-clone.sh new
+30
@@ -0,0 +1,30 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2009 Eric Wong
4 +#
5 +
6 +test_description='git svn shallow clone'
7 +. ./lib-git-svn.sh
8 +
9 +test_expect_success 'setup test repository' '
10 + svn_cmd mkdir -m "create standard layout" \
11 + "$svnrepo"/trunk "$svnrepo"/branches "$svnrepo"/tags &&
12 + svn_cmd cp -m "branch off trunk" \
13 + "$svnrepo"/trunk "$svnrepo"/branches/a &&
14 + svn_cmd co "$svnrepo"/branches/a &&
15 + (
16 + cd a &&
17 + > foo &&
18 + svn_cmd add foo &&
19 + svn_cmd commit -m "add foo"
20 + )
21 +'
22 +
23 +start_httpd
24 +
25 +test_expect_success 'clone trunk with "-r HEAD"' '
26 + git svn clone -r HEAD "$svnrepo/trunk" g &&
27 + ( cd g && git rev-parse --symbolic --verify HEAD )
28 +'
29 +
30 +test_done