bashgithookspre-commit

pre-commit bash script not found even though it exists for .githooks


I'm really confused on this.

The file clearly exists and has executable mode on. this is not woking on my VM running fedora. but runs fine on windows host with git-bash

I did set -x to see but i see same error

ajeet@fedora /home/ajeet/Repo/prov/xyz-service-app (dummy *%)$ git commit -am "Test"
+ git commit -am Test
fatal: cannot exec '.githooks/pre-commit': No such file or directory

The file is there for sure.

ajeet@fedora /home/ajeet/Repo/prov/xyz-service-app (dummy *%)$ cd .githooks/
ajeet@fedora /home/ajeet/Repo/prov/xyz-service-app/.githooks (dummy *%)$ ll
total 12
-rwxr-xr-x. 1 ajeet ajeet  975 Jun 18 15:37 pre-commit
-rwxr--r--. 1 ajeet ajeet 1664 Jun 18 15:26 SetupGitHooks.class
-rwxr--r--. 1 ajeet ajeet 1357 Jun 18 15:26 SetupGitHooks.java
ajeet@fedora /home/ajeet/Repo/prov/xyz-service-app/.githooks (dummy *%)$ ./pre-commit 
bash: ./pre-commit: cannot execute: required file not found
ajeet@fedora /home/ajeet/Repo/prov/xyz-service-app/.githooks (dummy *%)$

Solution

  • Found some useful hint here: https://askubuntu.com/a/133460/1101876

    created a fresh file and pasted the same content in that. now it works

    dos2unix pre-commit

    is the solution