-
Notifications
You must be signed in to change notification settings - Fork 440
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
Fixes #592: Exotic structure with Composer and GrumPHP in subfolder compared to GIT #607
Conversation
@@ -13,7 +13,7 @@ COMMIT_MSG_FILE=$1 | |||
COMMIT_MSG=$(cat "${COMMIT_MSG_FILE}") | |||
|
|||
# Fetch the GIT diff and format it as command input: | |||
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat) | |||
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged --src-prefix="a/${HOOK_PREFIX}" --dst-prefix="b/${HOOK_PREFIX}" | cat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not sure if this file needs to be updated as well. I did just to be sure, but have no way of testing it.
@@ -6,7 +6,7 @@ | |||
# | |||
|
|||
# Fetch the GIT diff and format it as command input: | |||
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat) | |||
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged --src-prefix="a/${HOOK_PREFIX}" --dst-prefix="b/${HOOK_PREFIX}" | cat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not sure if this file needs to be updated as well. I did just to be sure, but have no way of testing it.
Whoa, not at all sure what those failures are about in travis :/ |
ac9fc1d
to
f53d65a
Compare
I get the same errors on master without any change... |
@malc0mn. Thanks for the PR. I know some directory structures are hard to handle ATM. We are looking into adding e2e tests to cover as many paths as possible. We won't make any path changes in the meantime to make sure we don't break working structures. The Travis error is probably releated to a new version of symfony/console |
Right indeed, I knew it wouldn't cover all bases instantly but couldn't think of a good example right away. Why are you using the full git diff? Should the filenames of the files that were changed not be enough? |
The run command uses |
Been thinking about your example of changing files in the root dir and with this PR, that still will not be a problem given that the paths will now always be 'relative' (note the quotes) to the grumphp.yml file. Changing (adding in this example) a file in the root dir will give you this: diff --git a/../hello.php b/../hello.php
new file mode 100644
index 0000000000000000000000000000000000000000..7bf38ca41723f753057d7712a6c0d5f1161fbd17
--- /dev/null
+++ b/../hello.php
@@ -0,0 +1,3 @@
+<?php
+
+echo "hello" So that will still work fine as GrumPHP will show:
|
Given that you do a CD to the folder where |
Ah yes I see, but then there is a mismatch in how pre-commit and run works: pre-commit passes all files in lower folders, but run does only pass those in the cwd. So maybe it's better to introduce a new grumphp parameter, something like: grumphp_operates_in_this_folder. What do you think about that approach? |
So just to clarify by going back to the example in #592:
This would mean that grumphp would only operate on files inside the
which is IMHO very wrong, but still GrumPHP could purr along merrily if we leave the contents of the hook scripts aside (that would be another matter entirely). TL;DR |
The case with multiple project directories is quite hard since the hook files we provide in this package only expect one grumphp file. There will be a lot of edge cases like: what to do when files in multiple microservices change etc. Thanks for your feedback on the issue! |
Believe me, I wouldn't even think of supporting it since as I said it is IMHO very wrong to do such a thing. So what do we do with this PR? Close it? |
Made file objects created from a git diff rely on the absolute path of the file: |
This PR will make sure the paths generated by the git diff command in the
commit-msg
and thepre-commit
hooks will be relative to where GrumPHP is being executed based on thegrumphp.yml
config file, see #592 for a full description of the problem.