3

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% (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.

Community
  • 1
  • 1
Radek
  • 13,813
  • 52
  • 161
  • 255
  • What do you mean by "doesn't work correctly"? I see output from the fetch; it looks like it succeeded. `git reset --soft` doesn't produce any output if it runs successfully. At the top you say you get that error - what command prompts that? Is it within Redmine? (And is the redmine repo bare? If not, remember that `git reset --soft` doesn't touch index or working tree...) – Cascabel Nov 10 '10 at 14:30
  • @Jefromi: I updated my question...hopefully it is clearer now. My point is that if I run the `git fetch && git reset --soft` from a command line it works (=I can see updated repo from redmine) if fired from the hook I get the error in redmine. – Radek Nov 10 '10 at 21:48
  • 1
    You might want to put some debugging statements in your hook script, like print out the directory it's in and echo the commands before they run (or use -x on the shebang line). Anything printed to stdout/stderr by the hook script will be sent back to the remote. – ebneter Nov 12 '10 at 03:45
  • @ebneter: thanks, I updated my question. pwd gives me the right path I believe. It seems to me that `git` command is not executed properly as there is no git output when hook is executed. Compare to manual execution. – Radek Nov 12 '10 at 08:45
  • what does it mean to 'use -x on the shebang line'? – Radek Nov 12 '10 at 11:04
  • Try adding a pwd command right after the cd, to have the script print the directory you're actually in. My guess is that the script isn't changing to the correct directory. As for the "shebang line", it's the line at the top of your script that looks like #!/bin/bash or something similar. The "-x" option tells bash (or sh) to echo all the commands before executing them. – ebneter Nov 12 '10 at 20:21
  • I did the pwd, even before posting my question. It is in the correct directory. If the correct directory is the .git (repository) directory. In my case ~/srv/www/redmine.domain.com/git_repositories/linode.git` – Radek Nov 13 '10 at 10:52

1 Answers1

0

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

Radek
  • 13,813
  • 52
  • 161
  • 255