sirbrillig / phpcs-changed

🐘 Run phpcs on files and only report new warnings/errors compared to the previous version.
MIT License
31 stars 11 forks source link

Use full path command for git cat-file command #67

Closed sirbrillig closed 1 year ago

sirbrillig commented 1 year ago

When referencing a file in the remote repository, git requires that you specify the full path to the file.

For example, if you are in the root of a repository and run the following commands:

> cd foo/bar/
> git show HEAD:file.php
> echo $?
128

This will return an error because it can't find a file with a relative path. Instead, you can run the command with the full path to the file relative to the repo root:

> cd foo/bar/
> git show HEAD:$(git ls-files --full-name file.php)
> echo $?
0

For the git show command, phpcs-changed already does this thanks to the work done in https://github.com/sirbrillig/phpcs-changed/pull/18. However, the git cat-file command, added later in https://github.com/sirbrillig/phpcs-changed/pull/28 does not use that strategy, which means it will not work outside of the repository root.

In this PR we alter git cat-file to also use the full path name.

Fixes https://github.com/sirbrillig/phpcs-changed/issues/66