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 <tobias.schulte@gliderpilot.de> Signed-off-by: Eric Wong <normalperson@yhbt.net>

Tobias Schulte committed May 15, 2013 at 22:14 UTC f4f4c7fc00e8acf91150c717cf005fc36c1dd120
3 files changed +71 -1
Documentation/git-svn.txt
+5
@@ -300,6 +300,11 @@ where <name> is the name of the SVN repository as specified by the -R option to
300 git config --get-all svn-remote.<name>.commiturl
301 +
302
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 +
308 'tag'::
309 Create a tag in the SVN repository. This is a shorthand for
310 'branch -t'.
git-svn.perl
+18 -1
@@ -113,7 +113,7 @@ my ($_stdin, $_help, $_edit,
113 $_template, $_shared,
114 $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
115 $_before, $_after,
116 - $_merge, $_strategy, $_preserve_merges, $_dry_run, $_local,
116 + $_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
117 $_prefix, $_no_checkout, $_url, $_verbose,
118 $_commit_url, $_tag, $_merge_info, $_interactive);
119
@@ -203,6 +203,7 @@ my %cmd = (
203 { 'message|m=s' => \$_message,
204 'destination|d=s' => \$_branch_dest,
205 'dry-run|n' => \$_dry_run,
206 + 'parents' => \$_parents,
207 'tag|t' => \$_tag,
208 'username=s' => \$Git::SVN::Prompt::_username,
209 'commit-url=s' => \$_commit_url } ],
@@ -211,6 +212,7 @@ my %cmd = (
212 { 'message|m=s' => \$_message,
213 'destination|d=s' => \$_branch_dest,
214 'dry-run|n' => \$_dry_run,
215 + 'parents' => \$_parents,
216 'username=s' => \$Git::SVN::Prompt::_username,
217 'commit-url=s' => \$_commit_url } ],
218 'set-tree' => [ \&cmd_set_tree,
@@ -1172,6 +1174,10 @@ sub cmd_branch {
1174 $ctx->ls($dst, 'HEAD', 0);
1175 } and die "branch ${branch_name} already exists\n";
1176
1177 + if ($_parents) {
1178 + mk_parent_dirs($ctx, $dst);
1179 + }
1180 +
1181 print "Copying ${src} at r${rev} to ${dst}...\n";
1182 $ctx->copy($src, $rev, $dst)
1183 unless $_dry_run;
@@ -1179,6 +1185,17 @@ sub cmd_branch {
1185 $gs->fetch_all;
1186 }
1187
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 +
1199 sub cmd_find_rev {
1200 my $revision_or_hash = shift or die "SVN or git revision required ",
1201 "as a command-line argument\n";
t/t9167-git-svn-cmd-branch-subproject.sh new
+48
@@ -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