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
- is it possible to run a command before git checkout
- Git on windows over HTTP. post-receive hook not working
- How can I add --no-verify option to a commit using git gem?
- Git Allow “push to master” access to particular user in LDAP account
- git auto fetch before a diff
- Can a pre-receive hook block a user from pushing new files/folders?
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
gituser 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-receivehook (see the error above). Runs under the same user (git). The first line of the hook is
configuration: git (18.104.22.168) + gitolite (1.5.7) on ubuntu
I checked the GIT_DIR system variable byt command SET
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
Pushing to email@example.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 firstname.lastname@example.org: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
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 email@example.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 firstname.lastname@example.org:linode c553a15..854d159 master -> master
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.
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