从命令行确定但钩子(git)

时间:2010-11-10 13:18:50

标签: git githooks

我想在任何人推入远程仓库后自动更新我的redmine项目存储库。目前在redmine中的杜松子酒已经开启并且工作正常。但是在使用钩子自动更新后,我在redmine中得到The entry or revision was not found in the repository.

要在redime中设置git,我跟着redmine wiki,因此通过git clone --bare

创建了repo

要更新redmine的git存储库我使用 cd /srv/www/redmine.domain.com/git_repositories/linode.git && git fetch && git reset --soft refs/remotes/origin/master

  • 如果从git用户工作正常
  • 下的命令行运行,则手动更新

手动执行时的屏幕截图

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
  • 在运行表单post-receive挂钩时同样无法正常工作(请参阅上面的错误)。在同一个用户(git)下运行。钩子的第一行是#!/bin/sh
ubuntu上的

配置: git(1.7.0.4)+ gitolite(1.5.7)

我通过命令SET检查了GIT_DIR系统变量     remote:/srv/www/redmine.domain.com/git_repositories/linode.git[K     remote:GIT_DIR ='。'[K

我甚至试图通过

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

但没有任何帮助。

钩子的结果

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 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

我尝试了calling-git-pull-from-a-git-post-update-hookgit-post-receive-hook-with-git-pull-failed-to-find-a-valid-git-directory的一些提示,但没有任何帮助

更新

如果我尝试

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

我得到这个+ redmine存储库是不受影响的,可以从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

我发现如果我从钩子中执行git fetch,然后从命令行执行git reset --soft refs/remotes/origin/master则不起作用。我在redmine中得到了上述错误。我从命令行执行git fetch然后一切正常。来自hook和commnand line'git fetch`命令的控制台消息看起来与我相同。

1 个答案:

答案 0 :(得分:0)

我确实知道究竟是什么以及为什么但是在通过钩子执行git fetch之后(我使用gitolite)一些文件(可能是新文件)具有redmine“不喜欢的权限。”

chmod -R 770 redmine_repo.git

做了这个伎俩