Coder Social home page Coder Social logo

Comments (5)

RalfEggert avatar RalfEggert commented on August 30, 2024 1

@sebastianfeldmann

Almost 3 months later, I finally get around to trying it out and it works straight away. Thanks for your effort and work Captain Hook!

👍

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

There is some magic in place checking if we should use relative or absolute path.
The current approach is: If the Cap'n is located within the git repository it will use a relative path. So you are able to move the directory around without any implications.
If the Cap'n is located outside of your repository I'm currently using an absolute path to archive the same result. Being able to move the source files around without any hassle.

    protected function getPathForHookTo(Directory $repo, Path $target): string
    {
        if (!$target->isChildOf($repo)) {
            return '\'' . $target->getPath() . '\'';
        }
        return '__DIR__ . \'/../../' . $target->getRelativePathFrom($repo) . '\'';
    }

I think you are using PHIVE with symlinks meaning PHP will not look at the symlink path, it will look at the real_path meaning the path to the real file. This is was real_path returns.

The config value run-path is currently only used in Docker mode.
I like the idea of using it to specify the executable to call and using it as given without any real_path magic.

A quick fix for you might be to copy the PHAR to ./tools/*. Not perfect but then the path would be added relative.

<phar name="captainhook" version="^5.9" installed="5.9.1" location="./tools/captainhook" copy="true"/>

I will check if the run-path value can be used as is and keep you updated here.

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

I think this already does it but I will improve the install tests a little bit more.
For now I don't have the best feeling not breaking something for somebody else.

from captainhook.

RalfEggert avatar RalfEggert commented on August 30, 2024

@sebastianfeldmann

thanks for your thoughts and efforts so far.

Currently I use the following workaround. I have a small bash script anyway that installs all the necessary tools via phive. I have now extended this. We currently only use the pre-commit hook, so this fits for us.

echo "Run Captain Hook installation"
./tools/captainhook install --configuration=./captainhook.json pre-commit

echo ""
echo "Fix absolute path for Captain Hook in commit hook to local one"
HOOK_FILE=".git/hooks/pre-commit"

if [ -f "$HOOK_FILE" ]; then
  sed -i "s|$HOME/.phive/phars/captainhook-[0-9]*\.[0-9]*\.[0-9]*\.phar|./tools/captainhook|" "$HOOK_FILE"
  echo "The path in $HOOK_FILE was fixed."
else
  echo "Error: $HOOK_FILE does not exist."
fi

The workaround currently works in the team. But of course it would be great if the Cap'n also offers an official way to solve the problem.

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

You can use relative path now by configuring it in run-cmd to overwrite the absolute path behavior.

Release with 5.17.0

from captainhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.