gitea: Git-Hook for update does not get the refname, oldrev, newrev as parameter

  • Gitea version (or commit ref): v1.1
  • Git version: 2.10.1 (Apple Git-78)
  • Operating system: OSX/Ubuntu
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

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?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@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

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.

Hi @lafriks @lunny

I can confirm that this fix works now!

Thanks a lot Lauris for doing that fast work.

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