GIT (HUSKY): exit code when a file is being committed?
Asked Answered
G

1

0

is there a way to check if a file is being committed and exit with an error ?

I have a file in git that needs to be there but should never be modified and i was hoping to use husky as a pre-commit - so if anybody tries to modify the file and commit then it would throw an error.

If in future I need to modify the file then i can just disable the pre-commit.

the file is a configuration that i need to edit a lot when developing but the changes should never be committed.

I was hoping to use husky as a check to ensure that i dont.

Gyrostatics answered 11/1, 2019 at 4:19 Comment(0)
L
0

I would rather manage sure a file with a content filter driver, using .gitattributes declaration.

That means you do not version the actual configuration file, but only a template file, and a file with all possible values per environment.

smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

The generated actual file remains ignored (by the .gitignore): your actual working tree does not get "dirty".

The smudge script:

  • detect the right environment (not the branch, since only one is needed)
  • selects the correct value file and generates the correct file based on the template the smudge script is applied on during a git checkout.

That way, you modify the config.dev value file as much as you want when developing: the config file (not versioned) will be generated from those values.
But in production, a checkout of that same repo will trigger the generation of a prod config file, using the config.prod (versioned file) values.

Levitan answered 11/1, 2019 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.