Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git post-receive hook does not delete files

Tags:

git

I'm trying out git at the moment, and am trying to create a workflow so that a push to a bare remote repo on the server will update 2 different sites based on different branches.

The post-receive hook is:

#!/bin/sh
GIT_WORK_TREE=/www/development/ git checkout -f master
GIT_WORK_TREE=/www/production/ git checkout -f production

based on https://stackoverflow.com/a/3838804/1097483 but with a few modifications.

Unfortunately while testing it, commiting a new test file to any of the branches will be pushed and successfully update the web root, but for deleting the same test file, the web root still retains a copy of the deleted file.

Does anyone know how I can get the post-receive hook to force a delete?

like image 201
xiankai Avatar asked Aug 15 '26 14:08

xiankai


2 Answers

You should probably use git-reset and git-clean:

#!/bin/sh
GIT_WORK_TREE=/www/development/ git reset --hard master
GIT_WORK_TREE=/www/development/ git clean -fdx
GIT_WORK_TREE=/www/production/ git reset --hard production
GIT_WORK_TREE=/www/production/ git clean -fdx
like image 104
Koraktor Avatar answered Aug 17 '26 02:08

Koraktor


I think that the work-tree checkout does not record any information about the repository in the working directory. So when updating an already checked-out version, Git will not be able to tell which diff it would have to apply and as such which files it needs to remove.

Easiest solution would be to remove all files in the folders before checking them out..

like image 23
poke Avatar answered Aug 17 '26 03:08

poke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!