[英]Git hook on Ubuntu broken
I recently got a git hook from someone that aims to add the issue number, which is in a specific location of the branch name, to the beginning of all commits.我最近从某人那里得到了一个 git hook,旨在将问题编号(位于分支名称的特定位置)添加到所有提交的开头。 The goal is to take the #number
from feature/#number-issue
.目标是从feature/#number-issue
获取#number
。 Here is some info:这是一些信息:
➜ .githooks pwd
/home/luctia/.githooks
➜ .githooks git config --global --list
user.name=luctia
user.email=myemail
core.hookspath=/home/luctia/.githooks
➜ .githooks cat commit-msg
#!/bin/sh
WI=$(git status --branch | grep -iPo "(feature|bug)\/#\d+" | head -1)
WI=$(echo "($WI)" | grep -Po "\d+")
if [[ ! -z "$WI" ]]; then
WI="#$WI"
CM=$(cat "$1")
if [[ ! $CM == *"$WI "* ]]; then
echo "$WI $CM" > "$1"
fi
fi
This doesn't seem to work, though.不过,这似乎行不通。 The script is executable for every user, so that's not the issue.该脚本对每个用户都是可执行的,所以这不是问题。 I have tried switching from sh
to bash
, and with that edit I've executed the script on a file in a repo, which added the number to the beginning of the file, so I know it works.我尝试从sh
切换到bash
,并且通过该编辑,我在 repo 中的文件上执行了脚本,该脚本将数字添加到文件的开头,所以我知道它有效。 I'm not sure if git hooks can execute bash files, but it doesn't make a difference whether I use sh
or bash
, though I would like to know if it can run bash scripts.我不确定 git hooks 是否可以执行 bash 文件,但是我使用sh
还是bash
并没有什么区别,尽管我想知道它是否可以运行 bash 脚本。
I'm using Webstorm for my IDE right now, and it doesn't work in there, and it also doesn't work on CLI git.我现在正在为我的 IDE 使用 Webstorm,它在那里不起作用,它也不适用于 CLI git。 I have no idea how to proceed.我不知道如何继续。
Edit: I am pretty sure the script is not executed.编辑:我很确定脚本没有执行。 When I add data > /tmp/hook
to the script, no file appears.当我将data > /tmp/hook
添加到脚本时,没有文件出现。 I do have to change from sh
to bash
though.不过,我确实必须从sh
更改为bash
。
The problem was that I was trying to make this work on a pre-existing project, with an existing .git
directory.问题是我试图在一个已有的项目上使用现有的.git
目录进行这项工作。 I thought changing the config with the --global
flag would just work, but apparently the config inside the .git
directory of the project did not change, and the old hookspath
was still there.我认为使用--global
标志更改配置会起作用,但显然项目的.git
目录中的配置没有更改,并且旧的hookspath
仍然存在。 When I changed it, the script started working.当我更改它时,脚本开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.