2

I want to push from my local machine to a staging server via post-receive hook.

I did the following steps:

Remote Machine

  • mkdir /var/www/mfserver.git
  • git init --bare
  • mkdir /var/www/mfserver
  • sudo chmod -R ug+w /var/www/mfserver/.git
  • sudo chown -R root:root /var/www/mfserver/.git
  • git config core.sharedRepository group

Local Machine

  • git remote add staging user@serverip:/var/www/mfserver.git

When I then do: git push staging master I get still the error:

Delta compression using up to 8 threads.
Compressing objects: 100% (182/182), done.
Writing objects: 100% (206/206), 55.54 KiB | 0 bytes/s, done.
Total 206 (delta 69), reused 0 (delta 0)
remote: fatal: Unable to create temporary file '/var/www/mfserver.git/./objects/pack/tmp_pack_XXXXXX': Permission denied
error: unpack failed: index-pack abnormal exit
To admin@SERVERIP:/var/www/mfserver.git
 ! [remote rejected] master -> master (unpacker error)

Hook

#!/bin/bash
while read oldrev newrev ref
do
        if [[ $ref =- .*/master$ ]];
        then
                echo "Master ref received. Deploying master branch to Staging..."
                git --work-tree=/var/www/mfserver --git-dir=/var/www/mfserver.git checkout -f
        else
                echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed to the server."
        fi
done

This is my git hook: post-receive

I don't see why the error is coming up?

sesc360
  • 3,155
  • 10
  • 44
  • 86
  • 3
    The problem is not in your hook, it's in the basic receive: `index-pack` can't write to the repository ("permission denied"). Make sure whoever you're pushing-as has write permission (probably, "is in group root" given the chown/chmod you show). (That said, your hook is a bit careless: it treats any ref ending in `/master` as a push to `refs/heads/master`, even if it's actually a push to `refs/we/made/this/up/master`. But a weird ref is unlikely and a redundant checkout is safe anyway, so that's not a problem in practice.) – torek Oct 09 '15 at 20:40
  • Ha!! Amazing!! I never thought about that. And certainly did not understand the `index-pack` error. It works perfect now! – sesc360 Oct 09 '15 at 20:51

0 Answers0