puppet-git-hooks icon indicating copy to clipboard operation
puppet-git-hooks copied to clipboard

pre-receive fails due to empty oldrev

Open 2twong opened this issue 10 years ago • 5 comments

oldrev is empty at line 54 which causes git diff on line 57 of pre-receive to fail.

If I checkout master to a new branch, and push the new branch to origin/newbranchname, oldrev == 0{40} in pre-receive, newrev gets set to master, but oldrev gets set to empty and so the git diff on line 57 fails, due to the grep -v master

Reproducer with excerpt from pre-receive with set -x:

$ git branch
* master
$ git checkout -b p/newname
$ git push origin p/newname
..
remote: + oldrev=
remote: ++ git diff --name-only master --diff-filter=ACM
remote: fatal: This operation must be run in a work tree 
..

You can see oldrev is empty because of line 54:

oldrev=`git show-branch | grep -v '\*' | grep -v "master"...`

2twong avatar Nov 19 '15 19:11 2twong

Ya, this has been a long time bug. It only happens (as far as I know) on new branch pushes. I've gotten around it in the past by just disabling the server-side hook when pushing new branches, though I understand that is a horrible work around.

If someone can come up with a way to solve this, I'd love a PR!

drwahl avatar Nov 19 '15 21:11 drwahl

Is there a part of the hook that can be disabled for the case of a new branch push?

2twong avatar Nov 19 '15 21:11 2twong

Actually, looks like I may be off base here. d0a01baa358bf983459e7e0493e84d8a56057b07 addressed the issues I was referring to. I'll need to dig deeper into this to see what is going on...

drwahl avatar Nov 19 '15 21:11 drwahl

Thanks drwahl

2twong avatar Nov 20 '15 18:11 2twong

#71 should fix the issue

jcpunk avatar Mar 23 '16 21:03 jcpunk