How to replace local git hooks with updated versions with git init?

对着背影说爱祢 提交于 2019-12-19 05:45:15

问题


I have exactly the same question as this user here:

git init template, replacing modified hooks

I have a new template file in my global git hooks. However, the original template file was already loaded, so git init does not overwrite. I read the same here, this appears to be the correct git behaviour:

From http://www.cs.potsdam.edu/cgi-bin/man/man2html?1+git-init:

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.

So what is a good way to force reloading new git template hooks? I have many hooks in many git repos, on several computers and used by a variety of users. The most practical way is to have the users run a specific command, rather than telling them to remove the hook first and then run the git init command. Is there a way of doing this?


回答1:


The most practical way is to have the users run a specific command, rather than telling them to remove the hook first and then run the git init command

In that case, a possible way would be to distribute to those users a script which does just that (you could version that script in each of your repo).
Instead of doing the git init directly, they would call that script which would:

  • remove the hooks
  • call the git init --template=

But beware of the path you are using with the --temaplate option.
A relative pathname given to "git init --template=<path> <repo>" ought to be relative to the directory "git init" gets invoked in, but it instead was made relative to the repository, which has been corrected with Git 2.22.1 (Q2 2019).

See commit e1df7fe (10 May 2019) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit 35d7715, 25 Jul 2019)

init: make --template path relative to $CWD

During git-init we chdir() to the target directory, but --template is not adjusted.
So it's relative to the target directory instead of current directory.

It would be ok if it's documented, but --template in git-init.txt mentions nothing about this behavior.
Change it to be relative to $CWD, which is much more intuitive.



来源:https://stackoverflow.com/questions/10791486/how-to-replace-local-git-hooks-with-updated-versions-with-git-init

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!