gradle-githook icon indicating copy to clipboard operation
gradle-githook copied to clipboard

Better in use on windows ?

Open abcfy2 opened this issue 6 years ago • 5 comments

If I use powershell, git hook shows:

error: cannot spawn .git/hooks/pre-commit: No such file or directory

But .git/hooks/pre-commit is existed.

PS cat .git/hooks/pre-commit
#!/bin/sh
# gradle-githook

C:\Users\abcfy\projects\dteam-top\clock-seed\gradlew codenarcMain pmdMain spotbugsMain
[ $? -gt 0 ] && exit 1
...

And if I use Cygwin/Msys2/Mingw, git hook shows:

.git/hooks/pre-commit: line 4: C:Usersabcfyprojectsdteam-topclock-seedgradlew: command not found

abcfy2 avatar May 06 '19 04:05 abcfy2

Maybe you can use cygpath -m to mix path both for windows and posix

abcfy2 avatar May 06 '19 04:05 abcfy2

Sorry, I don't have a Windows. I can't check. 🙇

STAR-ZERO avatar May 06 '19 08:05 STAR-ZERO

I solved by myself, just solve the path for posix, and windows git could also works very well(Use git for windows cmd/git).

Here is my sample:

.git/hooks/pre-commit:

#!/bin/sh -e

echo $@
[ -f ./gradlew -o -f ./gradlew.bat ] && GRADLE=./gradlew || GRADLE=gradle
$GRADLE codenarcMain pmdMain spotbugsMain

.git/hooks/commit-msg:

#!/bin/sh -e

commitlint -x @commitlint/config-conventional -e $@

/bin/sh -e will automatic exited when the line not exit with 0, and [ -f ./gradlew -o -f ./gradlew.bat ] && GRADLE=./gradlew || GRADLE=gradle could solve the gradle wrapper not exist.

abcfy2 avatar May 06 '19 11:05 abcfy2

any news?

Murik avatar Aug 20 '20 13:08 Murik

Sorry, I'm too late.

Maybe, I fixed this issue. But I'm not. Please check version 1.2.1.

I am not familiar with Windows. If you have a problem with Windows, I want you to send a pull request. It's very helpful.

STAR-ZERO avatar Aug 29 '20 09:08 STAR-ZERO