commit-msg 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
  3. set -x
  4. fi
  5. if [ "$LEFTHOOK" = "0" ]; then
  6. exit 0
  7. fi
  8. call_lefthook()
  9. {
  10. if test -n "$LEFTHOOK_BIN"
  11. then
  12. "$LEFTHOOK_BIN" "$@"
  13. elif lefthook.exe -h >/dev/null 2>&1
  14. then
  15. lefthook.exe "$@"
  16. elif lefthook.bat -h >/dev/null 2>&1
  17. then
  18. lefthook.bat "$@"
  19. else
  20. dir="$(git rev-parse --show-toplevel)"
  21. osArch=$(uname | tr '[:upper:]' '[:lower:]')
  22. cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
  23. if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe"
  24. then
  25. "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe" "$@"
  26. elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe"
  27. then
  28. "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe" "$@"
  29. elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe"
  30. then
  31. "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe" "$@"
  32. elif test -f "$dir/node_modules/lefthook/bin/index.js"
  33. then
  34. "$dir/node_modules/lefthook/bin/index.js" "$@"
  35. elif go tool lefthook -h >/dev/null 2>&1
  36. then
  37. go tool lefthook "$@"
  38. elif bundle exec lefthook -h >/dev/null 2>&1
  39. then
  40. bundle exec lefthook "$@"
  41. elif yarn lefthook -h >/dev/null 2>&1
  42. then
  43. yarn lefthook "$@"
  44. elif pnpm lefthook -h >/dev/null 2>&1
  45. then
  46. pnpm lefthook "$@"
  47. elif swift package lefthook >/dev/null 2>&1
  48. then
  49. swift package --build-path .build/lefthook --disable-sandbox lefthook "$@"
  50. elif command -v mint >/dev/null 2>&1
  51. then
  52. mint run csjones/lefthook-plugin "$@"
  53. elif uv run lefthook -h >/dev/null 2>&1
  54. then
  55. uv run lefthook "$@"
  56. elif mise exec -- lefthook -h >/dev/null 2>&1
  57. then
  58. mise exec -- lefthook "$@"
  59. elif devbox run lefthook -h >/dev/null 2>&1
  60. then
  61. devbox run lefthook "$@"
  62. else
  63. echo "Can't find lefthook in PATH"
  64. fi
  65. fi
  66. }
  67. call_lefthook run "commit-msg" "$@"