Skip to content

Commit 6e3901c

Browse files
committed
fix: #1 crash when git not exists
1 parent 606dd95 commit 6e3901c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/LintPublishCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function handle()
3232
$basePath = $this->laravel->basePath();
3333

3434
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
35-
if (File::exists($basePath . '/.git')) {
35+
if (File::exists($basePath . '/.git/hooks')) {
3636
File::copy(__DIR__ . '/stubs/git-pre-commit', $basePath . '/.git/hooks/pre-commit');
3737
File::chmod($basePath . '/.git/hooks/pre-commit', 0755);
3838
}

tests/LintPublishCommandTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22

33
namespace LaravelFans\Lint\Tests;
44

5+
use Illuminate\Support\Facades\File;
6+
57
class LintPublishCommandTest extends TestCase
68
{
7-
public function testHandle()
9+
public function testGitNotExists()
10+
{
11+
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
12+
File::deleteDirectory($laravelPath . '/.git/', true);
13+
$this->artisan('lint:publish')->run();
14+
$this->assertFileExists($laravelPath . '/phpcs.xml');
15+
$this->assertFileDoesNotExist($laravelPath . '/.git/hooks/pre-commit');
16+
}
17+
18+
public function testGitExists()
819
{
920
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
21+
File::makeDirectory($laravelPath . '/.git/hooks/', 0755, true);
1022
$this->artisan('lint:publish')->run();
1123
$this->assertFileExists($laravelPath . '/phpcs.xml');
1224
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');

0 commit comments

Comments
 (0)