Skip to content

Commit 3908d9a

Browse files
[ BugFix ] Escape spaces in path (for real this time) (#88)
* extract space escaping, make idempotent * escape spaces when ensuring hooks are executable * escape spaces when generating bin_path * use existing method to ensure hooks are executable
1 parent f2a62b3 commit 3908d9a

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

app/Commands/Install.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ public function handle(): int
6565
$hook->install();
6666

6767
if ($this->option('verbose')) {
68-
$this->info("{$hook->name} git hook installed successfully.");
68+
$this->info("Ensuring {$hook->name} hook is executable...");
6969
}
70-
});
70+
$hook->ensureExecutable();
7171

72-
if ($this->platform->isNotWindows()) {
7372
if ($this->option('verbose')) {
74-
$this->info('Verifying hooks are executable...');
73+
$this->info("{$hook->name} git hook installed successfully.");
7574
}
76-
exec('chmod +x '.Platform::cwd('.git/hooks').'/*');
77-
}
75+
});
7876

7977
$this->info('Git hooks installed successfully.');
8078

app/Commands/Update.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,16 @@ public function handle(): int
4242
}
4343

4444
$hook->install();
45-
$hook->ensureExecutable();
4645

4746
if ($this->option('verbose')) {
48-
$this->info("{$hook->name} git hook installed successfully.");
47+
$this->info("Ensuring {$hook->name} hook is executable...");
4948
}
50-
});
49+
$hook->ensureExecutable();
5150

52-
if ($this->platform->isNotWindows()) {
5351
if ($this->option('verbose')) {
54-
$this->info('Verifying hooks are executable...');
52+
$this->info("{$hook->name} git hook installed successfully.");
5553
}
56-
exec('chmod +x '.Platform::cwd('.git/hooks').'/*');
57-
}
54+
});
5855

5956
$this->line('Git hooks updated successfully.');
6057

app/Hook.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public function enable(): void
9191
public function ensureExecutable(): void
9292
{
9393
if ((new Platform)->isNotWindows()) {
94-
exec('chmod +x '.Platform::cwd(".git/hooks/{$this->hook}"));
94+
$path = Platform::cwd(".git/hooks/{$this->hook}");
95+
$path = Platform::escapeSpaces($path);
96+
97+
exec("chmod +x {$path}");
9598
}
9699
}
97100

app/Platform.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ public static function temp_test_path(string $path = ''): string
2626

2727
public static function normalizePath(string $path): string
2828
{
29-
$path = str_replace(' ', '\\ ', $path);
30-
3129
if ((new self)->isWindows()) {
3230
return str_replace('\\', '/', $path);
3331
}
3432

3533
return $path;
3634
}
3735

36+
public static function escapeSpaces(string $path): string
37+
{
38+
return preg_replace('/(?<!\\\) /', '\\ ', $path);
39+
}
40+
3841
public static function getGlobalComposerHome(): string
3942
{
4043
return rtrim(shell_exec('composer -n global config home --quiet'), "\n");

app/Whisky.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public static function base_path(string $path = ''): string
1919

2020
public static function bin_path(): string
2121
{
22-
return Platform::normalizePath(match (true) {
22+
$path = Platform::normalizePath(match (true) {
2323
self::dogfooding() => Platform::cwd('whisky'),
2424
self::isRunningGlobally() => Platform::getGlobalComposerBinDir().'/whisky',
2525
default => Platform::cwd('vendor/bin/whisky'),
2626
});
27+
28+
return Platform::escapeSpaces($path);
2729
}
2830

2931
public static function dogfooding(): bool

0 commit comments

Comments
 (0)