开发者

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

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% (开发者_如何学Go3/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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜