-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
62 deletions.
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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Phar\Differ; | ||
|
||
use Fidry\Console\Input\IO; | ||
use KevinGH\Box\Console\Command\Extract; | ||
use KevinGH\Box\Phar\PharInfo; | ||
use function array_filter; | ||
use function explode; | ||
use function implode; | ||
use function sprintf; | ||
use function str_starts_with; | ||
|
||
final class GitDiffer implements Differ | ||
{ | ||
public function diff(PharInfo $pharInfoA, PharInfo $pharInfoB, IO $io): void | ||
{ | ||
$gitDiff = ProcessCommandBasedDiffer::getDiff( | ||
$pharInfoA, | ||
$pharInfoB, | ||
'git diff --no-index', | ||
); | ||
|
||
if (null === $gitDiff) { | ||
$io->writeln(Differ::NO_DIFF_MESSAGE); | ||
|
||
return; | ||
} | ||
|
||
$separator = 'diff --git '; | ||
|
||
$diffLines = explode( | ||
$separator, | ||
$gitDiff, | ||
); | ||
|
||
$pharMetaLine = sprintf( | ||
'a%2$s/%1$s b%3$s/%1$s', | ||
Extract::PHAR_META_PATH, | ||
$pharInfoA->getFileName(), | ||
$pharInfoB->getFileName(), | ||
); | ||
|
||
$filteredLines = array_filter( | ||
$diffLines, | ||
static fn (string $line) => !str_starts_with($line, $pharMetaLine) | ||
); | ||
|
||
$filteredDiff = implode($separator, $filteredLines); | ||
|
||
$io->writeln('' === $filteredDiff ? Differ::NO_DIFF_MESSAGE : $filteredDiff); | ||
} | ||
} |
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