question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support changing directory before hook installation

See original GitHub issue

Background

I’m tinkering with adding a pre-commit hook for the wonderful Mega-Linter project (a Python/Docker/Node hard fork of the Shell-based GitHub Super-Linter).

The Mega-Linter has a Node CLI, however the package.json for it lives in a mega-linter-runner subdirectory of the root folder of Mega-Linter repo. This means, per the pre-commit Node docs, it can’t be installed:

The hook repository must have a package.json. It will be installed via npm install .

Questions

  1. Can the install hook be customized so that I can point at the subdirectory via hook metadata?

  2. If not - what are my other options? The CLI mostly just wraps a Docker image, so I’ve gotten that to work directly with a local hook:

    repos:
    - repo: local
        hooks:
          - id: mega-linter
            name: Mega-Linter
            language: docker_image
            entry: -e DEFAULT_WORKSPACE=/src nvuillam/mega-linter:v4
    

    I don’t love this experience though, as it breaks the abstraction layer of the CLI. I also think hooks are way more discoverable and adopted when there is a .pre-commit-hooks.yaml in the root of the repo, indicating a known method of use for pre-commit users, vs using a local hook.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Mar 29, 2021

yeah that’s the breaks I guess 🤷 – if the upstream doesn’t want to support it they have every right not to. and if their tool is poorly designed / difficult to maintain that’s on them

additionally if your thing can’t be installed using the vanilla installation tools for the language it’s written in, there’s probably a bigger problem. adding complexity here pushes in the wrong direction (making this tool harder to maintain) instead of nudging maintainers towards making their tool easier to work with for everyone

I have no interest in getting into changing directories, environment variable substitution, installer flags, etc. – these are all error prone, difficult to configure, big potential for security issues, and for the 99% not necessary

0reactions
tpansinocommented, Mar 29, 2021

Fair enough! And thank you for taking the time to respond.

Read more comments on GitHub >

github_iconTop Results From Across the Web

change directory in bash is not affecting the post-commit hook
Git runs the hook in a subshell and there is no way at that point to change the parent shell's environment directly. ·...
Read more >
pre-commit
You specify a list of hooks you want and pre-commit manages the installation and execution of any hook written in any language before...
Read more >
Git Hooks | Atlassian Git Tutorial
git directory). This lets you edit them like any other version-controlled file. To install the hook, you can either create a symlink to...
Read more >
githooks Documentation - Git
Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working...
Read more >
AppSpec 'hooks' section - AWS CodeDeploy
BeforeInstall – Use to run tasks before the replacement task set is created. ... C:\ProgramData\Amazon\CodeDeploy\deployment-instructions folder on Windows ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found