new-githook.shell 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/sh
  2. if [ ! -e /data/go/bin ];then
  3. echo "/data/go/bin 目录不存在, 正在创建"
  4. echo "mkdir -p /data/go/bin"
  5. mkdir -p /data/go/bin
  6. echo "chmod 777 -R /data/go/bin"
  7. chmod -R 777 /data/go/bin
  8. fi
  9. CURDIR=`pwd`
  10. echo "当前目录:${CURDIR},开始执行创建git hook 脚本"
  11. GitPath="${CURDIR}/.git"
  12. if [ ! -d $GitPath ]; then
  13. echo "请执行 git init 初始化git 项目"
  14. exit -1
  15. fi
  16. GitHookPath="${CURDIR}/.git/hooks"
  17. if [ ! -d $GitHookPath ]; then
  18. echo "$GitHookPath 不存在"
  19. exit -1
  20. fi
  21. # 下载脚本
  22. curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/code.shell
  23. curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/message.shell
  24. # copy 文件,如果存在,则备份历史文本
  25. # commit go 文件检测,脚本
  26. GitCommitCheckPath="${GitPath}/hooks/pre-commit"
  27. GitCommitCheckOldPath="$GitCommitCheckPath.old"
  28. if [ -f $GitCommitCheckPath ]; then
  29. echo "cp $GitCommitCheckPath $GitCommitCheckOldPath"
  30. cp $GitCommitCheckPath $GitCommitCheckOldPath
  31. fi;
  32. echo "mv code.shell $GitCommitCheckPath"
  33. mv code.shell $GitCommitCheckPath
  34. chmod 755 $GitCommitCheckPath
  35. # commit 消息脚本
  36. GitCommitMessagePath="${GitPath}/hooks/commit-msg"
  37. GitCommitMessageOldPath="$GitCommitMessagePath.old"
  38. if [ -f $GitCommitMessagePath ]; then
  39. echo "cp $GitCommitMessagePath $GitCommitMessageOldPath"
  40. cp $GitCommitMessagePath $GitCommitMessageOldPath
  41. fi;
  42. echo "mv message.shell $GitCommitMessagePath"
  43. mv message.shell $GitCommitMessagePath
  44. echo "chmod 755 $GitCommitMessagePath"
  45. chmod 755 $GitCommitMessagePath
  46. GoFmtPath=/data/go/bin/gofmt
  47. if [ ! -f $GoFmtPath ];then
  48. echo "curl -o $GoFmtPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/gofmt"
  49. curl -o $GoFmtPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/gofmt
  50. echo "chmod 777 $GoFmtPath"
  51. chmod 777 $GoFmtPath
  52. fi
  53. GoImportPath=/data/go/bin/goimports
  54. if [ ! -f $GoImportPath ];then
  55. echo "curl -o $GoImportPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/goimports"
  56. curl -o $GoImportPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/goimports
  57. echo "chmod 777 $GoImportPath"
  58. chmod 777 $GoImportPath
  59. fi
  60. GoLinePath=/data/go/bin/golint
  61. if [ ! -f $GoLinePath ];then
  62. echo "curl -o $GoLinePath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/golint"
  63. curl -o $GoLinePath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/golint
  64. echo "chmod 777 $GoLinePath"
  65. chmod 777 $GoLinePath
  66. fi
  67. # https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/gofmt
  68. # https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/goimports
  69. # https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/golint
  70. # rm ./.git/hooks/pre-commit
  71. # rm ./.git/hooks/commit-msg
  72. # curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/code.shell
  73. # curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/message.shell
  74. # mv code.shell ./.git/hooks/pre-commit
  75. # chmod 755 ./.git/hooks/pre-commit
  76. # mv message.shell ./.git/hooks/commit-msg
  77. # chmod 755 ./.git/hooks/commit-msg
  78. echo "执行完成,请创建 git hook 脚本成功,请提交代码试一试 .... "