2012-09-08 73 views
0

在git中運行預提交鉤子時出現錯誤,我無法弄清楚。這是腳本,錯誤如下。Git預提交鉤子 - 沒有這樣的文件或目錄

#!/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 

這是我收到的錯誤:

.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 

我已經改變了權限的所有文件,以777只是用於測試,並檢查CR的任何地方,而我仍然得到錯誤。奇怪的部分是當我運行命令,從給出的錯誤,我沒有問題

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 

將工作得很好。

希望有人能看到我不能做的事。

回答

0

你可能想:

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

否則你告訴慶典在路徑「/home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /家庭/約翰/執行二進制Projects/node/test/public/javascripts/editor.min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js「,這正是錯誤消息所說的內容,但可能有點令人困惑,因爲錯誤消息不包括引號,這只是在參數分析過程中使用的。所以在這種情況下,bash最終會看到一個只有一個參數(執行程序的路徑)的命令,這個參數很長且不存在。

相關問題