1

I have implemented a post-receive hook on my server (git was initialized with git init --bare). Hook was created in the following way:

cd repo/hooks/
touch post-receive
chmod 777 post-receive

Then inside of the file I have:

#!/bin/sh
GIT_WORK_TREE=/var/www
export GIT_WORK_TREE
git checkout -f

Right now when I push my local changes everything gets moved to /var/www folder. The problem is that I do not want some of the folders to be moved. For example I have folder1, and folder2 there which I do not want to be moved. Currently I am manually removing these folders after the push, but this is a ridiculous work and I would like to automate it.

I am on ubuntu 14.04 / git 2.1

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753

1 Answers1

2

I am manually removing these folders after the push

You could just ad this step in your hook

The other way is to try and set up a sparse checkout (since you can exclude folders in the sparse-checkout file).

echo "/*" > .git/info/sparse-checkout
echo "!folder1/" >> .git/info/sparse-checkout
echo "!folder2/" >> .git/info/sparse-checkout
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Can you please tell how can I add this step (removing these folders after the push) in my hook? – Salvador Dali Sep 06 '14 at 10:26
  • 1
    @SalvadorDali simply adin gthe command you are doing manually in the post receive script (after the checkout step): as a `rm -Rf /var/www/folder1`. – VonC Sep 06 '14 at 10:27
  • Got it. But if I will set up sparse checkout, these folders would not even be moved? – Salvador Dali Sep 06 '14 at 10:28
  • @SalvadorDali yes, that the idea of a sparse checkout: to *not* checkout everything. – VonC Sep 06 '14 at 10:29
  • Is there anything different I have to do if I am doing this in --bare repo? When I am doing the first command `echo "/*" > .git/info/sparse-checkout` I am getting No such file or directory – Salvador Dali Sep 06 '14 at 10:40
  • @SalvadorDali true, you would do this a non-bare repo only, so the first option (adding the rm step) is the easiest. – VonC Sep 06 '14 at 10:41