0

I do execute the following steps to create on DEBIAN Server 1) git bare repo; 2) a working dir, where the files are copied after local git push; 3) a local clone on Windows, bare server repo is cloned.

I executed the following commands:

# SERVER: Setup git bare repo on server on Debian Wheezy v7.8, GIT 2.3.6
# mkdir /domains/site/test-workdir
# make a content copy on DEBIAN server into a test workdir
cp -rp /content/* /domains/site/test-workdir

mkdir /domains/git/site-bare.git
cd /domains/git/site-bare.git
git --git-dir=. --work-tree=/domains/site/test-workdir/. init
git config receive.denycurrentbranch ignore
cd /domains/git/site-bare.git/hooks
nano post-receive
# add the following content until # end
#!/bin/sh
export GIT_WORK_TREE=/domains/site/test-workdir/
export GIT_DIR=/domains/git/site-bare.git/
cd $GIT_DIR
git checkout -f
# end
chmod +x post-receive
cd ..
git add .
git commit -m "Initial commit"
git status
# On branch master
# nothing to commit, working directory clean


# LOCAL:
cd /w/Dev/\!GIT/
mkdir test-remote
cd /w/Dev/\!GIT/test-remote
git init
git remote add web-local ssh://root@192.168.1.101/domains/git/site-bare.git
git remote -v
# web-local       ssh://root@192.168.1.101/domains/git/site-bare.git (fetch)
# web-local       ssh://root@192.168.1.101/domains/git/site-bare.git (push)
git pull web-local master


# SERVER
cd /domains/site/test-workdir/
rm -r *

# LOCAL (Windows7 64bit, git v2.3.6)
# git push should execute post receive on remote, so workdir should get again the content
git push web-remote master

Once I also got the

Counting objects: 27, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 2.49 KiB | 0 bytes/s, done.
Total 27 (delta 21), reused 0 (delta 0)
remote: fatal: Not a git repository: '/domains/git/site-bare.git/.git'
To ssh://root@192.168.1.101/domains/git/site-bare.git
27b6ceb..8ed3301  master -> master

Later I did not get such "Not a git repository" error. But anyway, the workdir is not filled with content, this is my problem.

UPDATE: If I do "git checkout -f" of the server, then the workdir is updated, so this means that the post-receive hook is not executed.

UPDATE2: Fixed a bug in post-receive, but still not updated. Just if I execute the post-receive script manually.

Any idea why the remote workdir is not updated?

klor
  • 1,237
  • 4
  • 12
  • 37

1 Answers1

0

First, what you're trying to do manually is what tools like Capistrano are meant for, you should have a look at it.

I think your problem is that you ran "git init" without --bare. If you want a bare repo, then use --bare, and you won't need "git config receive.denycurrentbranch ignore".

You should see this related question: How to copy a pushed branch to another directory?

Community
  • 1
  • 1
Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65