Skip to contentSkip to conversation

git-svn: Make branch use correct svn-remote

PATCH In review Deskin Miller 4 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-svn: Make branch use correct svn-remote

The 'branch' subcommand incorrectly had the svn-remote to use hardcoded as 'svn', the default remote name. This meant that branches derived from other svn-remotes would try to use the branch and tag configuration for the 'svn' remote, potentially copying would-be branches to the wrong place in SVN, into the branch namespace for another project.

Fix this by using the remote name extracted from the svn info for the specified git ref. Add a testcase for this behaviour.

---
Applies on v1.6.1-rc1. Apologies for not catching this when first writing testcases for the branch subcommand.

Deskin Miller

 git-svn.perl                  |    2 +-
 t/t9128-git-svn-cmd-branch.sh |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
git-svn.perl +1 -1
index 914c707..e64e97b 100755
@@ -558,7 +558,7 @@ sub cmd_branch {
 
 	my ($src, $rev, undef, $gs) = working_head_info($head);
 
-	my $remote = Git::SVN::read_all_remotes()->{svn};
+	my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
 	my $glob = $remote->{ $_tag ? 'tags' : 'branches' };
 	my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};
 	my $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());
t/t9128-git-svn-cmd-branch.sh +17 -0
index 47c4d4d..e2b6696 100755
@@ -56,4 +56,21 @@ test_expect_success 'git svn branch tests' '
 	test_must_fail git svn tag tag1
 '
 
+test_expect_success 'branch uses correct svn-remote' '
+	(svn co "$svnrepo" svn &&
+	cd svn &&
+	mkdir mirror &&
+	svn add mirror &&
+	svn copy trunk tags branches mirror/ &&
+	svn ci -m "made mirror" ) &&
+	rm -rf svn &&
+	git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
+	git svn fetch -R mirror &&
+	git checkout mirror/trunk &&
+	base=$(git rev-parse HEAD:) &&
+	git svn branch -m "branch in mirror" d &&
+	test $base = $(git rev-parse remotes/mirror/d:) &&
+	test_must_fail git rev-parse remotes/d
+'
+
 test_done
Signature · 1 line
1.6.1.rc1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Deskin Miller

The 'branch' subcommand incorrectly had the svn-remote to use hardcoded as 'svn', the default remote name. This meant that branches derived from other svn-remotes would try to use the branch and tag configuration for the 'svn' remote, potentially copying would-be branches to the wrong place in SVN, into the branch namespace for another project.

Fix this by using the remote name extracted from the svn info for the specified git ref. Add a testcase for this behaviour.

Looks alright to me, thanks Deskin.

Quoted 51 lines

---
Applies on v1.6.1-rc1. Apologies for not catching this when first writing testcases for the branch subcommand.

Deskin Miller

 git-svn.perl                  |    2 +-
 t/t9128-git-svn-cmd-branch.sh |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
git-svn.perl +1 -1
index 914c707..e64e97b 100755
@@ -558,7 +558,7 @@ sub cmd_branch {
 
 	my ($src, $rev, undef, $gs) = working_head_info($head);
 
-	my $remote = Git::SVN::read_all_remotes()->{svn};
+	my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
 	my $glob = $remote->{ $_tag ? 'tags' : 'branches' };
 	my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};
 	my $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());
t/t9128-git-svn-cmd-branch.sh +17 -0
index 47c4d4d..e2b6696 100755
@@ -56,4 +56,21 @@ test_expect_success 'git svn branch tests' '
 	test_must_fail git svn tag tag1
 '
 
+test_expect_success 'branch uses correct svn-remote' '
+	(svn co "$svnrepo" svn &&
+	cd svn &&
+	mkdir mirror &&
+	svn add mirror &&
+	svn copy trunk tags branches mirror/ &&
+	svn ci -m "made mirror" ) &&
+	rm -rf svn &&
+	git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
+	git svn fetch -R mirror &&
+	git checkout mirror/trunk &&
+	base=$(git rev-parse HEAD:) &&
+	git svn branch -m "branch in mirror" d &&
+	test $base = $(git rev-parse remotes/mirror/d:) &&
+	test_must_fail git rev-parse remotes/d
+'
+
 test_done
Signature · 1 line
1.6.1.rc1
#2 lore raw
Quoted 7 lines · Eric Wong
Quoted 6 lines · Deskin Miller

The 'branch' subcommand incorrectly had the svn-remote to use hardcoded as 'svn', the default remote name. This meant that branches derived from other svn-remotes would try to use the branch and tag configuration for the 'svn' remote, potentially copying would-be branches to the wrong place in SVN, into the branch namespace for another project.

Quoted 8 lines
Quoted 4 lines

Fix this by using the remote name extracted from the svn info for the specified git ref. Add a testcase for this behaviour.

Looks alright to me, thanks Deskin.

Does not work for me X-<.

* expecting success:

        (svn co "$svnrepo" svn &&
        cd svn &&
        mkdir mirror &&
        svn add mirror &&
        svn copy trunk tags branches mirror/ &&
        svn ci -m "made mirror" ) &&
        rm -rf svn &&
        git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
        git svn fetch -R mirror &&
        git checkout mirror/trunk &&
        base=$(git rev-parse HEAD:) &&
        git svn branch -m "branch in mirror" d &&
        test $base = $(git rev-parse remotes/mirror/d:) &&
        test_must_fail git rev-parse remotes/d
A    svn/trunk
A    svn/trunk/foo
A    svn/branches
A    svn/branches/a
A    svn/branches/a/foo
A    svn/branches/b
A    svn/branches/b/foo
A    svn/tags
A    svn/tags/tag4
A    svn/tags/tag4/foo
A    svn/tags/tag1
A    svn/tags/tag1/foo
A    svn/tags/tag2
A    svn/tags/tag2/foo
A    svn/tags/tag3
A    svn/tags/tag3/foo

Checked out revision 8.
A mirror
svn: Client error in parsing arguments
* FAIL 4: branch uses correct svn-remote

                (svn co "$svnrepo" svn &&
                cd svn &&
                mkdir mirror &&
                svn add mirror &&
                svn copy trunk tags branches mirror/ &&
                svn ci -m "made mirror" ) &&
                rm -rf svn &&
                git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
                git svn fetch -R mirror &&
                git checkout mirror/trunk &&
                base=$(git rev-parse HEAD:) &&
                git svn branch -m "branch in mirror" d &&
                test $base = $(git rev-parse remotes/mirror/d:) &&
                test_must_fail git rev-parse remotes/d
#3 lore raw

PATCH 1/1 Make t9128-git-svn-cmd-branch pass with svn 1.4

The copy command in svn 1.4 allows only one source (svn copy A D), whereas the copy command in svn 1.5 allows multiple sources (svn copy A B C D). This patch rewrites t9128 to use the backwards compatible form.

---
 t/t9128-git-svn-cmd-branch.sh |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
t/t9128-git-svn-cmd-branch.sh +3 -1
index e2b6696..252daa7 100755
@@ -61,7 +61,9 @@ test_expect_success 'branch uses correct svn-remote' '
 	cd svn &&
 	mkdir mirror &&
 	svn add mirror &&
-	svn copy trunk tags branches mirror/ &&
+	svn copy trunk mirror/ &&
+	svn copy tags mirror/ &&
+	svn copy branches mirror/ &&
 	svn ci -m "made mirror" ) &&
 	rm -rf svn &&
 	git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
Signature · 1 line
1.6.1.rc1
#4 lore raw
In reply to Junio C Hamano

Junio C Hamano venit, vidit, dixit 03.12.2008 04:55:

Quoted 56 lines
Quoted 7 lines · Eric Wong
Quoted 6 lines · Deskin Miller

The 'branch' subcommand incorrectly had the svn-remote to use hardcoded as 'svn', the default remote name. This meant that branches derived from other svn-remotes would try to use the branch and tag configuration for the 'svn' remote, potentially copying would-be branches to the wrong place in SVN, into the branch namespace for another project.

Quoted 7 lines
Quoted 4 lines

Fix this by using the remote name extracted from the svn info for the specified git ref. Add a testcase for this behaviour.

Looks alright to me, thanks Deskin.

Does not work for me X-<.

* expecting success:

        (svn co "$svnrepo" svn &&
        cd svn &&
        mkdir mirror &&
        svn add mirror &&
        svn copy trunk tags branches mirror/ &&
        svn ci -m "made mirror" ) &&
        rm -rf svn &&
        git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
        git svn fetch -R mirror &&
        git checkout mirror/trunk &&
        base=$(git rev-parse HEAD:) &&
        git svn branch -m "branch in mirror" d &&
        test $base = $(git rev-parse remotes/mirror/d:) &&
        test_must_fail git rev-parse remotes/d
A    svn/trunk
A    svn/trunk/foo
A    svn/branches
A    svn/branches/a
A    svn/branches/a/foo
A    svn/branches/b
A    svn/branches/b/foo
A    svn/tags
A    svn/tags/tag4
A    svn/tags/tag4/foo
A    svn/tags/tag1
A    svn/tags/tag1/foo
A    svn/tags/tag2
A    svn/tags/tag2/foo
A    svn/tags/tag3
A    svn/tags/tag3/foo

Checked out revision 8.
A mirror
svn: Client error in parsing arguments
* FAIL 4: branch uses correct svn-remote

Quoted 5 lines
                (svn co "$svnrepo" svn &&
                cd svn &&
                mkdir mirror &&
                svn add mirror &&
                svn copy trunk tags branches mirror/ &&

With my svn (1.4.6) it fails already here: "svn copy" allows two arguments only. That may be different in svn 1.5.

Quoted 9 lines
                svn ci -m "made mirror" ) &&
                rm -rf svn &&
                git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror &&
                git svn fetch -R mirror &&
                git checkout mirror/trunk &&
                base=$(git rev-parse HEAD:) &&
                git svn branch -m "branch in mirror" d &&
                test $base = $(git rev-parse remotes/mirror/d:) &&
                test_must_fail git rev-parse remotes/d

If I split the above copy into three lines then the test passes (svn 1.4.6, Deskin's patch applied onto 1.6.1-rc1 with the fix.

Patch coming. (Sorry I always forget the ccs with send-email.)

Michael

#5 lore raw
Quoted 1 line · Michael J Gruber

Patch coming. (Sorry I always forget the ccs with send-email.)

Thanks, indeed my environment has svn 1.4.2 installed and Deskin's patch with your patch squashed in makes everything happy again.

#6 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 1 line · Michael J Gruber

Patch coming. (Sorry I always forget the ccs with send-email.)

Thanks, indeed my environment has svn 1.4.2 installed and Deskin's patch with your patch squashed in makes everything happy again.

Ah, curse my trusting svn to work the same between versions, and not testing on 1.4. Thanks for the quick fix, Michael.

Deskin Miller

#7 lore raw
In reply to Michael J Gruber
Quoted 6 lines · Michael J Gruber

Junio C Hamano venit, vidit, dixit 03.12.2008 04:55:

Quoted 2 lines
Quoted 1 line · Eric Wong

Deskin Miller <[email protected]> wrote:

If I split the above copy into three lines then the test passes (svn 1.4.6, Deskin's patch applied onto 1.6.1-rc1 with the fix.

Thank you all for the testing and fixes.

Signature · 1 line
Eric Wong