Git post-receive hook doesn't delete files

I am currently trying to git and trying to create a workflow so that pushing to a bare remote repo on the server will update 2 different sites based on different branches.

Hook after ingestion:

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

      

based on StackOverflow question but with a few changes.

Unfortunately, when testing it, a new test file upload to either branch will be pushed and successfully updated by the root website, but to delete the same test file, the root website still keeps a copy of the deleted file.

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

+3


source to share


3 answers


I finished work

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

      



based on @ Koraktor's answer.

0


source


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

      

+2


source


I think that checking the working tree does not write any information about the repository in the working directory. Thus, when upgrading an already tested version, Git will not be able to determine which diff it should apply, and as such which files should be removed.

The simplest solution is to delete all files in folders before checking them.

+1


source







All Articles