Reputation: 3255
I want to use an automated push script using git and configured my post-receive hook:
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production server..."
git --work-tree=/var/www/MFDispo --git-dir=~/Documents/MFDispo/.git checkout -f
else
echo "Ref $ref successfully received. Doing nothing. Only the master branch may be deployed on this server."
fi
done
But the push is not working:
remote: Master ref received. Deploying master branch to production server...
remote: fatal: Not a git repository: '~/Documents/MFDispo/.git'
But the folder on my client contains the git repo. I see the folder within the folder structure and the git system is working as I use it throughout coding and committing.
Do I need to specify the path differently?
UPDATE
After changing the path for --git-dir
to $HOME/Documents...
the same error appears but I can see the path he is searching in now as well. It is /home/sesc/Documents...
. But this is on my production server. I thought on the client the path is being searched by entering the path in the file?
UPDATE 2 So now I tried the following:
var/www/MFDispo
(this is the path on the production server)Now I get the error:
remote: error: insufficient permission for adding an object to repository database objects
do I need to chmod
the folder before I can start? At least it seems better than before!
Thank you
Upvotes: 2
Views: 286
Reputation: 14786
I don't think the ~ prefix is being expanded appropriately in the context where you are using it; it is expanded by bash only when bash recognizes it as the start of a word, not in the middle of an argument.
Try substituting ${HOME} instead on the relevant line:
git --work-tree=/var/www/MFDispo --git-dir=${HOME}/Documents/MFDispo/.git checkout -f
Upvotes: 1
Reputation: 57460
~
only expands to your home directory when it's at the beginning of a shell word (roughly, when it's at the beginning of the line or preceded by whitespace). Thus, in --git-dir=~/Documents/MFDispo/.git
, the ~
is not expanded, and so Git looks for a directory literally named ~
, which (I assume) doesn't exist. You have either write out the path to your home directory in full or else replace it with the shell variable $HOME
:
--git-dir=$HOME/Documents/MFDispo/.git
Upvotes: 2