Skip to content

Commit f4f4c7f

Browse files
tschulteEric Wong
authored andcommitted
git-svn: introduce --parents parameter for commands branch and tag
This parameter is equivalent to the parameter --parents on svn cp commands and is useful for non-standard repository layouts. Signed-off-by: Tobias Schulte <[email protected]> Signed-off-by: Eric Wong <[email protected]>
1 parent 7d82b4a commit f4f4c7f

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

Documentation/git-svn.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ where <name> is the name of the SVN repository as specified by the -R option to
300300
git config --get-all svn-remote.<name>.commiturl
301301
+
302302

303+
--parents;;
304+
Create parent folders. This parameter is equivalent to the parameter
305+
--parents on svn cp commands and is useful for non-standard repository
306+
layouts.
307+
303308
'tag'::
304309
Create a tag in the SVN repository. This is a shorthand for
305310
'branch -t'.

git-svn.perl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ sub _req_svn {
113113
$_template, $_shared,
114114
$_version, $_fetch_all, $_no_rebase, $_fetch_parent,
115115
$_before, $_after,
116-
$_merge, $_strategy, $_preserve_merges, $_dry_run, $_local,
116+
$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
117117
$_prefix, $_no_checkout, $_url, $_verbose,
118118
$_commit_url, $_tag, $_merge_info, $_interactive);
119119

@@ -203,6 +203,7 @@ sub _req_svn {
203203
{ 'message|m=s' => \$_message,
204204
'destination|d=s' => \$_branch_dest,
205205
'dry-run|n' => \$_dry_run,
206+
'parents' => \$_parents,
206207
'tag|t' => \$_tag,
207208
'username=s' => \$Git::SVN::Prompt::_username,
208209
'commit-url=s' => \$_commit_url } ],
@@ -211,6 +212,7 @@ sub _req_svn {
211212
{ 'message|m=s' => \$_message,
212213
'destination|d=s' => \$_branch_dest,
213214
'dry-run|n' => \$_dry_run,
215+
'parents' => \$_parents,
214216
'username=s' => \$Git::SVN::Prompt::_username,
215217
'commit-url=s' => \$_commit_url } ],
216218
'set-tree' => [ \&cmd_set_tree,
@@ -1172,13 +1174,28 @@ sub cmd_branch {
11721174
$ctx->ls($dst, 'HEAD', 0);
11731175
} and die "branch ${branch_name} already exists\n";
11741176

1177+
if ($_parents) {
1178+
mk_parent_dirs($ctx, $dst);
1179+
}
1180+
11751181
print "Copying ${src} at r${rev} to ${dst}...\n";
11761182
$ctx->copy($src, $rev, $dst)
11771183
unless $_dry_run;
11781184

11791185
$gs->fetch_all;
11801186
}
11811187

1188+
sub mk_parent_dirs {
1189+
my ($ctx, $parent) = @_;
1190+
$parent =~ s{/[^/]*$}{};
1191+
1192+
if (!eval{$ctx->ls($parent, 'HEAD', 0)}) {
1193+
mk_parent_dirs($ctx, $parent);
1194+
print "Creating parent folder ${parent} ...\n";
1195+
$ctx->mkdir($parent) unless $_dry_run;
1196+
}
1197+
}
1198+
11821199
sub cmd_find_rev {
11831200
my $revision_or_hash = shift or die "SVN or git revision required ",
11841201
"as a command-line argument\n";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2013 Tobias Schulte
4+
#
5+
6+
test_description='git svn branch for subproject clones'
7+
. ./lib-git-svn.sh
8+
9+
test_expect_success 'initialize svnrepo' '
10+
mkdir import &&
11+
(
12+
cd import &&
13+
mkdir -p trunk/project branches tags &&
14+
(
15+
cd trunk/project &&
16+
echo foo > foo
17+
) &&
18+
svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null
19+
) &&
20+
rm -rf import &&
21+
svn_cmd co "$svnrepo"/trunk/project trunk/project &&
22+
(
23+
cd trunk/project &&
24+
echo bar >> foo &&
25+
svn_cmd ci -m "updated trunk"
26+
) &&
27+
rm -rf trunk
28+
'
29+
30+
test_expect_success 'import into git' '
31+
git svn init --trunk=trunk/project --branches=branches/*/project \
32+
--tags=tags/*/project "$svnrepo" &&
33+
git svn fetch &&
34+
git checkout remotes/trunk
35+
'
36+
37+
test_expect_success 'git svn branch tests' '
38+
test_must_fail git svn branch a &&
39+
git svn branch --parents a &&
40+
test_must_fail git svn branch -t tag1 &&
41+
git svn branch --parents -t tag1 &&
42+
test_must_fail git svn branch --tag tag2 &&
43+
git svn branch --parents --tag tag2 &&
44+
test_must_fail git svn tag tag3 &&
45+
git svn tag --parents tag3
46+
'
47+
48+
test_done

0 commit comments

Comments
 (0)