Skip to content

Commit 01d01fa

Browse files
PatrickBrainMaestro
Patrick
authored andcommitted
Fix missing shebang after update (BrainMaestro#9)
This will also add and test the shebang on update.
1 parent 3eb176a commit 01d01fa

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Commands/UpdateCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
4141
$filename = "{$gitDir}/hooks/{$hook}";
4242

4343
$operation = file_exists($filename) ? 'Updated' : 'Added';
44+
45+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
46+
// On windows we need to add a SHEBANG
47+
// See: https://github.com/BrainMaestro/composer-git-hooks/issues/7
48+
$script = '#!/bin/bash' . PHP_EOL . $script;
49+
}
50+
4451
file_put_contents($filename, $script);
4552
chmod($filename, 0755);
4653
$output->writeln("{$operation} <info>{$hook}</info> hook");

tests/UpdateCommandTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ public function it_updates_hooks_that_already_exist()
4545
}
4646
}
4747

48+
public function it_adds_shebang_to_hooks_on_windows()
49+
{
50+
if(strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
51+
$this->markTestSkipped('This test is only relevant on windows. You\'re running Linux.');
52+
53+
self::createHooks();
54+
$this->commandTester->execute([]);
55+
56+
foreach (array_keys(self::$hooks) as $hook) {
57+
$this->assertContains("Updated {$hook} hook", $this->commandTester->getDisplay());
58+
59+
$content = file_get_contents(".git/hooks/" . $hook);
60+
$this->assertNotFalse(strpos($content, "#!/bin/bash"));
61+
$this->assertEquals(strpos($content, "#!/bin/bash"), 0);
62+
}
63+
}
64+
4865
/**
4966
* @test
5067
*/

0 commit comments

Comments
 (0)