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>
Eric Wong committed
Aug 12, 2009 at 16:01 UTC
b186a261b1f7ec1fbda8c5f6d84595f3a7716d92
3 files changed
+42
-1
git-svn.perl
+11
@@ -1156,6 +1156,17 @@ sub post_fetch_checkout {
1156
my $gs = $Git::SVN::_head or return;
1157
return if verify_ref('refs/heads/master^0');
1158
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
+
1170
my $valid_head = verify_ref('HEAD^0');
1171
command_noisy(qw(update-ref refs/heads/master), $gs->refname);
1172
return if ($valid_head || !verify_ref('HEAD^0'));
t/t9135-git-svn-moved-branch-empty-file.sh
+6
-1
@@ -10,7 +10,12 @@ test_expect_success 'load svn dumpfile' '
10
test_expect_success 'clone using git svn' 'git svn clone -s "$svnrepo" x'
11
12
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
+ )
19
'
20
21
test_done
t/t9145-git-svn-master-branch.sh
new
+25
@@ -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