简体   繁体   English

Git提交前挂钩-没有此类文件或目录

[英]Git Pre-Commit Hook - No such file or directory

I am getting an error when running a pre-commit hook in git, that I can't figure out. 在git中运行预提交钩子时出现错误,我无法弄清。 This is the script and the error is below. 这是脚本,下面是错误。

#!/bin/bash

# Pre-commit hook passing files through jslint and uglify

#ROOT_DIR=$(git rev-parse --show-toplevel)
JSLINT="/home/john/Projects/node/uglify/node_modules/.bin/jslint --indent 4 --white true -nomen"
UGLIFYJS="/home/john/Projects/node/uglify/node_modules/.bin/uglifyjs"
JS_TEMP_EDITOR="/home/john/Projects/node/test/generated/tmp/_combined_editor.js"
JS_COMBINED_EDITOR="/home/john/Projects/node/test/public/javascripts/editor.min.js"

# Where the editor files are located
BASE="/home/john/Projects/node/test/public/javascripts/editor/"
EDITOR=(
    "init.js"
    "utils.js"
    "validation.js"
    "main.js"
    "menu.js"
    "graph.js"
    "settings.js"
    "interview.js"
    "list.js"
    "thumbnail.js"
)

# go through each javascript file that has changed and run it rhough JSLINT
for file in $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P '\.((js)|(json))$'); do
    if  ! node $JSLINT $file 2>&1 | grep ${file}' is OK.' ; 
    then
        node $JSLINT $file
        exit 1
    fi  
done


# Erase old
> $JS_TEMP_EDITOR
> $JS_COMBINED_EDITOR

#run thru the EDITOR and cat the files into one
for editor_file in ${EDITOR[@]}; do
  cat "$BASE/$editor_file" >> $JS_TEMP_EDITOR
done


# check if  UGLIFYJS gives us an error
if node $UGLIFYJS $JS_TEMP_EDITOR 2>&1 | grep 'Error' ; 
then
    exit 1
else
        # *** THIS IS WHERE THE ERROR IS THROWN
    "node $UGLIFYJS -o $JS_COMBINED_EDITOR $JS_TEMP_EDITOR"
fi

exit 0

This is the error I am getting: 这是我得到的错误:

.git/hooks/pre-commit: line 55: node /home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /home/john/Projects/node/test/public/javascripts/editor.min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js: No such file or directory

I have changed the permissions of all the files to 777 just for testing, and also checked for CR's anywhere, and I still get the error. 我已经将所有文件的权限更改为777,仅用于测试,还检查了CR的任何位置,但仍然出现错误。 The weird part is when I run the command, from the error given, I get no problem ! 奇怪的是,当我运行命令时,从给出的错误中我没问题

node /home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /home/john/Projects/node/test/public/javascripts/editor.min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js

will work just fine. 会很好。

Hopefully someone can see something that I can't. 希望有人能看到我看不到的东西。

You probably want: 您可能想要:

node "$UGLIFYJS" -o "$JS_COMBINED_EDITOR" "$JS_TEMP_EDITOR"

Otherwise your telling bash to execute a binary at path "/home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /home/john/Projects/node/test/public/javascripts/editor.min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js" which is just what the error message says but maybe a bit confusing as the error message don't include the quotes, that is just used during argument parsing. 否则,您告诉bash在路径“ /home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /home/john/Projects/node/test/public/javascripts/editor.min.js”执行二进制文件/home/john/Projects/node/test/generated/tmp/_combined_editor.js“,这正是错误消息所说的内容,但由于错误消息不包含引号而引起混淆,这只是在参数解析期间使用。 So in this case bash ends up seeing a command with just one argument (path to the program to execute) that is very long and does not exist. 因此,在这种情况下,bash最终会看到一个命令,该命令只有一个参数(执行的程序路径),该参数很长且不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM