git-svn: loosen config globs limitations
Expand the area of globs applicability for branches and tags in git-svn. It is now possible to use globs like 'a*e', or 'release_*'. This allows users to avoid long lines in config like: branches = branches/{release_20,release_21,release_22,...} In favor of: branches = branches/release_* [ew: amended commit message, minor formatting and style fixes] Signed-off-by: Victor Leschuk <vleschuk@accesssoftek.com> Signed-off-by: Eric Wong <normalperson@yhbt.net>
Victor Leschuk committed
Jan 11, 2016 at 17:25 UTC
e4e5dd94e6eea4b50d8baed8b6b8cc50f6c8eae4
3 files changed
+243
-5
Documentation/git-svn.txt
+12
@@ -1034,6 +1034,8 @@ listed below are allowed:
1034
url = http://server.org/svn
1035
fetch = trunk/project-a:refs/remotes/project-a/trunk
1036
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/*
1039
tags = tags/*/project-a:refs/remotes/project-a/tags/*
1040
------------------------------------------------------------------------
1041
@@ -1044,6 +1046,16 @@ independent path component (surrounded by '/' or EOL). This
1046
type of configuration is not automatically created by 'init' and
1047
should be manually entered with a text-editor or using 'git config'.
1048
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
+
1059
It is also possible to fetch a subset of branches or tags by using a
1060
comma-separated list of names within braces. For example:
1061
perl/Git/SVN/GlobSpec.pm
+9
-5
@@ -11,16 +11,20 @@ sub new {
11
my $die_msg = "Only one set of wildcard directories " .
12
"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
13
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 =~ /[{}]/ &&
15
$part !~ /^\{[^{}]+\}/) {
16
die "Invalid pattern in '$glob': $part\n";
17
}
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 =~ /(.*)\*(.*)/) {
23
die $die_msg if $state eq "right";
24
+ my ($l, $r) = ($1, $2);
25
$state = "pattern";
23
- push(@patterns, "[^/]*");
26
+ my $pat = quotemeta($l) . '[^/]*' . quotemeta($r);
27
+ push(@patterns, $pat);
28
} elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
29
die $die_msg if $state eq "right";
30
$state = "pattern";
t/t9168-git-svn-partially-globbed-names.sh
new
+222
@@ -0,0 +1,222 @@
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
+ echo \"Only one set of wildcard directories\" \
134
+ \"(e.g. '*' or '*/*/*') is supported: 'branches/b_*/t/*'\" >expect.four &&
135
+ echo \"\" >>expect.four
136
+ "
137
+
138
+test_expect_success 'test disallow prefixed multi-globs' '
139
+ git config --add svn-remote.four.url "$svnrepo" &&
140
+ git config --add svn-remote.four.fetch \
141
+ trunk:refs/remotes/four/trunk &&
142
+ git config --add svn-remote.four.branches \
143
+ "branches/b_*/t/*:refs/remotes/four/branches/*" &&
144
+ git config --add svn-remote.four.tags \
145
+ "tags/t_*/*:refs/remotes/four/tags/*" &&
146
+ (
147
+ cd tmp &&
148
+ echo "try try" >>tags/t_end/src/b/readme &&
149
+ poke tags/t_end/src/b/readme &&
150
+ svn_cmd commit -m "try to try"
151
+ ) &&
152
+ test_must_fail git svn fetch four 2>stderr.four &&
153
+ test_cmp expect.four stderr.four &&
154
+ git config --unset svn-remote.four.branches &&
155
+ git config --unset svn-remote.four.tags
156
+ '
157
+
158
+test_expect_success 'prepare test globbing in the middle of the word' '
159
+ cat >expect.five <<EOF
160
+Tag commit to fghij
161
+Branch commit to abcde
162
+initial
163
+EOF
164
+ '
165
+
166
+test_expect_success 'test globbing in the middle of the word' '
167
+ git config --add svn-remote.five.url "$svnrepo" &&
168
+ git config --add svn-remote.five.fetch \
169
+ trunk:refs/remotes/five/trunk &&
170
+ git config --add svn-remote.five.branches \
171
+ "branches/a*e:refs/remotes/five/branches/*" &&
172
+ git config --add svn-remote.five.tags \
173
+ "tags/f*j:refs/remotes/five/tags/*" &&
174
+ (
175
+ cd tmp &&
176
+ svn_cmd cp trunk branches/abcde &&
177
+ echo "Branch commit to abcde" >>branches/abcde/src/a/readme &&
178
+ poke branches/b_/src/a/readme &&
179
+ svn_cmd commit -m "Branch commit to abcde" &&
180
+ svn_cmd up &&
181
+ svn_cmd cp branches/abcde tags/fghij &&
182
+ echo "Tag commit to fghij" >>tags/fghij/src/a/readme &&
183
+ poke tags/fghij/src/a/readme &&
184
+ svn_cmd commit -m "Tag commit to fghij" &&
185
+ svn_cmd up
186
+ ) &&
187
+ git svn fetch five &&
188
+ test $(git rev-list refs/remotes/five/branches/abcde | wc -l) -eq 2 &&
189
+ test $(git rev-list refs/remotes/five/tags/fghij | wc -l) -eq 3 &&
190
+ test $(git rev-parse refs/remotes/five/branches/abcde~1) = \
191
+ $(git rev-parse refs/remotes/five/trunk) &&
192
+ test $(git rev-parse refs/remotes/five/tags/fghij~1) = \
193
+ $(git rev-parse refs/remotes/five/branches/abcde) &&
194
+ git log --pretty=oneline refs/remotes/five/tags/fghij | \
195
+ sed -e "s/^.\{41\}//" >output.five &&
196
+ test_cmp expect.five output.five
197
+ '
198
+
199
+test_expect_success 'prepare test disallow multiple asterisks in one word' "
200
+ echo \"Only one '*' is allowed in a pattern: 'a*c*e'\" >expect.six &&
201
+ echo \"\" >>expect.six
202
+ "
203
+
204
+test_expect_success 'test disallow multiple asterisks in one word' '
205
+ git config --add svn-remote.six.url "$svnrepo" &&
206
+ git config --add svn-remote.six.fetch \
207
+ trunk:refs/remotes/six/trunk &&
208
+ git config --add svn-remote.six.branches \
209
+ "branches/a*c*e:refs/remotes/six/branches/*" &&
210
+ git config --add svn-remote.six.tags \
211
+ "tags/f*h*j:refs/remotes/six/tags/*" &&
212
+ (
213
+ cd tmp &&
214
+ echo "try try" >>tags/fghij/src/b/readme &&
215
+ poke tags/fghij/src/b/readme &&
216
+ svn_cmd commit -m "try to try"
217
+ ) &&
218
+ test_must_fail git svn fetch six 2>stderr.six &&
219
+ test_cmp expect.six stderr.six
220
+ '
221
+
222
+test_done