Skip to content

hooks broken in 1.1.0 #1250

Closed
Closed
@philfry

Description

@philfry
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions