0

Is it possible to have one or more files in a git repository that can be changed but not deleted or renamed? The use case is about a repository setup where multiple env files can only be tweaked by developers but prevent them to accidentally delete or rename the files as the CI would break without them with that exact name.

One idea I had was to write some sort of bash or node script and hook it in a pre-commit git hook with husky, but I am not sure how would that script would look like yet. Another idea was to initially set the right file permissions on the env files but I am not sure those would be retained in a git repository cloned on different OS platforms.

Anyway maybe there are some more idiomatic and smart ways to do this. Quite surprisingly I could not find anything online... So all sorts of creative solutions are accepted if not too cumbersome. thanks!

kuus
  • 453
  • 1
  • 5
  • 15
  • 2
    CI breaking *is* the prevention. You can't (and shouldn't) use Git for this. – user229044 Jul 15 '20 at 14:04
  • Hi @meagar, thx for your comment, would you mind expanding it a bit? How would you approach this? thanks! – kuus Jul 15 '20 at 14:09
  • 1
    If a chance in the repo causes CI to fail, then don't merge that change. You don't need specific checks for specific types of failures, and I wouldn't spend any time trying to prevent people from renaming files. Developers should know not to do that, and if they *do* do it, and CI fails, their changes won't be merged and they won't make the same mistake a second time. – user229044 Jul 15 '20 at 14:37

0 Answers0