So, there's this executable file called pint (it's part of the Laravel 9 framework). It formats PHP files according to a configurable standard like PSR12. Anyway, you can pass a list of the files you want to format as the parameters of pint like this:
pint file1 file2 file3 file4 ...
If you pass no argument, pint formats all files of the project.
So, what I'm trying to do is that I want pint to format only the files that have changed since the last commit. In other words, I want the output of git diff --name-only HEAD^ HEAD
to be passed as parameters of pint in bash shell.
So, this is what I could come up with, but sadly it doesn't work:
git diff --name-only HEAD^ HEAD -o /dev/stdout | ./vendor/bin/pint
Which says: fatal: /dev/stdout: '/dev/stdout' is outside repository at '/home/user/directory'
and then it proceeds to execute ./vendor/bin/pint
normally as if no argument had been passed.
I suppose I should somehow convert new line
to space
before passing it to pint but I'm not sure.
CodePudding user response:
|
is for piping to standard input, but pint
expects the filenames to be command-line arguments, not stdin.
Use $(...)
to substitute the output of a command into the command line.
./vendor/bin/pint $(git diff --name-only HEAD^ HEAD)
Note that this won't work if any of the filenames contain whitespace, since the spaces will be treated as filename delimiters.