Skip to content

Commit a7206ba

Browse files
committed
Merge branch 'svn-glob' of git://bogomips.org/git-svn
* 'svn-glob' of git://bogomips.org/git-svn: git-svn: shorten glob error message git-svn: loosen config globs limitations
2 parents e7c1132 + 62335bb commit a7206ba

File tree

5 files changed

+258
-13
lines changed

5 files changed

+258
-13
lines changed

Documentation/git-svn.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ listed below are allowed:
10341034
url = http://server.org/svn
10351035
fetch = trunk/project-a:refs/remotes/project-a/trunk
10361036
branches = branches/*/project-a:refs/remotes/project-a/branches/*
1037+
branches = branches/release_*:refs/remotes/project-a/branches/release_*
1038+
branches = branches/re*se:refs/remotes/project-a/branches/*
10371039
tags = tags/*/project-a:refs/remotes/project-a/tags/*
10381040
------------------------------------------------------------------------
10391041

@@ -1044,6 +1046,16 @@ independent path component (surrounded by '/' or EOL). This
10441046
type of configuration is not automatically created by 'init' and
10451047
should be manually entered with a text-editor or using 'git config'.
10461048

1049+
Also note that only one asterisk is allowed per word. For example:
1050+
1051+
branches = branches/re*se:refs/remotes/project-a/branches/*
1052+
1053+
will match branches 'release', 'rese', 're123se', however
1054+
1055+
branches = branches/re*s*e:refs/remotes/project-a/branches/*
1056+
1057+
will produce an error.
1058+
10471059
It is also possible to fetch a subset of branches or tags by using a
10481060
comma-separated list of names within braces. For example:
10491061

perl/Git/SVN/GlobSpec.pm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ sub new {
88
$re =~ s!/+$!!g; # no need for trailing slashes
99
my (@left, @right, @patterns);
1010
my $state = "left";
11-
my $die_msg = "Only one set of wildcard directories " .
12-
"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
11+
my $die_msg = "Only one set of wildcards " .
12+
"(e.g. '*' or '*/*/*') is supported: $glob\n";
1313
for my $part (split(m|/|, $glob)) {
14-
if ($part =~ /\*/ && $part ne "*") {
15-
die "Invalid pattern in '$glob': $part\n";
16-
} elsif ($pattern_ok && $part =~ /[{}]/ &&
14+
if ($pattern_ok && $part =~ /[{}]/ &&
1715
$part !~ /^\{[^{}]+\}/) {
1816
die "Invalid pattern in '$glob': $part\n";
1917
}
20-
if ($part eq "*") {
18+
my $nstars = $part =~ tr/*//;
19+
if ($nstars > 1) {
20+
die "Only one '*' is allowed in a pattern: '$part'\n";
21+
}
22+
if ($part =~ /(.*)\*(.*)/) {
2123
die $die_msg if $state eq "right";
24+
my ($l, $r) = ($1, $2);
2225
$state = "pattern";
23-
push(@patterns, "[^/]*");
26+
my $pat = quotemeta($l) . '[^/]*' . quotemeta($r);
27+
push(@patterns, $pat);
2428
} elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
2529
die $die_msg if $state eq "right";
2630
$state = "pattern";

t/t9108-git-svn-glob.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ test_expect_success 'test left-hand-side only globbing' '
8686
test_cmp expect.two output.two
8787
'
8888

89-
echo "Only one set of wildcard directories" \
90-
"(e.g. '*' or '*/*/*') is supported: 'branches/*/t/*'" > expect.three
91-
echo "" >> expect.three
89+
test_expect_success 'prepare test disallow multi-globs' "
90+
cat >expect.three <<EOF
91+
Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/*/t/*
92+
93+
EOF
94+
"
9295

9396
test_expect_success 'test disallow multi-globs' '
9497
git config --add svn-remote.three.url "$svnrepo" &&

t/t9109-git-svn-multi-glob.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ test_expect_success 'test another branch' '
135135
test_cmp expect.four output.four
136136
'
137137

138-
echo "Only one set of wildcard directories" \
139-
"(e.g. '*' or '*/*/*') is supported: 'branches/*/t/*'" > expect.three
140-
echo "" >> expect.three
138+
test_expect_success 'prepare test disallow multiple globs' "
139+
cat >expect.three <<EOF
140+
Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/*/t/*
141+
142+
EOF
143+
"
141144

142145
test_expect_success 'test disallow multiple globs' '
143146
git config --add svn-remote.three.url "$svnrepo" &&
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
#!/bin/sh
2+
test_description='git svn globbing refspecs with prefixed globs'
3+
. ./lib-git-svn.sh
4+
5+
test_expect_success 'prepare test refspec prefixed globbing' '
6+
cat >expect.end <<EOF
7+
the end
8+
hi
9+
start a new branch
10+
initial
11+
EOF
12+
'
13+
14+
test_expect_success 'test refspec prefixed globbing' '
15+
mkdir -p trunk/src/a trunk/src/b trunk/doc &&
16+
echo "hello world" >trunk/src/a/readme &&
17+
echo "goodbye world" >trunk/src/b/readme &&
18+
svn_cmd import -m "initial" trunk "$svnrepo"/trunk &&
19+
svn_cmd co "$svnrepo" tmp &&
20+
(
21+
cd tmp &&
22+
mkdir branches tags &&
23+
svn_cmd add branches tags &&
24+
svn_cmd cp trunk branches/b_start &&
25+
svn_cmd commit -m "start a new branch" &&
26+
svn_cmd up &&
27+
echo "hi" >>branches/b_start/src/b/readme &&
28+
poke branches/b_start/src/b/readme &&
29+
echo "hey" >>branches/b_start/src/a/readme &&
30+
poke branches/b_start/src/a/readme &&
31+
svn_cmd commit -m "hi" &&
32+
svn_cmd up &&
33+
svn_cmd cp branches/b_start tags/t_end &&
34+
echo "bye" >>tags/t_end/src/b/readme &&
35+
poke tags/t_end/src/b/readme &&
36+
echo "aye" >>tags/t_end/src/a/readme &&
37+
poke tags/t_end/src/a/readme &&
38+
svn_cmd commit -m "the end" &&
39+
echo "byebye" >>tags/t_end/src/b/readme &&
40+
poke tags/t_end/src/b/readme &&
41+
svn_cmd commit -m "nothing to see here"
42+
) &&
43+
git config --add svn-remote.svn.url "$svnrepo" &&
44+
git config --add svn-remote.svn.fetch \
45+
"trunk/src/a:refs/remotes/trunk" &&
46+
git config --add svn-remote.svn.branches \
47+
"branches/b_*/src/a:refs/remotes/branches/b_*" &&
48+
git config --add svn-remote.svn.tags\
49+
"tags/t_*/src/a:refs/remotes/tags/t_*" &&
50+
git svn multi-fetch &&
51+
git log --pretty=oneline refs/remotes/tags/t_end | \
52+
sed -e "s/^.\{41\}//" >output.end &&
53+
test_cmp expect.end output.end &&
54+
test "$(git rev-parse refs/remotes/tags/t_end~1)" = \
55+
"$(git rev-parse refs/remotes/branches/b_start)" &&
56+
test "$(git rev-parse refs/remotes/branches/b_start~2)" = \
57+
"$(git rev-parse refs/remotes/trunk)" &&
58+
test_must_fail git rev-parse refs/remotes/tags/t_end@3
59+
'
60+
61+
test_expect_success 'prepare test left-hand-side only prefixed globbing' '
62+
echo try to try >expect.two &&
63+
echo nothing to see here >>expect.two &&
64+
cat expect.end >>expect.two
65+
'
66+
67+
test_expect_success 'test left-hand-side only prefixed globbing' '
68+
git config --add svn-remote.two.url "$svnrepo" &&
69+
git config --add svn-remote.two.fetch trunk:refs/remotes/two/trunk &&
70+
git config --add svn-remote.two.branches \
71+
"branches/b_*:refs/remotes/two/branches/*" &&
72+
git config --add svn-remote.two.tags \
73+
"tags/t_*:refs/remotes/two/tags/*" &&
74+
(
75+
cd tmp &&
76+
echo "try try" >>tags/t_end/src/b/readme &&
77+
poke tags/t_end/src/b/readme &&
78+
svn_cmd commit -m "try to try"
79+
) &&
80+
git svn fetch two &&
81+
test $(git rev-list refs/remotes/two/tags/t_end | wc -l) -eq 6 &&
82+
test $(git rev-list refs/remotes/two/branches/b_start | wc -l) -eq 3 &&
83+
test $(git rev-parse refs/remotes/two/branches/b_start~2) = \
84+
$(git rev-parse refs/remotes/two/trunk) &&
85+
test $(git rev-parse refs/remotes/two/tags/t_end~3) = \
86+
$(git rev-parse refs/remotes/two/branches/b_start) &&
87+
git log --pretty=oneline refs/remotes/two/tags/t_end | \
88+
sed -e "s/^.\{41\}//" >output.two &&
89+
test_cmp expect.two output.two
90+
'
91+
92+
test_expect_success 'prepare test prefixed globs match just prefix' '
93+
cat >expect.three <<EOF
94+
Tag commit to t_
95+
Branch commit to b_
96+
initial
97+
EOF
98+
'
99+
100+
test_expect_success 'test prefixed globs match just prefix' '
101+
git config --add svn-remote.three.url "$svnrepo" &&
102+
git config --add svn-remote.three.fetch \
103+
trunk:refs/remotes/three/trunk &&
104+
git config --add svn-remote.three.branches \
105+
"branches/b_*:refs/remotes/three/branches/*" &&
106+
git config --add svn-remote.three.tags \
107+
"tags/t_*:refs/remotes/three/tags/*" &&
108+
(
109+
cd tmp &&
110+
svn_cmd cp trunk branches/b_ &&
111+
echo "Branch commit to b_" >>branches/b_/src/a/readme &&
112+
poke branches/b_/src/a/readme &&
113+
svn_cmd commit -m "Branch commit to b_" &&
114+
svn_cmd up && svn_cmd cp branches/b_ tags/t_ &&
115+
echo "Tag commit to t_" >>tags/t_/src/a/readme &&
116+
poke tags/t_/src/a/readme &&
117+
svn_cmd commit -m "Tag commit to t_" &&
118+
svn_cmd up
119+
) &&
120+
git svn fetch three &&
121+
test $(git rev-list refs/remotes/three/branches/b_ | wc -l) -eq 2 &&
122+
test $(git rev-list refs/remotes/three/tags/t_ | wc -l) -eq 3 &&
123+
test $(git rev-parse refs/remotes/three/branches/b_~1) = \
124+
$(git rev-parse refs/remotes/three/trunk) &&
125+
test $(git rev-parse refs/remotes/three/tags/t_~1) = \
126+
$(git rev-parse refs/remotes/three/branches/b_) &&
127+
git log --pretty=oneline refs/remotes/three/tags/t_ | \
128+
sed -e "s/^.\{41\}//" >output.three &&
129+
test_cmp expect.three output.three
130+
'
131+
132+
test_expect_success 'prepare test disallow prefixed multi-globs' "
133+
cat >expect.four <<EOF
134+
Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/b_*/t/*
135+
136+
EOF
137+
"
138+
139+
test_expect_success 'test disallow prefixed multi-globs' '
140+
git config --add svn-remote.four.url "$svnrepo" &&
141+
git config --add svn-remote.four.fetch \
142+
trunk:refs/remotes/four/trunk &&
143+
git config --add svn-remote.four.branches \
144+
"branches/b_*/t/*:refs/remotes/four/branches/*" &&
145+
git config --add svn-remote.four.tags \
146+
"tags/t_*/*:refs/remotes/four/tags/*" &&
147+
(
148+
cd tmp &&
149+
echo "try try" >>tags/t_end/src/b/readme &&
150+
poke tags/t_end/src/b/readme &&
151+
svn_cmd commit -m "try to try"
152+
) &&
153+
test_must_fail git svn fetch four 2>stderr.four &&
154+
test_cmp expect.four stderr.four &&
155+
git config --unset svn-remote.four.branches &&
156+
git config --unset svn-remote.four.tags
157+
'
158+
159+
test_expect_success 'prepare test globbing in the middle of the word' '
160+
cat >expect.five <<EOF
161+
Tag commit to fghij
162+
Branch commit to abcde
163+
initial
164+
EOF
165+
'
166+
167+
test_expect_success 'test globbing in the middle of the word' '
168+
git config --add svn-remote.five.url "$svnrepo" &&
169+
git config --add svn-remote.five.fetch \
170+
trunk:refs/remotes/five/trunk &&
171+
git config --add svn-remote.five.branches \
172+
"branches/a*e:refs/remotes/five/branches/*" &&
173+
git config --add svn-remote.five.tags \
174+
"tags/f*j:refs/remotes/five/tags/*" &&
175+
(
176+
cd tmp &&
177+
svn_cmd cp trunk branches/abcde &&
178+
echo "Branch commit to abcde" >>branches/abcde/src/a/readme &&
179+
poke branches/b_/src/a/readme &&
180+
svn_cmd commit -m "Branch commit to abcde" &&
181+
svn_cmd up &&
182+
svn_cmd cp branches/abcde tags/fghij &&
183+
echo "Tag commit to fghij" >>tags/fghij/src/a/readme &&
184+
poke tags/fghij/src/a/readme &&
185+
svn_cmd commit -m "Tag commit to fghij" &&
186+
svn_cmd up
187+
) &&
188+
git svn fetch five &&
189+
test $(git rev-list refs/remotes/five/branches/abcde | wc -l) -eq 2 &&
190+
test $(git rev-list refs/remotes/five/tags/fghij | wc -l) -eq 3 &&
191+
test $(git rev-parse refs/remotes/five/branches/abcde~1) = \
192+
$(git rev-parse refs/remotes/five/trunk) &&
193+
test $(git rev-parse refs/remotes/five/tags/fghij~1) = \
194+
$(git rev-parse refs/remotes/five/branches/abcde) &&
195+
git log --pretty=oneline refs/remotes/five/tags/fghij | \
196+
sed -e "s/^.\{41\}//" >output.five &&
197+
test_cmp expect.five output.five
198+
'
199+
200+
test_expect_success 'prepare test disallow multiple asterisks in one word' "
201+
echo \"Only one '*' is allowed in a pattern: 'a*c*e'\" >expect.six &&
202+
echo \"\" >>expect.six
203+
"
204+
205+
test_expect_success 'test disallow multiple asterisks in one word' '
206+
git config --add svn-remote.six.url "$svnrepo" &&
207+
git config --add svn-remote.six.fetch \
208+
trunk:refs/remotes/six/trunk &&
209+
git config --add svn-remote.six.branches \
210+
"branches/a*c*e:refs/remotes/six/branches/*" &&
211+
git config --add svn-remote.six.tags \
212+
"tags/f*h*j:refs/remotes/six/tags/*" &&
213+
(
214+
cd tmp &&
215+
echo "try try" >>tags/fghij/src/b/readme &&
216+
poke tags/fghij/src/b/readme &&
217+
svn_cmd commit -m "try to try"
218+
) &&
219+
test_must_fail git svn fetch six 2>stderr.six &&
220+
test_cmp expect.six stderr.six
221+
'
222+
223+
test_done

0 commit comments

Comments
 (0)