【发布时间】:2020-02-05 00:48:45
【问题描述】:
我创建了一个运行 linter 的 pre-commit 钩子。 pre-commit 文件存在于<project>\.githooks\pre-commit.sh 中。现在,我想通过制作文件与团队成员分享这个钩子
所以在makefile中我做了
.PHONY: all githooks
githooks:
root="$(pwd)"
ln -s "$root/.githooks" "$root/.git/hooks"
我收到错误
$ make githooks
root=""
ln -s "oot/.githooks" "oot/.git/hooks"
ln: oot/.git/hooks: No such file or directory
make: *** [githooks] Error 1
看起来我没有将$pwd 读入变量并且我无法加入 2 个字符串。我将如何在makefile 中做到这一点?
更新:
我已经把钩子改成了
githooks:
root="$$(pwd)"; \
ln -s "$$root/.githooks" "$$root/.git/hooks"
这是make文件的输出
[ 1:31PM ] [ ~ ]
$ make githooks
root="$(pwd)"; \
ln -s "$root/.githooks" "$root/.git/hooks"
[ 1:32PM ] [ ~ ]
$ find . -maxdepth 1 -type l -ls
find 命令没有返回任何链接。我试过git commit,但钩子没有触发。
【问题讨论】:
-
很确定该查找没有返回任何链接,因为您正在查看链接目标所在的根目录,而不是指向该目标的链接所在的 .git 目录。
-
在运行
make githooks之前是否存在.git?ln不会创建目录。 -
是的,确实存在。
-
find由于-maxdepth选项不显示链接。您应该使用-maxdepth 2来找到它。
标签: git shell makefile pre-commit-hook