I have the following shell script as post-receive
hook, which should copy my working copy into my /mnt/repo/
folder:
#!/bin/sh
rm -rf /tmp/repo/
rm -rf /mnt/repo/*
mkdir /tmp/repo/ && cd /tmp/repo/
git init
git remote add origin file:///home/git/repos/repo.git
git fetch
git checkout development
cp -r /tmp/repo/* /mnt/repo/
If I run it locally, it works just fine. However, if it is run by Git after pushing, it won't work, and I get the following output in my local Git Bash:
$ git push local development
[email protected]'s password:
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 349 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Initialized empty Git repository in /tmp/repo/
remote: From file:///home/git/repos/repo
remote: * [new branch] development -> origin/development
remote: * [new branch] release -> origin/release
remote: fatal: This operation must be run in a work tree
To [email protected]:repos/repo.git
01568cc..ee31229 development -> development
Moreover, in my /tmp/repo
and /mnt/repo
folders, I have the following folder structure:
drwxr-xr-x 7 git git 220 Mar 14 13:47 .
drwxrwxrwt 3 root root 60 Mar 14 13:47 ..
drwxr-xr-x 2 git git 40 Mar 14 13:47 branches
-rw-r--r-- 1 git git 183 Mar 14 13:47 config
-rw-r--r-- 1 git git 73 Mar 14 13:47 description
-rw-r--r-- 1 git git 240 Mar 14 13:47 FETCH_HEAD
-rw-r--r-- 1 git git 23 Mar 14 13:47 HEAD
drwxr-xr-x 2 git git 200 Mar 14 13:47 hooks
drwxr-xr-x 2 git git 60 Mar 14 13:47 info
drwxr-xr-x 44 git git 880 Mar 14 13:47 objects
drwxr-xr-x 5 git git 100 Mar 14 13:47 refs
It is a new repository and hence a working tree has yet not been attached to it.
Read here for more details.