Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 9b63b8a

Browse files
Merge branch 'develop'
2 parents 51afaa6 + 84cbcb6 commit 9b63b8a

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

october

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
88
require __DIR__.'/vendor/autoload.php';
99
}
1010

11-
$app = new Symfony\Component\Console\Application('October CMS Bootstrapper', '0.4.0');
11+
$app = new Symfony\Component\Console\Application('October CMS Bootstrapper', '0.4.1');
1212
$app->add(new \OFFLINE\Bootstrapper\October\Console\InitCommand);
1313
$app->add(new \OFFLINE\Bootstrapper\October\Console\InstallCommand);
1414
$app->run();

src/Installer/BaseInstaller.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use OFFLINE\Bootstrapper\October\Util\Gitignore;
88
use RuntimeException;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Process\Process;
1011

1112
abstract class BaseInstaller
1213
{
@@ -89,7 +90,7 @@ protected function cleanup($path)
8990
}
9091

9192
/**
92-
* Removes a directory recursive.
93+
* Removes a directory recursively.
9394
*
9495
* @param $dir
9596
*
@@ -100,12 +101,36 @@ public function rmdir($dir)
100101
$entries = array_diff(scandir($dir), ['.', '..']);
101102
foreach ($entries as $entry) {
102103
$path = $dir . DS . $entry;
103-
is_dir($path) ? $this->rmdir($path) : unlink($path);
104+
is_dir($path) ? $this->rmdir($path) : $this->unlink($path);
104105
}
105106

106107
return rmdir($dir);
107108
}
108109

110+
/**
111+
* Delete a file. Fallback to OS native rm command if the file to be deleted is write protected.
112+
*
113+
* @param string $file
114+
*/
115+
public function unlink($file)
116+
{
117+
if (is_writable($file)) {
118+
unlink($file);
119+
} else {
120+
// Just to be sure that we don't delete "too much" by accident...
121+
if (\in_array($file, ['*', '**', '.', '..', '/', '/*'])) {
122+
return;
123+
}
124+
125+
// If there are write-protected files present (primarily on Windows) we can use
126+
// the force mode of rm to remove it. PHP itself won't delete write-protected files.
127+
$command = stripos(PHP_OS, 'WIN') === 0 ? 'rm /f' : 'rm -f';
128+
$file = escapeshellarg($file);
129+
130+
(new Process($command . ' ' . $file))->setTimeout(60)->run();
131+
}
132+
}
133+
109134
protected function write($line)
110135
{
111136
$this->output->writeln($line);

src/Installer/PluginInstaller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace OFFLINE\Bootstrapper\October\Installer;
44

55

6-
use GitElephant\Repository;
76
use OFFLINE\Bootstrapper\October\Util\Composer;
7+
use OFFLINE\Bootstrapper\October\Util\Git;
88
use Symfony\Component\Process\Exception\LogicException;
99
use Symfony\Component\Process\Exception\RuntimeException;
1010
use Symfony\Component\Process\Process;
@@ -70,7 +70,7 @@ public function install()
7070
continue;
7171
}
7272

73-
$repo = Repository::open($pluginDir);
73+
$repo = Git::repo($pluginDir);
7474
try {
7575
$repo->cloneFrom($remote, $pluginDir);
7676
if ($branch !== false) {

src/Installer/ThemeInstaller.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace OFFLINE\Bootstrapper\October\Installer;
44

55

6-
use GitElephant\Repository;
6+
use OFFLINE\Bootstrapper\October\Util\Git;
77
use Symfony\Component\Process\Exception\InvalidArgumentException;
88
use Symfony\Component\Process\Exception\LogicException;
99
use Symfony\Component\Process\Exception\RuntimeException;
@@ -43,10 +43,11 @@ public function install()
4343

4444
if ( ! $this->isEmpty($themeDir)) {
4545
$this->write(sprintf('<comment>-> Theme "%s" is already installed. Skipping.</comment>', $theme));
46+
4647
return;
4748
}
4849

49-
$repo = Repository::open($themeDir);
50+
$repo = Git::repo($themeDir);
5051
try {
5152
$repo->cloneFrom($remote, $themeDir);
5253
} catch (RuntimeException $e) {

src/Util/Git.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace OFFLINE\Bootstrapper\October\Util;
4+
5+
use GitElephant\GitBinary;
6+
use GitElephant\Repository;
7+
8+
/**
9+
* This is a simple wrapper class around GitElephant to provide
10+
* the correct Binary if we run on Windows.
11+
*/
12+
class Git
13+
{
14+
public static function repo($path)
15+
{
16+
$binary = null;
17+
if (stripos(PHP_OS, 'WIN') === 0) {
18+
// Use the default `git` command under Windows. This requires the git binary
19+
// to be added to the PATH environment variable.
20+
$binary = new GitBinary('git');
21+
}
22+
23+
return Repository::open($path, $binary);
24+
}
25+
}

src/Util/UsesTemplate.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace OFFLINE\Bootstrapper\October\Util;
44

5-
use GitElephant\Repository;
65
use RuntimeException;
76

87
trait UsesTemplate
@@ -33,7 +32,7 @@ public function updateTemplateFiles()
3332
return;
3433
}
3534

36-
$repo = Repository::open($overridePath);
35+
$repo = Git::repo($overridePath);
3736
try {
3837
$repo->pull();
3938
} catch (\Throwable $e) {

0 commit comments

Comments
 (0)