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 #67

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 10, 2023

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#3855:

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 squizlabs/PHP_CodeSniffer#3854 : Fatal error when using Gitblame report in combination with basepath and running from project subdirectory

Related issues/external references

Fixes squizlabs/PHP_CodeSniffer#3854

Loosely related to squizlabs/PHP_CodeSniffer#3809

👆🏻 Translates to:
Fixes #31

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

@jrfnl jrfnl added this to the 3.8.0 milestone Nov 10, 2023
@jrfnl jrfnl force-pushed the feature/reports-gitblame-fix-fatal-error-subdir-basepath branch from bc984e2 to 9dcad76 Compare November 11, 2023 03:44
@jrfnl jrfnl force-pushed the feature/reports-gitblame-fix-fatal-error-subdir-basepath branch from 9dcad76 to 41c37d3 Compare December 4, 2023 23:55
…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 jrfnl force-pushed the feature/reports-gitblame-fix-fatal-error-subdir-basepath branch from 41c37d3 to a2667bc Compare December 5, 2023 00:02
@jrfnl jrfnl merged commit 66b4b36 into master Dec 5, 2023
63 checks passed
@jrfnl jrfnl deleted the feature/reports-gitblame-fix-fatal-error-subdir-basepath branch December 5, 2023 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant