Replies: 1 comment 1 reply
-
Hey! That's a good question. Lefthook always sets the git root as a root for all subcommands. This is crucial because it souldn't matter what folder you are running Why is it important to run git from within different folders? Are you trying to partially commit each folder? I'm just curious. I'd be glad to know more about your use case. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am working on custom Git prepare-commit-msg and commit-msg hook scripts that both need to process the complete list of changed files. This must work for commit, amend, and reword and for both prepare-commit-msg and commit-msg hooks.
I am facing the following issues:
git diff --staged --name-only
returns the list of changed files only for "normal" commits. For amend it returns only the additional changed files. For reword it returns nothing.git diff-tree --no-commit-id --name-only -r $SHA1
returns only the list of changed files of an existing commit. This would allow to collect existing changes during amend in a prepare-commit-msg hook. But due to the lack of a SHA1 it does not work in a commit-msg hook.Therefore I have resorted to parsing the comments about changed files generated by Git into the commit message. This works well when invoking Git from the toplevel directory of the working tree. When invoking Git from a subdirectory the paths of the changed files in the comments are relative to the current working directory.
In theory it would be easy to convert those paths relative to the current working directory back to paths relative to the toplevel directory of the working tree:
But Lefthook apparently invokes Git hook scripts from the toplevel directory of the working tree. Therefore I don't have access to the current working directory the user invoked Git in from within my hook script.
I tried to get Lefthook to execute my hook from the current working directory without success:
To resolve my issue I either need a mean to:
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions