Skip to content

Commit 4aacaeb

Browse files
author
Eric Wong
committed
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>
1 parent 0ad8ff2 commit 4aacaeb

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

git-svn.perl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ sub fetch_all {
16471647
my $ra = Git::SVN::Ra->new($url);
16481648
my $uuid = $ra->get_uuid;
16491649
my $head = $ra->get_latest_revnum;
1650+
$ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] });
16501651
my $base = defined $fetch ? $head : 0;
16511652

16521653
# read the max revs for wildcard expansion (branches/*, tags/*)

t/t9142-git-svn-shallow-clone.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)