@@ -28,6 +28,18 @@ class MigrateCommand extends Command {
28
28
29
29
const OPT_REMOTE = 'remote ' ;
30
30
31
+ const OPT_STDLAYOUT = 'stdlayout ' ;
32
+ const OPT_STDLAYOUT_S = 's ' ;
33
+
34
+ const OPT_TRUNK = 'trunk ' ;
35
+ const OPT_TRUNK_S = 'T ' ;
36
+
37
+ const OPT_BRANCHES = 'branches ' ;
38
+ const OPT_BRANCHES_S = 'b ' ;
39
+
40
+ const OPT_TAGS = 'tags ' ;
41
+ const OPT_TAGS_S = 't ' ;
42
+
31
43
const OPT_AUTHORS_FILE = 'authors-file ' ;
32
44
const OPT_AUTHORS_FILE_S = 'A ' ;
33
45
@@ -51,6 +63,10 @@ class MigrateCommand extends Command {
51
63
* @var string
52
64
*/
53
65
private $ gitsvn ;
66
+ /**
67
+ * @var QuestionHelper
68
+ */
69
+ private $ question ;
54
70
/**
55
71
* Path to authors mapping file.
56
72
* @var string
@@ -61,20 +77,36 @@ class MigrateCommand extends Command {
61
77
* @var string
62
78
*/
63
79
private $ remote ;
80
+
64
81
/**
65
- * @var QuestionHelper
82
+ * @var boolean
66
83
*/
67
- private $ question ;
84
+ private $ stdlayout ;
68
85
/**
69
- * Filename for placeholder file used to preserve empty subversion directories .
86
+ * Relative repository path or full url pointing to the trunk of the repository .
70
87
* @var string
71
88
*/
72
- private $ placeholderFileName ;
89
+ private $ trunk ;
90
+ /**
91
+ * Relative repository path or full url pointing to the branches of the repository.
92
+ * @var string
93
+ */
94
+ private $ branches ;
95
+ /**
96
+ * Relative repository path or full url pointing to the tags of the repository.
97
+ * @var string
98
+ */
99
+ private $ tags ;
73
100
/**
74
101
* Whether to preserve empty directories retrieved from subversion.
75
102
* @var boolean
76
103
*/
77
104
private $ preserveEmpty ;
105
+ /**
106
+ * Filename for placeholder file used to preserve empty subversion directories.
107
+ * @var string
108
+ */
109
+ private $ placeholderFileName ;
78
110
79
111
/**
80
112
* @inheritdoc
@@ -106,6 +138,46 @@ protected function configure() {
106
138
'URL of Git remote repository to push to. '
107
139
);
108
140
141
+ $ this ->addOption (
142
+ self ::OPT_STDLAYOUT ,
143
+ self ::OPT_STDLAYOUT_S ,
144
+ InputOption::VALUE_NONE ,
145
+ <<<DESC
146
+ The option --stdlayout is a shorthand way of setting trunk,tags,branches as the relative paths, which is the Subversion default.
147
+ If any of the other options are given as well, they take precedence.
148
+ DESC
149
+ );
150
+
151
+ $ this ->addOption (
152
+ self ::OPT_TRUNK ,
153
+ self ::OPT_TRUNK_S ,
154
+ InputOption::VALUE_REQUIRED ,
155
+ <<<DESC
156
+ Relative repository path or full url pointing to the trunk of the repository.
157
+ Takes precedence over the --stdlayout option.
158
+ DESC
159
+ );
160
+
161
+ $ this ->addOption (
162
+ self ::OPT_BRANCHES ,
163
+ self ::OPT_BRANCHES_S ,
164
+ InputOption::VALUE_REQUIRED ,
165
+ <<<DESC
166
+ Relative repository path or full url pointing to the branches of the repository.
167
+ Takes precedence over the --stdlayout option.
168
+ DESC
169
+ );
170
+
171
+ $ this ->addOption (
172
+ self ::OPT_TAGS ,
173
+ self ::OPT_TAGS_S ,
174
+ InputOption::VALUE_REQUIRED ,
175
+ <<<DESC
176
+ Relative repository path or full url pointing to the tags of the repository.
177
+ Takes precedence over the --stdlayout option.
178
+ DESC
179
+ );
180
+
109
181
$ this ->addOption (
110
182
self ::OPT_PRESERVE_EMPTY ,
111
183
null ,
@@ -145,6 +217,22 @@ protected function initialize(InputInterface $input, OutputInterface $output) {
145
217
$ this ->remote = $ input ->getOption (self ::OPT_REMOTE );
146
218
}
147
219
220
+ if ($ input ->hasOption (self ::OPT_STDLAYOUT )) {
221
+ $ this ->stdlayout = $ input ->getOption (self ::OPT_STDLAYOUT );
222
+ }
223
+
224
+ if ($ input ->hasOption (self ::OPT_TRUNK )) {
225
+ $ this ->trunk = $ input ->getOption (self ::OPT_TRUNK );
226
+ }
227
+
228
+ if ($ input ->hasOption (self ::OPT_BRANCHES )) {
229
+ $ this ->branches = $ input ->getOption (self ::OPT_BRANCHES );
230
+ }
231
+
232
+ if ($ input ->hasOption (self ::OPT_TAGS )) {
233
+ $ this ->tags = $ input ->getOption (self ::OPT_TAGS );
234
+ }
235
+
148
236
if ($ input ->hasOption (self ::OPT_PRESERVE_EMPTY )) {
149
237
$ this ->preserveEmpty = $ input ->getOption (self ::OPT_PRESERVE_EMPTY );
150
238
$ this ->placeholderFileName = $ input ->getOption (self ::OPT_PLACEHOLDER_FILE );
@@ -173,6 +261,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
173
261
$ this ->log ('REMOTE: ' . $ this ->remote );
174
262
}
175
263
264
+ if ($ this ->stdlayout ) {
265
+ $ this ->log ('USING STANDARD LAYOUT ' );
266
+ }
267
+
176
268
if ($ this ->preserveEmpty ) {
177
269
$ this ->log ('PRESERVE EMPTY DIRS WITH: ' . $ this ->placeholderFileName );
178
270
}
@@ -194,15 +286,23 @@ protected function execute(InputInterface $input, OutputInterface $output) {
194
286
$ createBranchesQ = new ConfirmationQuestion ('Migrate branches? ' , true );
195
287
196
288
if ($ this ->question ->ask ($ input , $ output , $ createBranchesQ )) {
197
- $ branches = $ this ->getSubversionBranches ($ this ->gitsvn );
198
- $ this ->createBranches ($ branches , $ this ->gitsvn );
289
+ try {
290
+ $ branches = $ this ->getSubversionBranches ($ this ->gitsvn );
291
+ $ this ->createBranches ($ branches , $ this ->gitsvn );
292
+ } catch (\RuntimeException $ e ) {
293
+ $ this ->comment ('Unable to migrate branches. Does the repository even have any?: ' . $ e ->getMessage ());
294
+ }
199
295
}
200
296
201
297
$ createTagsQ = new ConfirmationQuestion ('Migrate tags? ' , true );
202
298
203
299
if ($ this ->question ->ask ($ input , $ output , $ createTagsQ )) {
204
- $ tags = $ this ->getSubversionTags ($ this ->gitsvn );
205
- $ this ->createAnnotatedTags ($ tags , $ this ->gitsvn );
300
+ try {
301
+ $ tags = $ this ->getSubversionTags ($ this ->gitsvn );
302
+ $ this ->createAnnotatedTags ($ tags , $ this ->gitsvn );
303
+ } catch (\RuntimeException $ e ) {
304
+ $ this ->comment ('Unable to migrate tags. Does the repository even have any?: ' . $ e ->getMessage ());
305
+ }
206
306
}
207
307
208
308
if (isset ($ this ->remote )) {
@@ -233,14 +333,29 @@ private function cloneSubversionRepository($source, $destination, $authorsFile =
233
333
'git svn clone ' ,
234
334
$ source ,
235
335
'--prefix=svn/ ' ,
236
- '--stdlayout ' ,
237
336
'--quiet '
238
337
];
239
338
240
339
if (isset ($ authorsFile )) {
241
340
$ cmdSeg [] = '-A ' . $ authorsFile ;
242
341
}
243
342
343
+ if (!empty ($ this ->trunk )) {
344
+ $ cmdSeg [] = '--trunk= ' . $ this ->trunk ;
345
+ }
346
+
347
+ if (!empty ($ this ->branches )) {
348
+ $ cmdSeg [] = '--branches= ' . $ this ->branches ;
349
+ }
350
+
351
+ if (!empty ($ this ->tags )) {
352
+ $ cmdSeg [] = '--tags= ' . $ this ->tags ;
353
+ }
354
+
355
+ if ($ this ->stdlayout ) {
356
+ $ cmdSeg [] = '--stdlayout ' ;
357
+ }
358
+
244
359
if ($ this ->preserveEmpty ) {
245
360
$ cmdSeg [] = '--preserve-empty-dirs ' ;
246
361
$ cmdSeg [] = '--placeholder-filename= ' . $ this ->placeholderFileName ;
0 commit comments