Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/Commands/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filename = "{$gitDir}/hooks/{$hook}";

$operation = file_exists($filename) ? 'Updated' : 'Added';

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// On windows we need to add a SHEBANG
// See: https://github.com/BrainMaestro/composer-git-hooks/issues/7
$script = '#!/bin/bash' . PHP_EOL . $script;
}

file_put_contents($filename, $script);
chmod($filename, 0755);
$output->writeln("{$operation} <info>{$hook}</info> hook");
Expand Down
17 changes: 17 additions & 0 deletions tests/UpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ public function it_updates_hooks_that_already_exist()
}
}

public function it_adds_shebang_to_hooks_on_windows()
{
if(strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
$this->markTestSkipped('This test is only relevant on windows. You\'re running Linux.');

self::createHooks();
$this->commandTester->execute([]);

foreach (array_keys(self::$hooks) as $hook) {
$this->assertContains("Updated {$hook} hook", $this->commandTester->getDisplay());

$content = file_get_contents(".git/hooks/" . $hook);
$this->assertNotFalse(strpos($content, "#!/bin/bash"));
$this->assertEquals(strpos($content, "#!/bin/bash"), 0);
}
}

/**
* @test
*/
Expand Down