from command line ok but the hook (git)

I want to automatically update my redmine project repository after anybody pushes into remote repo. Currently gin in redmine is up and works fine. But after automatic update using a hook I get The entry or revision was not found in the repository. in redmine.

To set up git in redime I followed redmine wiki so the repo is bare created via git clone --bare

  • Managing library dependencies using git
  • Cannot push to Heroku 'fatal: unable to access..Could not resolve host: (nil); nodename nor servname provided, or not known'
  • Git Pull and Clone From HostGator Fails
  • How to make git check every file's contents even though stat info may not have changed?
  • git pre-push: connection closed by remote host while running tests
  • How can I clean my .git folder? Cleaned up my project directory, but .git is still massive
  • To update redmine’s git repository I use this cd /srv/www/redmine.domain.com/git_repositories/linode.git && git fetch && git reset --soft refs/remotes/origin/master

    • manual update if running from command line under git user works ok

    the screenshot when executed manually is

    remote: Counting objects: 5, done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 3 (delta 2), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From domain.com:linode
      * [new branch]      master     -> origin/master
    
    • the same doesn’t work correctly when running form post-receive hook (see the error above). Runs under the same user (git). The first line of the hook is #!/bin/sh

    configuration: git (1.7.0.4) + gitolite (1.5.7) on ubuntu

    I checked the GIT_DIR system variable byt command SET
    remote: /srv/www/redmine.domain.com/git_repositories/linode.git[K
    remote: GIT_DIR=’.'[K

    I even tried to set git path up in the hook by

    export GIT_DIR=/srv/www/redmine.domain.com/git_repositories/linode.git
    or unset GIT_DIR
    

    but nothing helped.

    The result of the hook

    echo "Post receive-hook => updating Redmine repository"
    #env -i git reset --hard
    #unset $(git rev-parse --local-env-vars)
    #unset GIT_DIR
    
    
    cd /srv/www/redmine.domain.com/git_repositories/linode.git
    pwd
    git fetch
    git reset --soft refs/remotes/origin/master
    

    is

    Pushing to git@domain.com:linode
    remote: Post receive-hook => updating Redmine repository[K
    remote: From domain.com:linode[K
    remote: /srv/www/redmine.domain.com/git_repositories/linode.git[K
    remote:    4755447..13b8e3d  master     -> origin/master[K
    To git@domain.com:linode
      4755447..13b8e3d  master -> master
    

    I tried few hints from calling-git-pull-from-a-git-post-update-hook and git-post-receive-hook-with-git-pull-failed-to-find-a-valid-git-directory but nothing helped

    Update

    if I try

    echo "Post receive-hook => updating Redmine repository"
    export GIT_DIR=
    
    cd /srv/www/domain.com/git_repositories/linode.git
    
    echo "Resetting working tree..."
    git reset --hard
    echo "Finished resetting working tree."
    
    git fetch
    git reset --soft refs/remotes/origin/master
    

    I get this + redmine repository is untouched and accessible from redmine

    Pushing to git@domain.com:linode
    remote: Post receive-hook => updating Redmine repository[K
    remote: Resetting working tree...[K
    remote: fatal: Not a git repository: ''[K
    remote: Finished resetting working tree.[K
    remote: fatal: Not a git repository: ''[K
    remote: fatal: Not a git repository: ''[K
    To git@domain.com:linode
     c553a15..854d159  master -> master
    

    Update2

    I found out that if I do git fetch from the hook and then git reset --soft refs/remotes/origin/master from command line it doesn’t work. I get the above error in redmine. I do git fetch from command line then everything works fine. Console messages from both hook and commnand line ‘git fetch` commands looks the same to me.

  • Undoing Git Clean
  • Git Shows Random Files as Modified After Clone; Can't Discard Them
  • Why is a cloned repo 10x larger than a fetched repo?
  • What settings affect user name in Git?
  • Rails messing up my code with “<<<<<<< HEAD”
  • Bitbucket/Github: permission denied public key
  • One Solution collect form web for “from command line ok but the hook (git)”

    I do know exactly what and why but after git fetch executed via hook (I use gitolite) some files (maybe new ones) has permissions that redmine `doesn’t like.

    chmod -R 770 redmine_repo.git
    

    did the trick

    Git Baby is a git and github fan, let's start git clone.