Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.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
Node.js Git预提交挂钩未运行_Node.js_Git_Bash_Pre Commit Hook - Fatal编程技术网

Node.js Git预提交挂钩未运行

Node.js Git预提交挂钩未运行,node.js,git,bash,pre-commit-hook,Node.js,Git,Bash,Pre Commit Hook,这是我的预提交挂钩: #!/bin/sh exec node build.js 当我将pre-commit更改为pre-commit.sh并运行它时,该代码工作正常,当我在终端中运行exec node build.js时,它也会正确执行。构建文件工作正常 下面是build.js: var fs = require("fs") var through2 = require('through2'); var markdownPdf = require("markdown-pdf") var rem

这是我的预提交挂钩:

#!/bin/sh
exec node build.js
当我将
pre-commit
更改为
pre-commit.sh
并运行它时,该代码工作正常,当我在终端中运行
exec node build.js
时,它也会正确执行。构建文件工作正常

下面是
build.js

var fs = require("fs")
var through2 = require('through2');
var markdownPdf = require("markdown-pdf")
var removeMarkdown = require("remove-markdown")

var resume = fs.createReadStream("README.md")
var pdf = fs.createWriteStream("Resume - Desmond Weindorf.pdf")
var txt = fs.createWriteStream("Resume - Desmond Weindorf.txt")
var md = fs.createWriteStream("Resume - Desmond Weindorf.md")

process.stdout.write('Building other file types...\n')

// pdf
resume.pipe(markdownPdf({ paperBorder: "1.4cm" })).pipe(pdf)

// txt
resume.pipe(through2(function(line, _, next) {
    this.push(removeMarkdown(line.toString()) + '\n');
    next()
})).pipe(txt)

// md
resume.pipe(md)
我认为它可能会在写入新文件之前提前结束(可能是),但在这种情况下,终端仍应显示初始写入输出

这是我在提交时的输出(pdf事先已更改,以测试是否被新更改覆盖):


我做错了什么?

快速猜测:预提交钩子是在repo中使用PWD执行的。所以它不知道
build.js
在哪里。尝试
exec node/path/to/build.js
@Mort使用完整的文件路径进行了尝试,但这并没有逐步解决问题。是否准确地称为“预提交”?它是否驻留在
.git/hooks/
中?文件是否可执行?在
exec
之前添加
echo pre-commit test
以测试git运行脚本。
chmod+x.git/hooks/pre-commit
并重试
chmod+x
使文件可执行。无论钩子与否,都需要对每个脚本执行此操作。
Desmonds-MacBook-Pro:resume desmond$ git commit -am "updated resume"
[master 7faab35] updated resume
 4 files changed, 36 insertions(+), 34 deletions(-)
 rewrite Resume - Desmond Weindorf.pdf (81%)