Skip to content

fix: create hooks dir, when hooks dir not exists #5

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

Merged
merged 4 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add it_create_git_hooks_path_when_hooks_dir_not_exists test met…
…hod for AddCommand and UpdateCo
  • Loading branch information
mark committed Jun 7, 2017
commit f54dbfdbfcd9b30f3ecd3a11d892c47a9b5c7b7e
2 changes: 1 addition & 1 deletion src/Commands/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$hookDir = "{$gitDir}/hooks";

if (! is_dir($hookDir)) {
mkdir($hookDir);
mkdir($hookDir, 0700, true);
}

foreach ($this->hooks as $hook => $script) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$hookDir = "{$gitDir}/hooks";

if (! is_dir($hookDir)) {
mkdir($hookDir);
mkdir($hookDir, 0700, true);
}

foreach ($this->hooks as $hook => $script) {
Expand Down
21 changes: 21 additions & 0 deletions tests/AddCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,25 @@ public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
$this->assertFalse(file_exists(".git/hooks/{$hook}"));
}
}

/**
* @test
*/
public function it_create_git_hooks_path_when_hooks_dir_not_exists()
{
$gitDirs = ['test-git-dir', '.git'];

foreach ($gitDirs as $gitDir) {
if (file_exists($hookDir = "{$gitDir}/hooks")) {
rmdir($hookDir);
}

$this->commandTester->execute(['--git-dir' => $gitDir]);

foreach (array_keys(self::$hooks) as $hook) {
$this->assertTrue(file_exists("{$gitDir}/hooks/{$hook}"));
unlink("{$gitDir}/hooks/{$hook}");
}
}
}
}
25 changes: 25 additions & 0 deletions tests/UpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,29 @@ public function it_uses_a_different_git_path_if_specified()

passthru("rm -rf {$gitDir}");
}

/**
* @test
*/
public function it_create_git_hooks_path_when_hooks_dir_not_exists()
{
$gitDirs = ['test-git-dir', '.git'];

foreach ($gitDirs as $gitDir) {
if (file_exists($hookDir = "{$gitDir}/hooks")) {
rmdir($hookDir);
}

$this->commandTester->execute(['--git-dir' => $gitDir]);

foreach (array_keys(self::$hooks) as $hook) {
$this->assertTrue(file_exists("{$gitDir}/hooks/{$hook}"));
unlink("{$gitDir}/hooks/{$hook}");
}

if ($gitDir != '.git') {
passthru("rm -rf {$gitDir}");
}
}
}
}