Skip to content
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

Use git’s core.hooksPath capability to store hook scripts in the repository #61

Open
lstrojny opened this issue Mar 18, 2022 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers ready This issue is ready for us to code on it

Comments

@lstrojny
Copy link

mookme init writes the actual git hook scripts into .git/hooks. Since 2.9, git itself supports changing the path in which git looks up the hooks scripts to some place in the repository. E.g. mookme could place it’s scripts under .hooks/scripts and run git config core.hooksPath .hooks/scripts to make git read from these scripts.
Storing the scripts directly in the repository allows modifying them, e.g. for integration with git-lfs hooks.

@LMaxence
Copy link
Member

Wow I didn't know that !

One question that come in my mind as I read this:

  • What happens to the default .git/hooks/*.sh files that are used ? Mookme comes with the promise that it won't mess up with anything that would already be written in the .git folder, but this might go in the total opposite direction
  • 2.9 seems to be an already quite old version, but we'll need to handle former versions of git probably ?

@lstrojny
Copy link
Author

What happens to the default .git/hooks/*.sh files that are used ? Mookme comes with the promise that it won't mess up with anything that would already be written in the .git folder, but this might go in the total opposite direction

They would be ignored. The config setting basically says "look up hooks scripts in this folder" and nowhere else.

@LMaxence
Copy link
Member

Okay then this should probably an option for the init command. Or a question in the init commit asking if the user wants to set this git config option to something. If provided, it would then:

  • run the git config command in the repo doing the initialization
  • store a parameter with this path in the .mookme.json config file
  • run the git config command in the repo when someone runs mookme init --only-hook

@lstrojny
Copy link
Author

lstrojny commented Mar 18, 2022

That sounds good indeed! That way mookme init --only-hooks would just lookup the path from the config and only add hooks if they are missing.

@lstrojny
Copy link
Author

Scratch that,

if (!hook.includes(mookmeCmd)) {
should already handle it sufficiently.

@LMaxence LMaxence added enhancement New feature or request good first issue Good for newcomers labels Mar 19, 2022
@LMaxence
Copy link
Member

Description

We want to exploit the git option core.hooksPath, to enable the hooks scripts to be commited, or written somewhere else.

Use case 1: I am the first on my project to setup Mookme

  • run the git config command in the repo doing the initialization
  • store a parameter with this path in the .mookme.json config file

Use case 2: I cloned a repo with mookme in it, and the option is set in .mookme.json

  • run the git config command in the repo when someone runs mookme init --only-hook
  • the script modification being idempotent, it doesn't matter if the script file is part of the VCS, and thus is already written
  • A very fortunate thing here is that if I setup Mookme to use VCS scripts, nothing is needed otherwise than running the git config command for mookme to be setup in a freshly-cloned repository.

Todos

  • [Preliminary] -> We need to refacto the GitToolkit.writeGitHooksFiles method so that it accepts an optional argument folderPath, defaulting to the actual value used in the function (${this.rootDir}/.git)
  • In the init command, add a prompter asking if the user wants to configure the core.hooksPath for this project (ie change the location of the script files). Then if yes, it is prompted to enter a relative path from the git folder, and we ensure this path exists (using inquirer's validate question option
  • If the user answers no, it defaults to .git/hooks
  • If it is yes, the value is written in .mookme.json under gitScriptsFolder, and it is used at the end when writing hook shell script files
  • In the init command, when --only-hook is called, we retrieve the value of gitScriptsFolder, and if it exists, we pass it to writeGitHooksFiles

@LMaxence
Copy link
Member

That remains a piece of work, but I'll leave it as available for newcomers because it does not impact crucial parts of the code and is relatively well-scoped.

No need to do all of this in one single merge request, it is possible to move on with this step by step !

@LMaxence LMaxence added the ready This issue is ready for us to code on it label Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers ready This issue is ready for us to code on it
Projects
None yet
Development

No branches or pull requests

2 participants