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

Fatal error when using Gitblame report from subdirectory when ruleset has basepath #3854

Closed
3 tasks done
jrfnl opened this issue Jul 13, 2023 · 3 comments · Fixed by PHPCSStandards/PHP_CodeSniffer#67
Closed
3 tasks done

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Jul 13, 2023

Describe the bug

When basepath is set in a custom ruleset AND PHPCS is subsequently run from within a subdirectory of the project AND the Gitblame report is requested, a fatal error happens.

As far as I can see, this is due to the $filename which is being passed to Gitblame::getBlameContent() not being the full path to the file, but the path with the basename stripped off.

To reproduce

Steps to reproduce the behavior with PHPCS itself:

  1. Change into the src directory of the PHPCS project
  2. Run phpcs -psl . --report=gitblame
  3. See the following error message displayed
PHP_CodeSniffer version 3.7.2 (stable) by Squiz (http://www.squiz.net)

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: chdir(): No such file or directory (errno 2) in path/to/src/Reports/Gitblame.php on line 72 in path/to/src/Runner.php:608
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Runner->handleErrors(2, 'chdir(): No suc...', '...', 72)
#1 path/to/src/Reports/Gitblame.php(72): chdir('src')
#2 path/to/src/Reports/VersionControl.php(43): PHP_CodeSniffer\Reports\Gitblame->getBlameContent('src\\Config.php')
#3 path/to/src/Reporter.php(285): PHP_CodeSniffer\Reports\VersionControl->generateFileReport(Array, Object(PHP_CodeSniffer\Files\LocalFile), true, 150)
#4 path/to/src/Runner.php(700): PHP_CodeSniffer\Reporter->cacheFileReport(Object(PHP_CodeSniffer\Files\LocalFile), Object(PHP_CodeSniffer\Config))
#5 path/to/src/Runner.php(438): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#6 path/to/src/Runner.php(116): PHP_CodeSniffer\Runner->run()
#7 path/to/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#8 {main}
  thrown in path/to/src/Runner.php on line 608

Exit code is 255

Expected behavior

No fatal error and the git blame report is displayed correctly

Versions (please complete the following information)

Operating System Windows 10
PHP version 8.2.7 (but not relevant)
PHP_CodeSniffer version bleeding edge including the fix from #3809
Standard PHPCS native phpcs.xml.dist
Install type git clone

Additional context

This issue is loosely related to #3809.

Please confirm:

  • I have searched the issue list and am not opening a duplicate issue.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.
@jrfnl jrfnl changed the title Fatal error when using GitBlame report from subdirectory when ruleset has basepath Fatal error when using Gitblame report from subdirectory when ruleset has basepath Jul 13, 2023
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 13, 2023

PR #3855 should fix this

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#31

@jrfnl jrfnl closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 8, 2023

FYI: the fix for this issue 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