【问题标题】:How to create a makefile to share githooks如何创建一个makefile来共享githooks
【发布时间】: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 之前是否存在.gitln 不会创建目录。
  • 是的,确实存在。
  • find 由于-maxdepth 选项不显示链接。您应该使用-maxdepth 2 来找到它。

标签: git shell makefile pre-commit-hook


【解决方案1】:

有两个问题。

  1. 配方中的每一行都在单独的 shell 中执行; root 在第一个 shell 中定义,但不在执行 ln 的 shell 中定义。整个脚本需要在配方中的一个 逻辑 行中。

  2. $(pwd) 尝试在执行该行之前扩展名为 pwd 的 Makefile 变量。要保留命令替换,请将$ 加倍:$$(pwd)。同样,需要$$root 传递$root 以使shell 扩展。现在,$root 正在尝试扩展同样未定义的 Makefile 变量 r,然后是文字文本 oot

正确的食谱应该是

githooks:
        root="$$(pwd)"; \
        ln -s "$$root/.githooks" "$$root/.git/hooks"

【讨论】:

  • 我试过了,没用。我已经更新了questin中的详细信息。
猜你喜欢
  • 2011-12-27
  • 2014-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-27
  • 2012-02-15
  • 1970-01-01
相关资源
最近更新 更多