Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 始终跳过链接到自定义脚本的npm安装的预推挂钩_Git_Npm_Hook_Package.json - Fatal编程技术网

Git 始终跳过链接到自定义脚本的npm安装的预推挂钩

Git 始终跳过链接到自定义脚本的npm安装的预推挂钩,git,npm,hook,package.json,Git,Npm,Hook,Package.json,我想阻止所有开发人员执行git推送到主控(不包括强制)。我没有要求每个人在.git/hooks文件夹中创建一个预推文件,而是希望使用npm自动化这个过程,并将所需的文件添加到远程git存储库中 我在package.json中添加了“pre-push”,它指向一个自定义脚本 "pre-push": { "run": [ "prepushscript" ] }, "scripts": { "start": "node app.js", "test": "node_modul

我想阻止所有开发人员执行git推送到主控(不包括强制)。我没有要求每个人在.git/hooks文件夹中创建一个预推文件,而是希望使用npm自动化这个过程,并将所需的文件添加到远程git存储库中

我在package.json中添加了“pre-push”,它指向一个自定义脚本

"pre-push": {
  "run": [
    "prepushscript"
  ]
},

"scripts": {
  "start": "node app.js",
  "test": "node_modules/.bin/gulp test",
  "prepushscript": "prepushscript"
},

"devDependencies": {
  .
  .
  "pre-push": "^0.1.0",
  .
  .
}
注意:自定义脚本prepushscript与package.json处于相同的文件级别

prepushscript文件相当简单

protected_branch='master'  
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')

if [ $protected_branch = $current_branch ]  
then  
    echo "Error: You are attempting to push to a protected branch."
exit 1 # push will not execute
fi
自定义脚本之所以有效,是因为在.git/hooks文件夹中创建本地预推文件并尝试推送到受保护的分支时,会导致看到脚本的回显错误消息。Npm安装也在.git/hooks文件夹中创建符号链接。一旦我在本地master上有了一个准备推送的commit并运行git push,推送就完成了,我得到了以下结果:

pre-push:
pre-push: Failed to find the root of this git repository, cannot locate the `package.json`.
pre-push: Skipping the pre-push hook.
pre-push:
Everything up-to-date
我已经尝试在package.json中用一个简单的echo语句替换prepushscript条目,以查看脚本是否有问题,但是我得到了相同的控制台日志。其他尝试是向prepushscript文件添加扩展名,以查看它是否运行


我无法找出的主要问题是我无法找到错误的来源以及它与package.json的关系。谢谢你的帮助

我在“预推”npm软件包中也遇到了同样的错误。它似乎不像“程序文件”那样,在我的窗口中用空格填充完整的路径。最后我不得不选择“”了。

这行不行:

 this.root = this.exec(this.git, ['rev-parse', '--show-toplevel']);

正在尝试获取“顶级”目录的绝对路径

this.git
包含git可执行文件的路径。当使用git GUI并且它使用自己的嵌入式可执行文件时,就会出现问题。我在使用SourceTree时遇到这个问题,并更改了我的首选项,以便它使用系统可执行文件:

SourceTree>Preferences>Git>使用系统Git(Git版本)

如果您使用的是不同的GUI,请转到其首选项,并确保它使用的是系统可执行文件