1

working hard on configuration of my git repository, but stil no success.

Goal: as soon i make a push on my lokal repo, to the dev branch, it will merged with master brench.

post-update (hook)

#!/bin/bash
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".

LOGFILE=/www/htdocs/w00dac5d/_production/.git_push_log.tmp

&> $LOGFILE

echo 'push-start'

echo `basename $PWD`
#cd ../
#echo `basename $PWD`

git status
git checkout master

echo 'push-checkout'
git merge dev

exec git-update-server-info

getting errors like

"its not a git repo" but i check teh folder an it is the right one.

enter image description here

Alexander_F
  • 2,831
  • 3
  • 28
  • 61
  • Check out http://stackoverflow.com/questions/2432026/gitosis-admin-git-push-failed-exec-hooks-post-update (with its comment), and see if you need to set `GIT_DIR` environment variable. – VonC Jan 31 '12 at 09:45
  • it is not really clear where to set it – Alexander_F Jan 31 '12 at 14:28
  • I believe in your hook script, just to make sure Git knows where to look when you are making your git commands like `git status`: the current directory isn't the only thing that matter. – VonC Jan 31 '12 at 14:30
  • after cd ../ echo `basename $PWD` he is in _production, this is the git repo... – Alexander_F Jan 31 '12 at 14:40
  • 1
    I would still recommend you try to set `GIT_DIR` to that `.git` directory full path (and `GIT_WORK_TREE` to the parent directory), to be extra sure. Test it and see of the errors persists. – VonC Jan 31 '12 at 14:43

1 Answers1

2

The problem here is that in a post-update hook in a non-bare repository, GIT_DIR is set to . and your current directory is the .git directory. For such details for each different git hook, see this underrated blog post ;)

That means that if you do cd .. then GIT_DIR will still be . but your current directory will no longer be the .git directory. Try beginning your hook script with:

export GIT_DIR=/whereever/production/.git
export GIT_WORK_TREE=/whereever/production/

... to be safe - the rules about how GIT_DIR and GIT_WORK_TREE interact are fiddly.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327