I have set up a git repository for my webpage (it's simple HTML, generated from markdown by Pandoc). The repository will only be updated remotely by me, and I have successfully configured it to work with HTTPS.
Now, This is not a bare repository -- nobody will update the repository or the working tree locally on the server, so I just keep a working copy there, and make it available for the web server to publish.
It all works fine, but -- I need the working tree to be automatically updated every time I push changes to the server, so I have written the following post-update
script (in the example, the working tree is in /path/git/me
, and the repository in /path/git/me/.git
):
#!/bin/bash
(cd /path/git/me/ && echo "running git reset --hard on `pwd`" && git reset --hard)
(cd /path/git/me/ && pandoc -s -o index.html index.md)
And when I run git push
, the hook is executed, but something really strange happens:
- git complains that
'.'
is not a repository, and does not run thegit reset --hard
command - however, pandoc does run without problems!
Below is the transcript of a push:
$ GIT_TRACE=1 git push
12:21:12:21:27.088581 run-command.c:347 trace: run_command: 'git-remote-https' 'origin' 'https://server.org/git/me'
Username for 'https://server.org': me
Password for 'https://me@server.org':
12:21:32.624468 run-command.c:347 trace: run_command: 'send-pack' '--stateless-rpc' '--helper-status' '--thin' '--progress' 'https://server.org/git/me/' '--stdin'
12:21:32.627833 exec_cmd.c:128 trace: exec: 'git' 'send-pack' '--stateless-rpc' '--helper-status' '--thin' '--progress' 'https://server.org/git/me/' '--stdin'
12:21:32.633026 git.c:348 trace: built-in: git 'send-pack' '--stateless-rpc' '--helper-status' '--thin' '--progress' 'https://server.org/git/me/' '--stdin'
12:21:32.634024 run-command.c:347 trace: run_command: 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '--progress'
12:21:32.634538 exec_cmd.c:128 trace: exec: 'git' 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '--progress'
12:21:32.636701 git.c:348 trace: built-in: git 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '--progress'
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 223 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: running git reset --hard on /path/git/me
remote: fatal: Not a git repository: '.'
To https://server.org/git/me
93be2f2..9cc7a28 master -> master
What did I do wrong here, and how would I get the hook to run the commands as intended?