Skip to content

Commit d8ec997

Browse files
committed
Resolve git hooks project path from working directory
1 parent a9194ce commit d8ec997

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/Console/Command/GitHooksCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ protected function configure(): void
130130
protected function execute(InputInterface $input, OutputInterface $output): int
131131
{
132132
$sourcePath = $this->fileLocator->locate((string) $input->getOption('source'));
133+
$projectPath = (string) $this->filesystem->getAbsolutePath('.');
133134
$targetPath = (string) $this->filesystem->getAbsolutePath((string) $input->getOption('target'));
134-
$projectPath = Path::canonicalize(Path::join($targetPath, '..', '..'));
135135
$overwrite = ! $input->getOption('no-overwrite');
136136
$dryRun = (bool) $input->getOption('dry-run');
137137
$check = (bool) $input->getOption('check');

tests/Console/Command/GitHooksCommandTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ protected function setUp(): void
116116
->willReturn(false);
117117
$this->input->isInteractive()
118118
->willReturn(false);
119+
$this->filesystem->getAbsolutePath('.')
120+
->willReturn('/app');
119121
$this->filesystem->readFile(Argument::containingString('/post-merge'))
120122
->willReturn('#!/bin/sh');
121123

@@ -208,7 +210,7 @@ public function executeWillRenderManagedGrumPhpConfigIntoPlaceholderHooks(): voi
208210
$this->input->getOption('source')
209211
->willReturn('resources/git-hooks');
210212
$this->input->getOption('target')
211-
->willReturn('.git/hooks');
213+
->willReturn('.githooks');
212214
$this->input->getOption('no-overwrite')
213215
->willReturn(false);
214216

@@ -217,18 +219,18 @@ public function executeWillRenderManagedGrumPhpConfigIntoPlaceholderHooks(): voi
217219
$this->finderFactory->create()
218220
->willReturn(new Finder())
219221
->shouldBeCalledOnce();
220-
$this->filesystem->getAbsolutePath('.git/hooks')
221-
->willReturn('/app/.git/hooks');
222-
$this->filesystem->exists('/app/.git/hooks/post-merge')
222+
$this->filesystem->getAbsolutePath('.githooks')
223+
->willReturn('/app/.githooks');
224+
$this->filesystem->exists('/app/.githooks/post-merge')
223225
->willReturn(false);
224-
$this->filesystem->exists('/app/.git/hooks/pre-commit')
226+
$this->filesystem->exists('/app/.githooks/pre-commit')
225227
->willReturn(false);
226228
$this->filesystem->readFile(Argument::containingString('/pre-commit'))
227229
->willReturn("DEVTOOLS_GRUMPHP_CONFIG=__DEV_TOOLS_GRUMPHP_CONFIG__\n");
228-
$this->filesystem->copy(Argument::containingString('/post-merge'), '/app/.git/hooks/post-merge', false)
230+
$this->filesystem->copy(Argument::containingString('/post-merge'), '/app/.githooks/post-merge', false)
229231
->shouldBeCalledOnce();
230232
$this->filesystem->dumpFile(
231-
'/app/.git/hooks/pre-commit',
233+
'/app/.githooks/pre-commit',
232234
Argument::that(
233235
static fn(string $contents): bool => str_contains(
234236
$contents,

0 commit comments

Comments
 (0)