Skip to content

display file name in the diff output #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/file-diff
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ function fileDiff($oldFilePath, $newFilePath)
$newLineNumber = $i + 1;


$changes[] = ($oldLine === null ? "$colorGreen+ New (Line $newLineNumber): " : "$colorRed- Old (Line $oldLineNumber): ") . ($oldLine ?? $newLine) . "$colorReset";
$changes[] = ($oldLine === null ? "$colorGreen+ $newFilePath (Line $newLineNumber): " : "$colorRed- $oldFilePath (Line $oldLineNumber): ") . ($oldLine ?? $newLine) . "$colorReset";

if ($oldLine !== null && $newLine !== null) {
$changes[] = "$colorGreen+ New (Line $newLineNumber): " . $newLine . "$colorReset";
$changes[] = "$colorGreen+ $newFilePath (Line $newLineNumber): " . $newLine . "$colorReset";
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/FileDiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static function commandArgumentProvider(): iterable
file_put_contents("new", "this line has same old code" . PHP_EOL, FILE_APPEND);


yield ['old', 'new', 'Old (Line 1):'];
yield ['old', 'new', 'Old (Line 2):'];
yield ['old', 'new', 'old (Line 1):'];
yield ['old', 'new', 'old (Line 2):'];
}

public static function matchingDataProvider(): iterable
Expand All @@ -35,7 +35,7 @@ public static function matchingDataProvider(): iterable
file_put_contents("new", "this has matching content" . PHP_EOL, FILE_APPEND);


yield ['old', 'new', 'Old (Line 3):'];
yield ['old', 'new', 'old (Line 3):'];
}

#[Test]
Expand Down