-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In order to forward hooks that require stdIn like pre-push it is necessary to allow access to the original hook stdIn data. You can now use {$STDIN} in action configurations like this: echo {$STDIN} | hooks/git-lfs/pre-push Fixes issue #256
- Loading branch information
1 parent
454d537
commit 90deb99
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CaptainHook. | ||
* | ||
* (c) Sebastian Feldmann <sf@sebastian-feldmann.info> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CaptainHook\App\Runner\Action\Cli\Command\Placeholder; | ||
|
||
/** | ||
* Class StdIn | ||
* | ||
* @package CaptainHook | ||
* @author Sebastian Feldmann <sf@sebastian-feldmann.info> | ||
* @link https://github.com/captainhookphp/captainhook | ||
* @since Class available since Release 5.23.5 | ||
*/ | ||
class StdIn extends Foundation | ||
{ | ||
/** | ||
* Return the original hook stdIn (shell escaped) | ||
* | ||
* Returns at least '' | ||
* | ||
* @param array<string, mixed> $options | ||
* @return string | ||
*/ | ||
public function replacement(array $options): string | ||
{ | ||
return escapeshellarg(implode(PHP_EOL, $this->io->getStandardInput())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/unit/Runner/Action/Cli/Command/Placeholder/StdInTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CaptainHook. | ||
* | ||
* (c) Sebastian Feldmann <sf@sebastian-feldmann.info> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CaptainHook\App\Runner\Action\Cli\Command\Placeholder; | ||
|
||
use CaptainHook\App\Console\IO\Mockery as IOMockery; | ||
use CaptainHook\App\Config\Mockery as ConfigMockery; | ||
use CaptainHook\App\Mockery as AppMockery; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class StdInTest extends TestCase | ||
{ | ||
use IOMockery; | ||
use AppMockery; | ||
use ConfigMockery; | ||
|
||
/** | ||
* Tests StdIn::replacement | ||
*/ | ||
public function testStdInValue(): void | ||
{ | ||
$expected = 'refs/heads/main 9dfa0fa6221d75f48b2dfac359127324bedf8409' | ||
. ' refs/heads/main 8309f6e16097754469c485e604900c573bf2c5d8'; | ||
|
||
$io = $this->createIOMock(); | ||
$repo = $this->createRepositoryMock(); | ||
$config = $this->createConfigMock(); | ||
$io->expects($this->once())->method('getStandardInput')->willReturn([$expected]); | ||
|
||
$placeholder = new StdIn($io, $config, $repo); | ||
$result = $placeholder->replacement([]); | ||
|
||
$this->assertEquals(escapeshellarg($expected), $result); | ||
} | ||
|
||
/** | ||
* Tests StdIn::replacement | ||
*/ | ||
public function testEmptyStdIn(): void | ||
{ | ||
$io = $this->createIOMock(); | ||
$repo = $this->createRepositoryMock(); | ||
$config = $this->createConfigMock(); | ||
$io->method('getStandardInput')->willReturn([]); | ||
|
||
$placeholder = new StdIn($io, $config, $repo); | ||
$result = $placeholder->replacement([]); | ||
$this->assertEquals("''", $result); | ||
} | ||
} |