2016-11-15 261 views
0

我写了shell脚本,我试图把这个脚本作为客户端钩子脚本,但没有得到脚本引擎哪一个我应该用来运行.sh文件。通常情况下,我已经看到.js文件将被用作SVN的钩子脚本,不幸的是我不太了解jscript,所以请帮助我如何在SVN中添加和运行脚本作为客户端钩脚本。我尝试过使用WSciptCScirpt但是它们不适用于我的shell脚本。如何运行shell脚本作为tortoiseSVN的客户端钩脚本?

#!/bin/bash 

MAIN_DIR="/cygdrive/e/Trunk/COMMON" 
FILE_NAME="/cygdrive/e/Trunk_PRE_COMMIT_HOOK/long_path.txt" 



lengthy_path=`find ${MAIN_DIR} -regextype posix-extended -regex '.{500,}'| awk -F'Trunk/' '{print $2}' > ${FILE_NAME}` 



if [ -f ${FILE_NAME} ] 
    then 
    if [ -s ${FILE_NAME} ] 
    then 
     echo -e "\n\n\nSorry the path of a file exceeds 256 charectors, please make it shorten and try commiting again.You can see the path in $FILE_NAME" 
    else 
     echo -e "\n\n\nPath is perfect code can be committed..........." 
fi 
    else 
     echo -e "\n\n\nFile not exists............" 
fi 
+1

[客户端挂钩脚本只有在使用TortoiseSVN时才有可能](http://stackoverflow.com/a/8490859/1698557),或者[自动包装/混淆svn命令本身](http:// www.pal-blog.de/entwicklung/perl/better-source-svn-client-side-precommit-hooks.html)。 –

+0

@PatrickQuirk是的,忘了提及我只使用了Tortoise SVN,请让我知道当开发人员试图将代码提交到repo时,哪个脚本引擎需要用来运行.sh脚本。 –

+0

发布您的脚本。文件扩展名大部分是没有意义的。 –

回答

1

你试图执行Windows上的bash脚本,这意味着你要么需要安装了Cygwin或可以使用新的bash shell functionality in Windows 10。我对这两者都没有经验,但希望我能让你指出正确的方向。

  1. 如果你使用Cygwin,在龟钩脚本配置对话框中使用以下命令(图中the documentation 4.87):

    C:\cygwin\bin\bash C:\path\to\your_script.sh 
    

    (从this answer来源)

  2. 如果您使用的是Windows 10 bash shell,请使用以下命令:

    bash -c "/mnt/c/path/to/your_script.sh" 
    

声明(在“运行Linux命令来自外部的打击”从this page来源):因为我没有时间或方式我没有测试过其中任一。试一试,并留下一些反馈。

+0

其实我已经试过你上面提示的方式了; C:\ cygwin \ bin \ bash C:\ path \ to \ my_script.sh但是不幸的是它返回下面的错误“FIND:无效开关”,如果它得到解决,我认为脚本将通过..我已经检查,在cygwin fInd.exe也存在.. –

+0

您的脚本正在调用Windows的'find'命令而不是cygwin's。用'/ bin/find'或'/ usr/bin/find'替换'find',无论哪个存在。 –