Skip to content
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

Gitblame: fix fatal error on chdir() when basepath is set and phpcs is run from subdir #3855

Closed

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 13, 2023

Description

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

'filename' => Common::stripBasepath($phpcsFile->getFilename(), $this->config->basepath),

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).

Suggested changelog entry

Fixed bug #3854 : Fatal error when using Gitblame report in combination with basepath and running from project subdirectory

Related issues/external references

Fixes #3854

Loosely related to #3809

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

…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
@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#67

@jrfnl jrfnl deleted the feature/reports-gitblame-fix-fatal-error-subdir-basepath branch December 2, 2023 02:28
@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 8, 2023

FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal error when using Gitblame report from subdirectory when ruleset has basepath
1 participant