Comments (10)
@sebastianfeldmann, thanks a lot for your help and investigation here.
I fear I did not explain our setup properly enough. Thought, it would be unimportant, but it seems to make a difference.
The modules, I'm talking about, are no proper git submodules. They are included via composer, but required with the --prefer-source
flag. So they live, like normal composer requirements, in vendor
, but they include a .git
folder on their own.
You can reproduce that with any composer module, just run composer require XXX --prefer-source
.
And for these, we would like to have the same hooks as we have for our composer project.
Would you be so kind and try that with your approach? I think, there, you will have the same problem as I mentioned before. Please let me know your findings.
Thanks a lot again for your help here, I know, this is a pretty rare and unusual case, we have here, but we did not find any other way for our project.
from captainhook.
@sebastianfeldmann, thanks a lot for your help here. Really awesome.
I just tested, and your last approach seems to work fine for us, and it looks a bit easier than the first one.
Again, thank you so much.
Will let you know, as soon as something strange comes up in that process.
from captainhook.
I checked that further and found out, that it is not related to the general setup, but to the actual tests we're running.
We're using a condition for phpcs to only check files changed of type PHP.
As soon as I remove this condition, the hook works fine.
Is there a good explanation for that?
from captainhook.
The Cap'n needs git
to figure out the changed files. Is git available within your container and has access to the .git
directory?
from captainhook.
@sebastianfeldmann, thanks for your reply.
I don't see a reason why the captain should not have access.
Like I said, when I run the command manually, there is no problem.
I now debugged into \CaptainHook\App\Hook\Condition\FileChanged\OfType::isTrue
, which is in my eyes the problematic point.
I "var_dumped" the $repository
during the push of my sub-repository changes, and see the following:
That seems to be the project repository and not the sub-repository in the vendor
folder.
How does the captain decide, which repo to take? As I push my sub-repository, I would expect him to use this one.
from captainhook.
🤔 I never worked with submodules
So normally the Cap'n looks for the default path ./.git
. You can specify a custom path to your .git directory.
--
So i played around with submodules a little bit.
Adding a submodule to a repository adds a git-directory in your git-directory normally unter .git/modules/MODULE_NAME
You have to install the hook there as well to .git/modules/MODULE_NAME/hooks
In my tests the captainhook install
command did not work properly.
Only adjusting the hook scripts manually made it work.
I will try to figure out a way to make the install command work properly.
Here is my manually adjusted pre-commit hook script for my submodule, the important parts are the ../
in front of the command and the configuration option.
#!/bin/sh
# installed by CaptainHook 5.23.0
INTERACTIVE="--no-interaction"
# read original hook stdIn to pass it in as --input option
input=$(cat)
if [ -t 1 ]; then
# If we're in a terminal, redirect stdout and stderr to /dev/tty and
# read stdin from /dev/tty. Allow interactive mode for CaptainHook.
exec >/dev/tty 2>/dev/tty </dev/tty
INTERACTIVE=""
fi
../vendor/bin/captainhook $INTERACTIVE --configuration=../captainhook.json --bootstrap=vendor/autoload.php --input="$input" hook:pre-commit "$@"
from captainhook.
If you run the install from the submodule the Cap'n will figure it out.
../vendor/bin/captainhook install --configuration=../captainhook.json
The only disadvantage I see is that the Cap'n copies the absolute path from the submodule .git
file similar to additional worktrees. This means you can not move your project to another directory without re-installing the submodule hooks.
from captainhook.
So here is how you can do it:
My file structure looks like this
tools
├─ captainhook
vendor
├─ namespace
│ ├─ package
│ │ ├─ .git
│ │ ├─ ...
├─ autoload.php
captainhook.json
composer.json
when inside vendor/namespace/package
run
../../../tools/captainhook install --bootstrap ../../autoload.php
this requires the package to bring their own captainhook.json
.
If you want to use the same config as the main project you have to reverence the config and adjust your bootstrap path
../../../tools/captainhook install --configuration=../../../captainhook.json --bootstrap=vendor/autoload.php
because the bootstrap path is checked from the configuration location.
from captainhook.
Another option is to run this command from the main project root.
tools/captainhook install --git-directory=vendor/namespace/package/.git
All of them worked on my machine ;)
from captainhook.
Perfect, I will close this. Feel free to reopen it if you encounter any problems :)
from captainhook.
Related Issues (20)
- Using $ENV in run-exec config HOT 3
- Support for Relative Path to CaptainHook Executable in Generated Hooks HOT 5
- Allow Staged and Changed files condition to define diff-filter HOT 1
- PHP Fatal error: Argument #2 ($filter) must be of type array HOT 7
- InjectIssueKeyFromBranch does not work as expected HOT 10
- http://captainhook.info is not available anymore? HOT 1
- Support Symfony 7 HOT 2
- $CHANGED_FILES placeholder is empty for first push HOT 1
- [FEATURE-REQUEST] New placeholder `ALL_CHANGED_FILES` HOT 17
- Docker mode not working? HOT 9
- Linting fails when it shouldn't? HOT 3
- Default config file does not work HOT 3
- Error 'The "--input" option does not exist' when rerunning the hooks HOT 1
- captainhook/captainhook-phar failing, prefer captainhook/captainhook in README HOT 3
- Execute PHAR hook installation without an autoloader HOT 9
- [Feature] Parallel execution of actions HOT 1
- [Bug?] Pre-push hook failing with ddev/docker HOT 4
- Installation not working behind a proxy
- Install fails with a missing class HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from captainhook.