gpt4 book ai didi

node.js - 可选的 githook 表现为非可选的

转载 作者:搜寻专家 更新时间:2023-10-31 23:45:47 24 4
gpt4 key购买 nike

我正在尝试使用 this gist在我的工作流程中作为 post-mergepost-checkout git hooks。

#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com

# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.

changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"

check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}

# Example usage
# In this example it's used to run `npm install` if package.json changed
check_run package.json "npm install"

这声称只有当 package.json 文件被更改时才会运行 npm install。

但是在我试过的所有机器上。无论 package.json 是否已更改,npm install 命令都会运行。

为了测试这一点,我在当前提交时创建了一个新分支,然后检查它,从而触发 post-checkout git hook。我不希望 npm install 运行,因为 package.json 未更改。

视觉证明(注意 npm 警告文本):

enter image description here

最佳答案

ORIG_HEAD 应替换为 HEAD@{1},如 question 中所述ORIG_HEAD 是一种较旧的、不太可靠的方法,用于获取 HEAD 的先前状态。在我的例子中,它没有被设置。

关于node.js - 可选的 githook 表现为非可选的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43876375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com