post-receive hooks don't receive reference information #921

Closed
opened 2025-11-02 03:41:34 -06:00 by GiteaMirror · 8 comments
Owner

Originally created by @Funzinator on GitHub (Jul 27, 2017).

  • Gitea version (or commit ref): 1.1.2
  • Git version: 2.13.1
  • Operating system: FreeBSD 10.3
  • 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

Since the change to use post-receive.d, the stdin is not forwarded to the scripts in post-receive.d.

A common use-case is to execute a post-receive hook only for a certain branch. For that, one would use an approach like in SO:11322356.

I modified the post-receive hook installed by gitea (see below). After that my hook is working fine again. Maybe it's useful to put this in the main gitea repo.

#!/usr/bin/env bash
ORI_DIR=`pwd`
SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
while read oldrev newrev refname
  old=${oldrev:-old}
  new=${newrev:-new}
  ref=${refname:-ref}
done
cd "$ORI_DIR"
for i in `ls "$SHELL_FOLDER/post-receive.d"`; do
    echo "$old $new $ref" | sh "$SHELL_FOLDER/post-receive.d/$i"
done
Originally created by @Funzinator on GitHub (Jul 27, 2017). - Gitea version (or commit ref): 1.1.2 - Git version: 2.13.1 - Operating system: FreeBSD 10.3 - Database (use `[x]`): - [ ] PostgreSQL - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description Since the change to use `post-receive.d`, the stdin is not forwarded to the scripts in `post-receive.d`. A common use-case is to execute a post-receive hook only for a certain branch. For that, one would use an approach like in [SO:11322356](https://stackoverflow.com/questions/11322356/how-to-process-files-on-a-branch-in-post-receive-hook-in-git). I modified the `post-receive` hook installed by gitea (see below). After that my hook is working fine again. Maybe it's useful to put this in the main gitea repo. ``` #!/usr/bin/env bash ORI_DIR=`pwd` SHELL_FOLDER=$(cd "$(dirname "$0")";pwd) while read oldrev newrev refname old=${oldrev:-old} new=${newrev:-new} ref=${refname:-ref} done cd "$ORI_DIR" for i in `ls "$SHELL_FOLDER/post-receive.d"`; do echo "$old $new $ref" | sh "$SHELL_FOLDER/post-receive.d/$i" done ```
GiteaMirror added the issue/not-a-bug label 2025-11-02 03:41:34 -06:00
Author
Owner

@lafriks commented on GitHub (Jul 27, 2017):

I think it should be fixed in master

@lafriks commented on GitHub (Jul 27, 2017): I think it should be fixed in master
Author
Owner

@Funzinator commented on GitHub (Jul 27, 2017):

I saw aff11bc but it doesn't fix it for post-receive; only for update. Maybe I am missing something?

@Funzinator commented on GitHub (Jul 27, 2017): I saw aff11bc but it doesn't fix it for `post-receive`; only for `update`. Maybe I am missing something?
Author
Owner

@lafriks commented on GitHub (Jul 27, 2017):

I think I fixed it with this commit f189ccd

@lafriks commented on GitHub (Jul 27, 2017): I think I fixed it with this commit f189ccd
Author
Owner

@lunny commented on GitHub (Aug 7, 2017):

@Funzinator please confirm.

@lunny commented on GitHub (Aug 7, 2017): @Funzinator please confirm.
Author
Owner

@Funzinator commented on GitHub (Aug 7, 2017):

Yes, it's OK. The FreeBSD ports version is just too old. It is resolved in 1.1.3

@Funzinator commented on GitHub (Aug 7, 2017): Yes, it's OK. The FreeBSD ports version is just too old. It is resolved in 1.1.3
Author
Owner

@HerrHase commented on GitHub (Aug 30, 2017):

I have testet this with gitea-1.1.3-linux-amd64, but it doesen't work. I have tried really different ways to get the name of the current branch, but it is always empty.

@HerrHase commented on GitHub (Aug 30, 2017): I have testet this with gitea-1.1.3-linux-amd64, but it doesen't work. I have tried really different ways to get the name of the current branch, but it is always empty.
Author
Owner

@Funzinator commented on GitHub (Aug 30, 2017):

What is the content of your post-receive file? A fresh installation created a good file for me while an update didn't change existing post-receive scripts in existing repositories.

@Funzinator commented on GitHub (Aug 30, 2017): What is the content of your `post-receive` file? A fresh installation created a good file for me while an update didn't change existing `post-receive` scripts in existing repositories.
Author
Owner

@lafriks commented on GitHub (Aug 30, 2017):

@Funzinator @nirgendswo yes that is bug in 1.1.x that has been fixed in 1.2.0-rc1 version

@lafriks commented on GitHub (Aug 30, 2017): @Funzinator @nirgendswo yes that is bug in 1.1.x that has been fixed in 1.2.0-rc1 version
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#921