Skip to content

Commit

Permalink
Gitblame: fix fatal error on chdir() when basepath is set and php…
Browse files Browse the repository at this point in the history
…cs is run from subdir

The `Reporter::prepareFileReport()` method strips the `basepath` off the file name for the `$report['filename']`.

https://github.com/squizlabs/PHP_CodeSniffer/blob/276f68cc74a3e4e1855bab6d01f0089337d00ae0/src/Reporter.php#L337

While this is fine in most cases, for "blame" reports, the full path is needed.

This changes the path passed to the `getBlameContent()` method in subclasses of the `VersionControl` class to the full path, which fixes the fatal error for the `Gitblame` report (and probably similar/related errors in the `Hgblame` and the `Svnblame` reports, but I don't have any repos to test this on).

Fixes 3854
  • Loading branch information
jrfnl committed Nov 11, 2023
1 parent b0d171b commit 9dcad76
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Reports/VersionControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class VersionControl implements Report
*/
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
{
$blames = $this->getBlameContent($report['filename']);
$blames = $this->getBlameContent($phpcsFile->getFilename());

$authorCache = [];
$praiseCache = [];
Expand Down

0 comments on commit 9dcad76

Please sign in to comment.