Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Feat ] Quiet Install #6

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions app/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Install extends Command
{
protected $signature = 'install';
protected $signature = 'install {--verbose}';

protected $description = 'Install git hooks';

Expand All @@ -34,19 +34,25 @@ public function handle(): int
);
}

$this->info('Installing git hooks...');
if ($this->option('verbose')) {
$this->info('Installing git hooks...');
}

$this->getHooks()->each(function ($hook) {
if ($this->hookIsDisabled($hook)) {
$this->warn("{$hook} git hook is disabled, skipping...");
if ($this->option('verbose')) {
$this->warn("{$hook} git hook is disabled, skipping...");
}

return;
}

$this->installHook($hook);
});

$this->info('Verifying hooks are executable...');
if ($this->option('verbose')) {
$this->info('Verifying hooks are executable...');
}
exec('chmod +x '.Whisky::cwd('.git/hooks').'/*');
exec('chmod +x '.Whisky::base_path('bin/run-hook'));

Expand Down Expand Up @@ -82,12 +88,16 @@ private function hookIsInstalled(string $hook): bool
private function installHook(string $hook): void
{
if (! File::exists(Whisky::cwd(".git/hooks/{$hook}"))) {
$this->line("{$hook} file does not exist yet, creating...");
if ($this->option('verbose')) {
$this->line("{$hook} file does not exist yet, creating...");
}
File::put(Whisky::cwd(".git/hooks/{$hook}"), '#!/bin/sh'.PHP_EOL);
}

if ($this->hookIsInstalled($hook)) {
$this->warn("{$hook} git hook already installed, skipping...");
if ($this->option('verbose')) {
$this->warn("{$hook} git hook already installed, skipping...");
}

return;
}
Expand All @@ -97,6 +107,8 @@ private function installHook(string $hook): void
"eval \"$(./vendor/bin/whisky get-run-cmd {$hook})\"".PHP_EOL,
);

$this->info("{$hook} git hook installed successfully.");
if ($this->option('verbose')) {
$this->info("{$hook} git hook installed successfully.");
}
}
}