开发者

Git push from post-update hook fails - X is not a repository

I am trying to setup a central repository that will automatically push to another repository when it is pushed to from my local machine. I have been Googling for several days now and I have tried every command combination I could find with no luck.

The setup: I first created the central repository as a bare and then cloned it to the second machine as a non-bare. I added the second machine as a remote, called "www", to the first machine. I confirmed that I could execute "git push www master" manually from the first machine and it will update the second via SSH. I then cloned the repository to my local development machine via HTTP. I can push from local to central just fine.

My post-update hook in its current form:

#!/bin/bash

cd /var/git_repos/site.git

unset $(git rev-parse --local-env-vars)

branch=$(git rev-parse --abbrev-ref HEAD)

if [ "$branch" == "master" ];
then
  echo "Pushing $branch to www..."
  env -i git push www master
fi

exec git update-server-info

I have cobbled this together from various SO and blog posts. It works fine when executed manually from the CLI of the first machine ("cd /var/git_repos/site.git/hooks; ./post-update") but I get the error message "www is not a Git repository" when executed as a hook.

The output:

$ git push
Password:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 264 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Pushing master to www...
remote: fatal: 'www' does not appear to be a git repository
remote: fatal: The remote end hung up unexpectedly
To https://xxx@git.xxx.xxx/site.git
   e3d3a1d..103c819  master -> master

Can anyone tell me what I am doing wrong?

Edit: I have figured out that 开发者_如何学Cmy initial issue was that the permissions on site.git were not entirely set correctly. Having fixed that problem, I have a new problem.

New output:

$ git push
Password:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: I am apache <---- Output of "whoami" for debugging
remote: Pushing master to www...
remote: ssh: connect to host 192.168.1.79 port 22: Permission denied
remote: fatal: The remote end hung up unexpectedly
To https://nnn@git.nnn.nnn/site.git
   29d504c..f14f201  master -> master

I have tried adding the following to my /etc/sudoers file with no luck:

apache ALL=NOPASSWD: /usr/bin/ssh


This is the error you get when trying to push to an unknown remote. Try:

git push thisisprobablynotaremote master

Check

git remote -v

and make sure that www is properly defined, also check

git config --list

www should be there as well.

Print the output of all commands from the hook itself and compare the output.


I would suggest changing the www to the full url of the remote repo you are pushing to. Additionally changing master to master:master might be of help.


Don't do

unset $(git rev-parse --local-env-vars)

I think you saw the hooks where people were trying to do a git pull from a different repo. You are just doing all the commands relative to the current repo. So you don't have to do that.

Similarly, don't do:

env -i git push www master

remove the env -i

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜