Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit d965faf

Browse files
committed
Merge branch 'configurable-repo-layout'
This branch brings in functionality to specify the layout to be migrated. It exposes the git-svn options -T<trunk_subdir>, --trunk=<trunk_subdir>, -t<tags_subdir>, --tags=<tags_subdir>, -b<branches_subdir>, --branches=<branches_subdir>, -s, --stdlayout and passes them to the command line accordingly. * configurable-repo-layout: update README.md with new options on migrate command better error messages Catch runtime RuntimeException when migrating branches or tags adjut error messages add layout options and pass them to git-svn
2 parents 3515425 + 235943a commit d965faf

File tree

3 files changed

+135
-12
lines changed

3 files changed

+135
-12
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ $ bin/svn2git migrate [-A|--authors-file="..."] [--remote="..."] source
9898
```
9999
--authors-file (-A) Path to Subversion authors mapping.
100100
--remote URL of Git remote repository to push to.
101+
--stdlayout (-s) The option --stdlayout is a shorthand way of setting trunk,tags,branches as the relative paths, which is the Subversion default.
102+
If any of the other options are given as well, they take precedence.
103+
--trunk (-T) Relative repository path or full url pointing to the trunk of the repository.
104+
Takes precedence over the --stdlayout option.
105+
--branches (-b) Relative repository path or full url pointing to the branches of the repository.
106+
Takes precedence over the --stdlayout option.
107+
--tags (-t) Relative repository path or full url pointing to the tags of the repository.
108+
Takes precedence over the --stdlayout option.
101109
--preserve-empty-dirs Create a placeholder file in the local Git repository for each empty directory fetched from Subversion.
102110
--placeholder-filename Set the name of placeholder files created by --preserve-empty-dirs. (default: ".gitkeep")
103111
--help (-h) Display this help message.
@@ -111,7 +119,7 @@ $ bin/svn2git migrate [-A|--authors-file="..."] [--remote="..."] source
111119

112120
**Example**
113121
```bash
114-
$ bin/svn2git migrate svn://example.com/svnrepo -A authors-transform.txt [email protected]:user/remoterepo.git
122+
$ bin/svn2git migrate svn://example.com/svnrepo -A authors-transform.txt [email protected]:user/remoterepo.git --stdlayout
115123
```
116124

117125
To update the master or any added branch / tag just execute the migrate command again.

src/Cli/Cli.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function execute($cmd, $ctx = null) {
7474
}
7575

7676
if ($this->trustExitCodes && $return != 0) {
77-
throw new \RuntimeException("Unable to execute '$cmd':" . implode("\n", $output), $return);
77+
throw new \RuntimeException("Error executing `$cmd` (returned $return): " . implode("\n", $output), $return);
7878
}
7979

8080
return $output;
@@ -100,7 +100,7 @@ public function passthru($cmd, $ctx = null) {
100100
}
101101

102102
if ($this->trustExitCodes && $return != 0) {
103-
throw new \RuntimeException("Unable to execute '$cmd'");
103+
throw new \RuntimeException("Error executing `$cmd` (returned $return)");
104104
}
105105
}
106106
}

src/Command/MigrateCommand.php

Lines changed: 124 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ class MigrateCommand extends Command {
2828

2929
const OPT_REMOTE = 'remote';
3030

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+
3143
const OPT_AUTHORS_FILE = 'authors-file';
3244
const OPT_AUTHORS_FILE_S = 'A';
3345

@@ -51,6 +63,10 @@ class MigrateCommand extends Command {
5163
* @var string
5264
*/
5365
private $gitsvn;
66+
/**
67+
* @var QuestionHelper
68+
*/
69+
private $question;
5470
/**
5571
* Path to authors mapping file.
5672
* @var string
@@ -61,20 +77,36 @@ class MigrateCommand extends Command {
6177
* @var string
6278
*/
6379
private $remote;
80+
6481
/**
65-
* @var QuestionHelper
82+
* @var boolean
6683
*/
67-
private $question;
84+
private $stdlayout;
6885
/**
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.
7087
* @var string
7188
*/
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;
73100
/**
74101
* Whether to preserve empty directories retrieved from subversion.
75102
* @var boolean
76103
*/
77104
private $preserveEmpty;
105+
/**
106+
* Filename for placeholder file used to preserve empty subversion directories.
107+
* @var string
108+
*/
109+
private $placeholderFileName;
78110

79111
/**
80112
* @inheritdoc
@@ -106,6 +138,46 @@ protected function configure() {
106138
'URL of Git remote repository to push to.'
107139
);
108140

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+
109181
$this->addOption(
110182
self::OPT_PRESERVE_EMPTY,
111183
null,
@@ -145,6 +217,22 @@ protected function initialize(InputInterface $input, OutputInterface $output) {
145217
$this->remote = $input->getOption(self::OPT_REMOTE);
146218
}
147219

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+
148236
if ($input->hasOption(self::OPT_PRESERVE_EMPTY)) {
149237
$this->preserveEmpty = $input->getOption(self::OPT_PRESERVE_EMPTY);
150238
$this->placeholderFileName = $input->getOption(self::OPT_PLACEHOLDER_FILE);
@@ -173,6 +261,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
173261
$this->log('REMOTE: ' . $this->remote);
174262
}
175263

264+
if ($this->stdlayout) {
265+
$this->log('USING STANDARD LAYOUT');
266+
}
267+
176268
if ($this->preserveEmpty) {
177269
$this->log('PRESERVE EMPTY DIRS WITH: ' . $this->placeholderFileName);
178270
}
@@ -194,15 +286,23 @@ protected function execute(InputInterface $input, OutputInterface $output) {
194286
$createBranchesQ = new ConfirmationQuestion('Migrate branches? ', true);
195287

196288
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+
}
199295
}
200296

201297
$createTagsQ = new ConfirmationQuestion('Migrate tags? ', true);
202298

203299
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+
}
206306
}
207307

208308
if (isset($this->remote)) {
@@ -233,14 +333,29 @@ private function cloneSubversionRepository($source, $destination, $authorsFile =
233333
'git svn clone',
234334
$source,
235335
'--prefix=svn/',
236-
'--stdlayout',
237336
'--quiet'
238337
];
239338

240339
if (isset($authorsFile)) {
241340
$cmdSeg[] = '-A ' . $authorsFile;
242341
}
243342

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+
244359
if ($this->preserveEmpty) {
245360
$cmdSeg[] = '--preserve-empty-dirs';
246361
$cmdSeg[] = '--placeholder-filename=' . $this->placeholderFileName;

0 commit comments

Comments
 (0)