progrium / gitreceive

Easily accept and handle arbitrary git pushes
1.14k stars 108 forks source link

pre-receive hook declined error #36

Closed jacobbednarz closed 7 years ago

jacobbednarz commented 9 years ago

Hey, I've followed the README and have this setup as instructed however whenever I try to push to it I end up getting the following error.

$ git push demo master

Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.33.33:hello_world
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@192.168.33.33:hello_world'

So I've checked the remotes (and they look fine)

$ git remote -v     
demo    git@192.168.33.33:hello_world (fetch)
demo    git@192.168.33.33:hello_world (push)

The weirdest thing though is that the repository is created where it should be.

$ pwd
/home/git

$ ls -la
total 36
drwxr-xr-x 8 git  root 4096 Jan 21 08:43 .
drwxr-xr-x 5 root root 4096 Jan 21 08:13 ..
drwx------ 2 git  git  4096 Jan 21 08:19 .cache
drwxr-xr-x 2 git  root 4096 Jan 21 08:36 .ssh
drwxrwxr-x 7 git  git  4096 Jan 21 08:38 hello_world
-rwxr-xr-x 1 git  root  232 Jan 21 08:13 receiver

So I am a little stumped as to what to be the cause here? Here is my authorized_keys file incase it helps.

$ cat /home/git/.ssh/authorized_keys 
command="GITUSER=git /usr/bin/gitreceive run jacob cc:a8:cc:d5:87:02:42:1b:19:25:36:d5:75:ec:f2:dc",no-agent-forwarding,no-pty,no-user-rc,no-X11-forwarding,no-port-forwarding ssh-rsa AAAAB3NzaC1<redacted>sagHzeOkAX4BztXEQBhLCTRixlVaWH jacob.bednarz@gmail.com
jkiesele commented 9 years ago

Hi,

I just ran into the same problem, tried fiddling around with the receiver script to add some debug output, and noticed a strange thing:

If the receiver script has a newer timestamp then the latest push, it works! Without understanding the issue, I added one line to the receiver script: touch $0

Now it works like a charm. I didn't have too much time to dig into the reason for that, but maybe someone here can tell.

Cheers

jacobbednarz commented 9 years ago

Hmm, never chcked the timestamps but perhaps my client was in front of the server time and that caused an issue?

Thanks for the heads up though! I will have a bit of a look and see if I can expand more on my issue after checking the timestamps.

DeltaWhy commented 9 years ago

I am having the same problem. Having a lot of difficulty debugging it but it looks like the git archive command in the hook fails with exit status 141. This may be a separate issue since touching the receiver script does nothing for me.

Running git version 1.9.1 on the server and 2.2.2 on the client.

spesnova commented 9 years ago

@jacobbednarz Hi, I had the same error before. In my case, receiver script caused the error. I think receiver script must receive STDIN from gitreceive.

Following reciever script works for me.

#!/bin/bash

APP=$1
REVISION=$2
USER=$3

echo "----> Unpacking repo..."
mkdir -p /tmp/build/$APP && cat | tar -x -C /tmp/build/$APP
jacobbednarz commented 9 years ago

I've debugged this and the only way I was able to continue replicating this was to have commented out code (or nothing) in the receiver like the default shows.

The only thing I can put this down to is that the script is expecting a return value and it's not getting it by default. I think to prevent new users from hitting this snag, we should update the default receiver to output and exit with a 0 status.

Thoughts? I'm happy to throw together a pull request if everyone agrees.

jacobbednarz commented 9 years ago

Added a pull request in hope that it will be reviewed and this little hurdle is removed for other users.

ccravens commented 9 years ago

After messing with it for a while I found out because I wasn't handling the tar file and producing a working version of the repository the script would hang. I removed the following from line 115 in gitreceiver script:

git archive "$newrev" |

That prevents archiving the new revision and piping the resulting tarfile to the gitreceiver script.

progrium commented 9 years ago

Well that is the whole point of this project, so removing that line means you basically don't want this project.

On Fri, Apr 24, 2015 at 6:33 AM, Chad Cravens notifications@github.com wrote:

After messing with it for a while I found out because I wasn't handling the tar file and producing a working version of the repository the script would hang. I removed the following from line 115 in gitreceiver script:

git archive "$newrev" |

That prevents archiving the new revision and piping the resulting tarfile to the gitreceiver script.

— Reply to this email directly or view it on GitHub https://github.com/progrium/gitreceive/issues/36#issuecomment-95798535.

Jeff Lindsay http://progrium.com

EnricoSottile commented 9 years ago

I experienced the same problem until i tried the solution pointed by spesnova, which worked for me. However, i still cannot push the tags as explained in this issue. .https://github.com/progrium/gitreceive/issues/38

hgilani commented 8 years ago

I was also facing this error and on inspecting script I found out that trigger_receiever method has following logic.

    [[ "$refname" == "refs/heads/master" ]] && \
      git archive "$newrev" | "$home_dir/receiver" "$repo" "$newrev" "$user" "$fingerprint"

What this means is that you can only push master branch and the code comments explicitly says to disable this condition if you want to push other branches. Since I was pushing non master branch removing this condition fixed the issue.