[x]
):Hi, I have tested some simple scripts from here:
https://git-scm.com/book/uz/v2/Customizing-Git-An-Example-Git-Enforced-Policy
and put that as update-hook via Git-Hooks->update
#!/usr/bin/env ruby
$refname = ARGV[0]
$oldrev = ARGV[1]
$newrev = ARGV[2]
$user = ENV['USER']
puts "Enforcing Policies..."
puts "(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
But it seems that the ARGV is empty.
Also a very simple
#!/bin/bash
echo "$1 $2 $3"
doesn't print out anything.
From where in the "hook call" of gitea I will be able to read the refs?
Hint from @lunny
maybe this PR will fix that? @TomFreudenberg #1975
Hi @lunny thanks for guiding me to that PR. It might resolve my issue too, but I can't test it. The patch cannot be cherry-picked to release/v1.1 branch in case of missing integrations/gitea-integration-meta/gitea-repositories/...
I will check if the master branch is working for me with that applied.
Update:
Still no success, the arguments $1, $2, $3 should have been available but they are not.
Seems to me that this might be a bug?
Ok, I did a default git test
git create --bare hooks.git
and then put that above `ruby` example into `hooks.git/hooks/update` and run a test push.
That works like expected:
git push
Counting objects: 3, done. Writing objects: 100% (3/3), 304 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Enforcing Policies... remote: (refs/heads/master) (5317c5) (c59a55) To /tmp/hooks.git 5317c5f..c59a55c master -> master
When I put the same hook script into a gitea repository, I get an error, because arguments $1
, $2
and $3
are empty / not set.
Posted originally from @lafriks
Just checked and hooks seems to work just fine.
pre-receive:
#!/bin/sh
read oldrev newrev refname
echo "(pre-receive) Old revision: $oldrev"
echo "(pre-receive) New revision: $newrev"
echo "(pre-receive) Reference name: $refname"
update:
#!/bin/sh
refname="$1"
oldrev="$2"
newrev="$3"
echo "(update) Old revision: $oldrev"
echo "(update) New revision: $newrev"
echo "(update) Reference name: $refname"
post-receive:
#!/bin/sh
read oldrev newrev refname
echo "(post-receive) Old revision: $oldrev"
echo "(post-receive) New revision: $newrev"
echo "(post-receive) Reference name: $refname"
When pushing to repository I get output:
~/tmp/repo1$ git push
Username for 'http://localhost:3000': user1
Password for 'http://user1@localhost:3000':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 979 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: (pre-receive) Old revision: da71e16f337ac6b7beddaa7eada597b4c3357a9e
remote: (pre-receive) New revision: 0d3b36185327af7e7a6a4725f9bc2084143838d3
remote: (pre-receive) Reference name: refs/heads/master
remote: (update) Old revision: da71e16f337ac6b7beddaa7eada597b4c3357a9e
remote: (update) New revision: 0d3b36185327af7e7a6a4725f9bc2084143838d3
remote: (update) Reference name: refs/heads/master
remote: (post-receive) Old revision: da71e16f337ac6b7beddaa7eada597b4c3357a9e
remote: (post-receive) New revision: 0d3b36185327af7e7a6a4725f9bc2084143838d3
remote: (post-receive) Reference name: refs/heads/master
To http://localhost:3000/user1/repo1.git
da71e16..0d3b361 master -> master
@lunny @lafriks
I still can't reproduce the output from Lauris without doing a patch.
The post-receive and pre-receive hooks are working but not the update hook. I tried this for branch release/v1.1 as well as for master branch.
I have created new repositories all the time via gitea web interface. After that the update hook script of the new repos looks like:
#!/usr/bin/env bash
data=$(cat)
exitcodes=""
hookname=$(basename $0)
GIT_DIR=${GIT_DIR:-$(dirname $0)}
for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
test -x "${hook}" || continue
echo "${data}" | "${hook}"
exitcodes="${exitcodes} $?"
done
for i in ${exitcodes}; do
[ ${i} -eq 0 ] || exit ${i}
done
But as you can see from your integration meta sources at: https://github.com/go-gitea/gitea/blob/master/integrations/gitea-integration-meta/gitea-repositories/user2/repo1.git/hooks/update#L6
the update hook should have forwarded the params 1 to 3, like
echo "${data}" | "${hook}" $1 $2 $3
If I change the update hook script, then I can reproduce the output from Lauris as well.
Thanks for feedback
Did you try running update hooks from administration interface?
Hi @lafriks, what does that mean?
try running update hooks from administration interface?
I do the following:
@TomFreudenberg, I'm sorry I was testing with code I did some fixes :laughing:. On master it does not work, I'll create PR that does fix this problem
@TomFreudenberg can you please check with code from #2095 to see if that fixes your issue?
Hi @lafriks @lunny
I can confirm that this fix works now!
Thanks a lot Lauris for doing that fast work.
Just as an info I post the three hooks working with Ruby Lang as well
post-receive:
#!/usr/bin/env ruby
oldrev, newrev, refname = gets.chomp.split(" ")
puts "(post-receive) Old revision: #{oldrev}"
puts "(post-receive) New revision: #{newrev}"
puts "(post-receive) Reference name: #{refname}"
pre-receive:
#!/usr/bin/env ruby
oldrev, newrev, refname = gets.chomp.split(" ")
puts "(pre-receive) Old revision: #{oldrev}"
puts "(pre-receive) New revision: #{newrev}"
puts "(pre-receive) Reference name: #{refname}"
update:
#!/usr/bin/env ruby
refname = ARGV[0]
oldrev = ARGV[1]
newrev = ARGV[2]
puts "(update) Old revision: #{oldrev}"
puts "(update) New revision: #{newrev}"
puts "(update) Reference name: #{refname}"
@lunny, @lafriks - off-topic question - do you have an approx date for 1.2.0 to be available as branch release/v1.2?
We will create a new service based on gitea (really great project) and I would like to do it with the next stable release and the fixes from above.
Thanks in advance, if you have an idea.
Tom
There are no exact date but after few remaining issues are resolved I think it will be released. It could be in a week or two if no critical issues or upgrade migration issues found that can't be resolved in this time-frame.
Great Lauris, thats what I thought when reading the open issues on the milestone path.
Offtopic:
Hi @lafriks Lauris, sorry for disturbing you again. Do you have some update about 1.2 release date. Thanks for some information. Tom
@TomFreudenberg we are still working on fixing final bugs to release as stable version as possible it is very close but I can't give you exact date
@lafriks Thanks for your update - thats fine for me
Offtopic:
@lafriks Lauris, If we would like to start with working on our servers, what would you prefer? Start with 1.1.3 or use master until 1.2 is ready. Thanks for your suggestion. Tom
@TomFreudenberg 1.2 is close enough to be safe on using master, if you have tried it out and have not encountered any issues that are not critical for you
Most helpful comment
@TomFreudenberg 1.2 is close enough to be safe on using master, if you have tried it out and have not encountered any issues that are not critical for you