Skip to content

Commit b186a26

Browse files
author
Eric Wong
committed
svn: initial "master" points to trunk if possible
Since "trunk" is a convention for the main development branch in the SVN world, try to make that the master branch upon initial checkout if it exists. This is probably less surprising based on user requests. t9135 was the only test which relied on the previous behavior and thus needed to be modified. Signed-off-by: Eric Wong <normalperson@yhbt.net>
1 parent 6ffd781 commit b186a26

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

git-svn.perl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,17 @@ sub post_fetch_checkout {
11561156
my $gs = $Git::SVN::_head or return;
11571157
return if verify_ref('refs/heads/master^0');
11581158

1159+
# look for "trunk" ref if it exists
1160+
my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
1161+
my $fetch = $remote->{fetch};
1162+
if ($fetch) {
1163+
foreach my $p (keys %$fetch) {
1164+
basename($fetch->{$p}) eq 'trunk' or next;
1165+
$gs = Git::SVN->new($fetch->{$p}, $gs->{repo_id}, $p);
1166+
last;
1167+
}
1168+
}
1169+
11591170
my $valid_head = verify_ref('HEAD^0');
11601171
command_noisy(qw(update-ref refs/heads/master), $gs->refname);
11611172
return if ($valid_head || !verify_ref('HEAD^0'));

t/t9135-git-svn-moved-branch-empty-file.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ test_expect_success 'load svn dumpfile' '
1010
test_expect_success 'clone using git svn' 'git svn clone -s "$svnrepo" x'
1111

1212
test_expect_success 'test that b1 exists and is empty' '
13-
(cd x && test -f b1 && ! test -s b1)
13+
(
14+
cd x &&
15+
git reset --hard branch-c &&
16+
test -f b1 &&
17+
! test -s b1
18+
)
1419
'
1520

1621
test_done

t/t9145-git-svn-master-branch.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Eric Wong
4+
#
5+
test_description='git svn initial master branch is "trunk" if possible'
6+
. ./lib-git-svn.sh
7+
8+
test_expect_success 'setup test repository' '
9+
mkdir i &&
10+
> i/a &&
11+
svn_cmd import -m trunk i "$svnrepo/trunk" &&
12+
svn_cmd import -m b/a i "$svnrepo/branches/a" &&
13+
svn_cmd import -m b/b i "$svnrepo/branches/b"
14+
'
15+
16+
test_expect_success 'git svn clone --stdlayout sets up trunk as master' '
17+
git svn clone -s "$svnrepo" g &&
18+
(
19+
cd g &&
20+
test x`git rev-parse --verify refs/remotes/trunk^0` = \
21+
x`git rev-parse --verify refs/heads/master^0`
22+
)
23+
'
24+
25+
test_done

0 commit comments

Comments
 (0)