0

I am trying to set up git post-update hook in windows environment. Here is the code:

#!/bin/sh
cd /c/inetpub/vhosts/mywebsite || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info

When I run this from shell (sh post-update) everything works great. But after push I have an error:

hooks/post-update: line 7: cd: /c/inetpub/vhosts/mywebsite: Not a directory

What I'm doing wrong?

breethe
  • 613
  • 1
  • 6
  • 18
  • When you are in the *Git Bash* shell, what happens if you try to do `cd /c/inetpub/vhosts/mywebsite`? – Klas Mellbourn Jun 08 '13 at 14:35
  • Everything works as expected, current dir changed to /c/inetpub/vhosts/mywebsite. – breethe Jun 08 '13 at 15:21
  • what do you get if you do `echo $USER` in your shell, and if you put that in your hook script and do a push? Does it give the same thing? Also, if you change the absolute path of `/c/inetpub/vhosts/mywebsite` to a relative path, does that work? (For that, keep in mind that hook scripts are executed in the root directory of the repository, for example if your hook script is `/c/repos/repo.git/hooks/post-update` then it is executed in `/c/repos/repo.git`.) – janos Jun 09 '13 at 08:06
  • Not sure I'am doing things right, but `echo $USER` gives me empty line both in shell and after push. Using relative path's gives me the same error `hooks/post-update: line 8: cd: ../../inetpub/vhosts/mywebsite: Not a directory` – breethe Jun 09 '13 at 10:17

1 Answers1

0

You can try using the a different path, a relevant path. For example, your root path.

#!/bin/sh
unset GIT_DIR
cd ..
git checkout -f

Using cd .. to go back to your folder's root path. Then, the git checkout -f is used to force update the working copy every time the repo gets updated.

lvarayut
  • 13,963
  • 17
  • 63
  • 87