|
3 | 3 |
|
4 | 4 | declare(strict_types=1); |
5 | 5 |
|
| 6 | +use GitWrapper\GitWrapper; |
6 | 7 | use Symfony\Component\Filesystem\Filesystem; |
7 | 8 |
|
8 | 9 | require_once __DIR__.'/../vendor/autoload.php'; |
9 | 10 |
|
10 | 11 | $filesystem = new Filesystem(); |
11 | | - |
12 | | -$target = __DIR__.'/../lib/schematron'; |
13 | | - |
14 | | -$base = 'https://github.com/Schematron/schematron/raw/master'; |
| 12 | +$git = new GitWrapper(); |
| 13 | +$git->streamOutput(); |
| 14 | + |
| 15 | +$repoUri = 'https://github.com/Schematron/schematron'; |
| 16 | +$repoDir = __DIR__.'/../tmp/schematron'; |
| 17 | +$patchesDir = __DIR__.'/../tmp/patches'; |
| 18 | +$targetDir = __DIR__.'/../lib/schematron'; |
| 19 | +$patches = [ |
| 20 | + 'https://github.com/Schematron/schematron/pull/81.patch', // Fixes attribute paths. |
| 21 | +]; |
15 | 22 | $files = [ |
16 | 23 | 'LICENSE', |
17 | 24 | 'trunk/schematron/code/iso_schematron_skeleton_for_xslt1.xsl', |
|
20 | 27 | 'trunk/converters/code/ToSchematron/ExtractSchFromXSD.xsl', |
21 | 28 | ]; |
22 | 29 |
|
23 | | -$filesystem->remove(new FilesystemIterator($target)); |
| 30 | +if (!$filesystem->exists($repoDir)) { |
| 31 | + $filesystem->mkdir($repoDir); |
| 32 | + $repo = $git->cloneRepository($repoUri, $repoDir, ['depth' => 1]); |
| 33 | +} else { |
| 34 | + $repo = $git->workingCopy($repoDir); |
| 35 | + $repo->fetch('origin', 'master', ['depth' => 1]); |
| 36 | + $repo->reset(['hard' => true], 'origin/master'); |
| 37 | +} |
| 38 | + |
| 39 | +foreach ($patches as $patch) { |
| 40 | + $patchTarget = "${patchesDir}/".md5($patch); |
| 41 | + |
| 42 | + echo "Downloading {$patch} to {$patchTarget}\n"; |
| 43 | + $filesystem->copy($patch, $patchTarget); |
| 44 | + $repo->apply($patchTarget, ['verbose' => true]); |
| 45 | +} |
| 46 | + |
| 47 | +$filesystem->remove(new FilesystemIterator($targetDir)); |
24 | 48 |
|
25 | 49 | foreach ($files as $file) { |
26 | | - $filesystem->copy("{$base}/${file}", "{$target}/".basename($file)); |
| 50 | + $origin = "${repoDir}/${file}"; |
| 51 | + $target = "${targetDir}/".basename($file); |
| 52 | + |
| 53 | + echo "Copying {$origin} to {$target}\n"; |
| 54 | + $filesystem->copy($origin, $target); |
27 | 55 | } |
0 commit comments