如何解决Git Post Commit 挂钩将更改的文件转换为变量
这里是 Git Hook 新手
我有一个 git post-commit 钩子,我正在修改文件。我想在一个变量中获取文件路径+文件名(减去扩展名)。然后将此变量传递给转换器
#!/bin/bash
#.git/hooks/post-commit
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook,rename this file to "post-commit".
echo "post-commit started"
IFS=$'\n'
git diff --name-only HEAD^ HEAD | grep '\.json$' |
while read file; do
echo "$file"
A="$file" | cut -d'.' -f 1
#Don't get anything in A
echo "$A"
B="$A" +".html"
#Don't get anything in B
echo "$B"
## Python to convert goes here
## generate-schema-doc $A $B
done
echo "post-commit finished"
解决方法
这不是关于 git hooks,而是关于 bash 语言。 首先这一行:
A="$file" | cut -d'.' -f 1
$file
可能不是 shell 命令,即使是,您也应该指示 shell 您要实际执行它。
A=`echo "$file" | cut -d "." -f 1`
您在加入 $A
和 .html
时遇到另一个错误。您可以通过以下方式简化:
B="$A.html"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。