11

I have created a pre-commit hook which takes the database dump and saves it in a file under my application/folder which is also in the git repo, after saving it I add the file to commit list . Following is the code in my pre-commit file

    D:/xampp/mysql/bin/mysqldump -u root -pxyz --skip-extended-insert [database] > D:/xampp/htdocs/app/application/[database].sql

cd D:/xampp/htdocs/app/application
git add [database].sql

I tried to run the pre-commit code directly through command prompt it works without any error but when I try to commit the code through git bash I get this error

fatal: Not a git repository: '.git' 

I am assuming its because of the git command used in the pre-commit file, can anyone tell me whats wrong in this file and how I should amend it

Anand Joshi
  • 452
  • 7
  • 23

3 Answers3

10

In doubt, in your hook, set up explicitly git-dir and work-tree parameters:

git --git-dir .git --work-tree . add ...

You can even put the full path to be extra-sure:

git --git-dir D:/xampp/htdocs/app/application/.git --work-tree D:/xampp/htdocs/app/application/. add ...

That way, you rule out any environment issue with those git-dir or work-tree stuck into another path which isn't the one of the repo your are cd'ing into.
See "Calling 'git pull' from a git post-update hook" for an example of that problem.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • can you direct me to link or can you explain me why was this happening ? @vonc – Anand Joshi Aug 12 '12 at 19:31
  • @AnandJoshi the link I mention in my answer is a good illustration: http://stackoverflow.com/questions/3542854/calling-git-pull-from-a-git-post-update-hook . Your hook start with the wrong path for the git dir or work tree. Whenever you change directory into *another* repo from an hook, it is best to set explicitly those values (git dir and work tree) to the target repo you want to operate on. – VonC Aug 12 '12 at 19:37
1

i had the exact same issue like you and found this solution:

instead of doing

cd D:/xampp/htdocs/app/application
git add [database].sql

i simply did

git add D:/xampp/htdocs/app/application/[database].sql

that way i didn't irritate git by cd-ing into another folder :)

nerdess
  • 10,051
  • 10
  • 45
  • 55
0

make sure you're in directory which have .git folder ? to make sure, try to run

git status

and see what's happen. if you still get such message, I think your git hasn't been set up yet.

follow those steps to set up it:

git init
git add .
git commit -m "your message"
git push
kevin
  • 59
  • 1
  • 7
  • what do you get when running git status ? – kevin Aug 11 '12 at 13:36
  • modified : aplication/[database].sql that is because the sql dump is created every time commit command is done, @kevin do you have any experience with hooks ? – Anand Joshi Aug 11 '12 at 13:55