Skip to content

Commit 6aeb3d0

Browse files
Add diff filter to conditions
1 parent 14c8209 commit 6aeb3d0

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"ext-xml": "*",
3939
"sebastianfeldmann/camino": "^0.9.2",
4040
"sebastianfeldmann/cli": "^3.3",
41-
"sebastianfeldmann/git": "^3.8.6",
41+
"sebastianfeldmann/git": "^3.8.8",
4242
"symfony/console": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
4343
"symfony/filesystem": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
4444
"symfony/process": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0"

src/Hook/Condition/FileChanged.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@ abstract class FileChanged extends File
3535
*/
3636
protected array $filesToWatch;
3737

38+
/**
39+
* Git filter options
40+
*
41+
* @var array<string>
42+
*/
43+
private array $filter;
44+
3845
/**
3946
* FileChange constructor
4047
*
4148
* @param array<string> $files
49+
* @param string $filter
4250
*/
43-
public function __construct(array $files)
51+
public function __construct(array $files, string $filter = 'ACMR')
4452
{
4553
$this->filesToWatch = $files;
54+
$this->filter = !empty($filter) ? str_split($filter) : [];
4655
}
4756

4857
/**
@@ -82,6 +91,6 @@ protected function getChangedFiles(IO $io, Repository $repository): array
8291
$oldHash = isset($ranges[0]) ? $ranges[0]->from()->id() : 'HEAD@{1}';
8392
$newHash = isset($ranges[0]) ? $ranges[0]->to()->id() : 'HEAD';
8493

85-
return $repository->getDiffOperator()->getChangedFiles($oldHash, $newHash);
94+
return $repository->getDiffOperator()->getChangedFiles($oldHash, $newHash, $this->filter);
8695
}
8796
}

tests/unit/Hook/Condition/FileChanged/AllTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testIsFalse(): void
3131
$repository = $this->createRepositoryMock('');
3232
$repository->expects($this->once())->method('getDiffOperator')->willReturn($operator);
3333

34-
$fileChange = new All(['foo.php', 'bar.php']);
34+
$fileChange = new All(['foo.php', 'bar.php'], '');
3535

3636
$this->assertFalse($fileChange->isTrue($io, $repository));
3737
}

0 commit comments

Comments
 (0)