Amparo
Amparo

Reputation: 824

Git deployment: removing files when push files removed

I have a post-receive hook to deploy my app in webroot when I push on master branch. This is my script:

#!/bin/bash
while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch..."
        git --work-tree=/var/www/mywebroot --git-dir=/home/myuser/myrepo checkout -f master
    else
        echo "Ref $ref successfully received.  Doing nothing."
    fi
done

The problem is that when I push any commit that deletes any file, the files were removed are not removed in webroot.

Upvotes: 2

Views: 222

Answers (1)

VonC
VonC

Reputation: 1325437

You can add (using git clean) just after the git checkout line:

git -work-tree=/var/www/mywebroot --git-dir=/home/myuser/myrepo clean -fd

That will remove untracked files and folders.

Upvotes: 1

Related Questions