Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hooks broken in 1.1.0 #1250

Closed
5 of 7 tasks
philfry opened this issue Mar 14, 2017 · 0 comments
Closed
5 of 7 tasks

hooks broken in 1.1.0 #1250

philfry opened this issue Mar 14, 2017 · 0 comments
Labels
Milestone

Comments

@philfry
Copy link
Contributor

philfry commented Mar 14, 2017

  • Gitea version (or commit ref): 1.1.0
  • Git version: 2.12.0
  • Operating system: Linux/CentOS 7
  • 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

The way gitea runs hooks is broken in multiple ways.
First, as with gitea 1.1.0, the files in pre-receive.d, post-receive.d and update.d must be sh scripts (not even bash) as they are invoked using sh $filename. You cannot put binaries or even python scripts into these folders as sh cannot interpret them.
Next, no data is passed to the scripts in post-receive.d. So the scripts won't know about branches, revisions, you name it.

Possible fix - works as pre-receive, post-receive and update:

#!/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+=($?)
done

for i in "${exitcodes[@]}"; do
  [ "${i}" == 0 ] || exit ${i}
done

Please note that the scripts in {{pre,post}-receive,update}.d must have the executable bit set in order to run. So when adding custom hooks using gitea's webinterface gitea is required to set that bit.
Also note that the script above requires bash. If you want to have it shell-agnostic (well, at least sh-agnostic) we'll probably have to rewrite the exitcodes-array-stuff.

@lunny lunny added this to the 1.x.x milestone Mar 14, 2017
@lunny lunny added the type/bug label Mar 14, 2017
@lunny lunny modified the milestones: 1.2.0, 1.x.x Mar 15, 2017
@lunny lunny closed this as completed in fe94032 Mar 23, 2017
lunny pushed a commit that referenced this issue Mar 28, 2017
…t and options hooks (#1376)

* issue #1250, replace {pre,post}-receive and update hooks with a single shell script that does not require custom hooks to be a sh-script

* issue #1250, make script posix compilant

* v23, add migration script to update {pre,post}-receive and update hooks

* migration: use a more common name and rename v23 to v26 to avoid conflicts

* gofmt'ed and added copyright header

* fix SyncRepositoryHooks to also sync wiki repos

* no migration for you.
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants