@matheusbsbs / matheus-bagliano / commits / b47ddefe02
Fork 0

Fix multi-glob assertion in git-svn

Fixes bad regex match check for multiple globs (would always return one glob regardless of actual number). [ew: fixed a bashism in the test and some minor line-wrapping] Signed-off-by: Marcus Griep <marcus@griep.us> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Marcus Griep committed Aug 8, 2008 at 01:41 UTC b47ddefe02945f8746c642219450245cf83ed130
2 files changed +33 -8
git-svn.perl
+3 -2
@@ -4915,14 +4915,15 @@ sub new {
4915 my ($class, $glob) = @_;
4916 my $re = $glob;
4917 $re =~ s!/+$!!g; # no need for trailing slashes
4918 - my $nr = ($re =~ s!^(.*)\*(.*)$!\(\[^/\]+\)!g);
4919 - my ($left, $right) = ($1, $2);
4918 + my $nr = $re =~ tr/*/*/;
4919 if ($nr > 1) {
4920 die "Only one '*' wildcard expansion ",
4921 "is supported (got $nr): '$glob'\n";
4922 } elsif ($nr == 0) {
4923 die "One '*' is needed for glob: '$glob'\n";
4924 }
4925 + $re =~ s!^(.*)\*(.*)$!\(\[^/\]+\)!g;
4926 + my ($left, $right) = ($1, $2);
4927 $re = quotemeta($left) . $re . quotemeta($right);
4928 if (length $left && !($left =~ s!/+$!!g)) {
4929 die "Missing trailing '/' on left side of: '$glob' ($left)\n";
t/t9108-git-svn-glob.sh
+30 -6
@@ -16,7 +16,8 @@ test_expect_success 'test refspec globbing' '
16 echo "goodbye world" > trunk/src/b/readme &&
17 svn import -m "initial" trunk "$svnrepo"/trunk &&
18 svn co "$svnrepo" tmp &&
19 - cd tmp &&
19 + (
20 + cd tmp &&
21 mkdir branches tags &&
22 svn add branches tags &&
23 svn cp trunk branches/start &&
@@ -37,7 +38,7 @@ test_expect_success 'test refspec globbing' '
38 echo "byebye" >> tags/end/src/b/readme &&
39 poke tags/end/src/b/readme &&
40 svn commit -m "nothing to see here"
40 - cd .. &&
41 + ) &&
42 git config --add svn-remote.svn.url "$svnrepo" &&
43 git config --add svn-remote.svn.fetch \
44 "trunk/src/a:refs/remotes/trunk" &&
@@ -48,7 +49,7 @@ test_expect_success 'test refspec globbing' '
49 git-svn multi-fetch &&
50 git log --pretty=oneline refs/remotes/tags/end | \
51 sed -e "s/^.\{41\}//" > output.end &&
51 - cmp expect.end output.end &&
52 + test_cmp expect.end output.end &&
53 test "`git rev-parse refs/remotes/tags/end~1`" = \
54 "`git rev-parse refs/remotes/branches/start`" &&
55 test "`git rev-parse refs/remotes/branches/start~2`" = \
@@ -66,11 +67,12 @@ test_expect_success 'test left-hand-side only globbing' '
67 "branches/*:refs/remotes/two/branches/*" &&
68 git config --add svn-remote.two.tags \
69 "tags/*:refs/remotes/two/tags/*" &&
69 - cd tmp &&
70 + (
71 + cd tmp &&
72 echo "try try" >> tags/end/src/b/readme &&
73 poke tags/end/src/b/readme &&
74 svn commit -m "try to try"
73 - cd .. &&
75 + ) &&
76 git-svn fetch two &&
77 test `git rev-list refs/remotes/two/tags/end | wc -l` -eq 6 &&
78 test `git rev-list refs/remotes/two/branches/start | wc -l` -eq 3 &&
@@ -80,7 +82,29 @@ test_expect_success 'test left-hand-side only globbing' '
82 `git rev-parse refs/remotes/two/branches/start` &&
83 git log --pretty=oneline refs/remotes/two/tags/end | \
84 sed -e "s/^.\{41\}//" > output.two &&
83 - cmp expect.two output.two
85 + test_cmp expect.two output.two
86 + '
87 +
88 +echo "Only one '*' wildcard expansion is supported (got 2): 'branches/*/*'" \
89 + > expect.three
90 +echo "" >> expect.three
91 +
92 +test_expect_success 'test disallow multi-globs' '
93 + git config --add svn-remote.three.url "$svnrepo" &&
94 + git config --add svn-remote.three.fetch \
95 + trunk:refs/remotes/three/trunk &&
96 + git config --add svn-remote.three.branches \
97 + "branches/*/*:refs/remotes/three/branches/*" &&
98 + git config --add svn-remote.three.tags \
99 + "tags/*/*:refs/remotes/three/tags/*" &&
100 + (
101 + cd tmp &&
102 + echo "try try" >> tags/end/src/b/readme &&
103 + poke tags/end/src/b/readme &&
104 + svn commit -m "try to try"
105 + ) &&
106 + test_must_fail git-svn fetch three 2> stderr.three &&
107 + test_cmp expect.three stderr.three
108 '
109
110 test_done