0

This is a little weird so I have this line in my remote git repo hook script post-receive:

cd /path/to/my/deployed/app
git reset --hard
rm files/.development

And from my local machine i push to my git repo - here's what's weird. Those lines that is at the end of my post-receive is executed in my local machine and not in my remote server??

Obviously I end up getting this error:

MacBook-Air:$ git push to-my-deployed-app

Counting objects: 23, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (16/16), 2.56 KiB, done.
Total 16 (delta 11), reused 0 (delta 0)
remote: warning: updating the current branch
remote: fatal: Not a git repository: '.'
remote: rm: cannot remove `files/.development': No such file or directory

So there .. very odd...

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
David
  • 4,235
  • 12
  • 44
  • 52
  • If you are pushing to a non-bare repository and trying to use this hook to update the working tree after the push, then you should consider the `post-update` script linked in the [“Why won't I see changes in the remote repo after "git push"?”](https://git.wiki.kernel.org/index.php/GitFaq#Why_won.27t_I_see_changes_in_the_remote_repo_after_.22git_push.22.3F) Git FAQ. It handles dirty working trees by stashing before the reset (so you at least have a chance of recovering any changes made directly on the server (outside of Git)). – Chris Johnsen Mar 23 '11 at 07:02
  • thanks for trying to help. though i don't need to worry about having a dirty tree on our server, since its a live repo no one developers there but everyone just pushes to that live repo. i just want my hook script to execute correctly - updating the working tree. please see below my last comment for Mark. thanks! – David Mar 28 '11 at 18:01

1 Answers1

4

Why do you think it's being run locally? The prefix remote: before each error indicates that it came from the remote. From those errors, it looks as if the path to your repository is wrong. In fact, you shouldn't need to change directory if you're trying to run git reset --hard in the repository the hook is in - the current working directory for the hook will be the top level of that repository anyway.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • hmm that makes sense, shouldn't be cd'ing to a directory but nevertheless, not sure why the cd to my app dir is wrong since if – David Mar 23 '11 at 07:51
  • @David: it's hard for anyone here to guess since clearly `/path/to/my/deployed/app` isn't the real path on your server, and we can't see what's in the real directory anyway... – Mark Longair Mar 23 '11 at 08:15
  • hi Mark thanks for helping - i think I'm making some progress but still a little funky. so I removed the extra step to change path and now i get this result: Total 5 (delta 3), reused 0 (delta 0) remote: warning: updating the current branch remote: HEAD is now at 2968db5 small tweak for the label 'for' attribute . BUT - when i go to the server and edit my file, my changes weren't there? What happened here and why did the server yielded that message but the files/workign copy wasn't updated? – David Mar 27 '11 at 08:21