Git Hooks not editable and not working #3370

Closed
opened 2025-11-02 05:10:26 -06:00 by GiteaMirror · 19 comments
Owner

Originally created by @ghost on GitHub (May 23, 2019).

  • Gitea version (or commit ref): gitea/gitea:latest from docker-hub as of posting
  • Git version: 2.20
  • Operating system: Debian 9.9
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
    • Not possible

Description

Hi all,

I have successfully setup Gitea in a Docker environment using the official docker-compose.yml file to have things set up. All repositories are now migrated and I wanted to get my hooks done as well.

Coming from the git console, I was creating a post-receive file directly in the hooks directory and entered my code. However, after committing and pushing my changes to Gitea, the hook is not fired. I have tested the script alone and it worked perfectly. Next, I moved the script to the post-receive.d directory and tested it again with no effect.

I googled a bit and found out, that the hooks can be entered via the GUI in settings, too. The post-receive indicator is green (only if the file is in the post-receive.d folder). But, there is no way to edit the hooks! I found a screenshot where there is an edit button after each hook type but not in my setup (see screenshots below).

I tested it on various browsers, there are no edit buttons.

How do I get those edit buttons and how do I get Gitea to fire the hooks?

Thanks!

Screenshots

How I would expect it:
image

How it is on my setup
image

Originally created by @ghost on GitHub (May 23, 2019). - Gitea version (or commit ref): gitea/gitea:latest from docker-hub as of posting - Git version: 2.20 - Operating system: Debian 9.9 - Database (use `[x]`): - [ ] PostgreSQL - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [ ] Not relevant - [x] Not possible ## Description Hi all, I have successfully setup Gitea in a Docker environment using the official docker-compose.yml file to have things set up. All repositories are now migrated and I wanted to get my hooks done as well. Coming from the git console, I was creating a post-receive file directly in the hooks directory and entered my code. However, after committing and pushing my changes to Gitea, the hook is not fired. I have tested the script alone and it worked perfectly. Next, I moved the script to the post-receive.d directory and tested it again with no effect. I googled a bit and found out, that the hooks can be entered via the GUI in settings, too. The post-receive indicator is green (only if the file is in the post-receive.d folder). But, there is no way to edit the hooks! I found a screenshot where there is an edit button after each hook type but not in my setup (see screenshots below). I tested it on various browsers, there are no edit buttons. How do I get those edit buttons and how do I get Gitea to fire the hooks? Thanks! ## Screenshots How I would expect it: ![image](https://user-images.githubusercontent.com/14041595/58292856-5afaee80-7dc3-11e9-82b3-e00f832d94f8.png) How it is on my setup ![image](https://user-images.githubusercontent.com/14041595/58292903-8087f800-7dc3-11e9-89b3-3b737f711615.png)
GiteaMirror added the type/question label 2025-11-02 05:10:26 -06:00
Author
Owner

@ghost commented on GitHub (May 24, 2019):

Somehow, latest is Gitea Version: 1.9.0+dev-274-g6ff9349a0

@ghost commented on GitHub (May 24, 2019): Somehow, latest is Gitea Version: 1.9.0+dev-274-g6ff9349a0
Author
Owner

@zeripath commented on GitHub (May 24, 2019):

How are you pushing?

If you are pushing by SSH are you sure that you're pushing with a key managed by Gitea?

If you push with a key that is not managed by Gitea its hooks will not run.

To test whether you are pushing with a key managed by Gitea you should SSH to the Gitea server as the git user and if you get a terminal rather than being told Gitea does not provide a shell then you are not pushing with a Gitea managed key.

@zeripath commented on GitHub (May 24, 2019): How are you pushing? If you are pushing by SSH are you sure that you're pushing with a key managed by Gitea? If you push with a key that is not managed by Gitea its hooks will not run. To test whether you are pushing with a key managed by Gitea you should SSH to the Gitea server as the git user and if you get a terminal rather than being told Gitea does not provide a shell then you are not pushing with a Gitea managed key.
Author
Owner

@lafriks commented on GitHub (May 24, 2019):

Might be that your user does not have edit hooks rights or you have hooks editing disabled in app.ini

@lafriks commented on GitHub (May 24, 2019): Might be that your user does not have edit hooks rights or you have hooks editing disabled in app.ini
Author
Owner

@ghost commented on GitHub (May 25, 2019):

Might be that your user does not have edit hooks rights or you have hooks editing disabled in app.ini

I added specifically DISABLE_GIT_HOOKS = false in the app.ini located in

/var/lib/docker/volumes/gitea_main_data/_data/gitea/conf# nano app.ini

I restarted the service but that wasn't the issue.

I am using an organisation which owns the repository and my user is member of that organisation. My user is administrator, too. So I should have the privileagues. Do you have any other ideas?

@ghost commented on GitHub (May 25, 2019): > Might be that your user does not have edit hooks rights or you have hooks editing disabled in app.ini I added specifically DISABLE_GIT_HOOKS = false in the app.ini located in `/var/lib/docker/volumes/gitea_main_data/_data/gitea/conf# nano app.ini` I restarted the service but that wasn't the issue. I am using an organisation which owns the repository and my user is member of that organisation. My user is administrator, too. So I should have the privileagues. Do you have any other ideas?
Author
Owner

@zeripath commented on GitHub (May 25, 2019):

How are you pushing?

@zeripath commented on GitHub (May 25, 2019): How are you pushing?
Author
Owner

@ghost commented on GitHub (May 25, 2019):

How are you pushing?

I push with HTTPS and not SSH.

@ghost commented on GitHub (May 25, 2019): > How are you pushing? I push with HTTPS and not SSH.
Author
Owner

@zeripath commented on GitHub (May 25, 2019):

Are you sure that you have the repositories directory mounted executable?

@zeripath commented on GitHub (May 25, 2019): Are you sure that you have the repositories directory mounted executable?
Author
Owner

@ghost commented on GitHub (May 25, 2019):

bash-4.4# pwd
/data/git/repositories/wordpress/ziin_hp_wp.git
bash-4.4# ls -lah
total 248
drwxr-xr-x    8 git      git         4.0K May 23 21:17 .
drwxr-xr-x    4 git      git         4.0K Apr 24 21:38 ..
-rw-r--r--    1 root     root          23 May 23 18:01 HEAD
-rw-r--r--    1 root     root          41 May 23 18:02 ORIG_HEAD
drwxr-xr-x    2 git      git         4.0K Feb 18 18:01 branches
-rw-r--r--    1 git      git           66 Feb 18 18:01 config
-rw-r--r--    1 git      git           73 Feb 18 18:01 description
drwxr-xr-x    5 git      git         4.0K May 23 23:10 hooks
-rw-r--r--    1 root     root      198.9K May 23 18:02 index
drwxr-xr-x    2 git      git         4.0K May 13 09:03 info
drwxr-xr-x    2 git      git         4.0K Apr 23 15:20 logs
drwxr-xr-x  147 git      git         4.0K May 23 21:17 objects
drwxr-xr-x    4 git      git         4.0K Feb 18 18:01 refs
bash-4.4#
@ghost commented on GitHub (May 25, 2019): ``` bash-4.4# pwd /data/git/repositories/wordpress/ziin_hp_wp.git bash-4.4# ls -lah total 248 drwxr-xr-x 8 git git 4.0K May 23 21:17 . drwxr-xr-x 4 git git 4.0K Apr 24 21:38 .. -rw-r--r-- 1 root root 23 May 23 18:01 HEAD -rw-r--r-- 1 root root 41 May 23 18:02 ORIG_HEAD drwxr-xr-x 2 git git 4.0K Feb 18 18:01 branches -rw-r--r-- 1 git git 66 Feb 18 18:01 config -rw-r--r-- 1 git git 73 Feb 18 18:01 description drwxr-xr-x 5 git git 4.0K May 23 23:10 hooks -rw-r--r-- 1 root root 198.9K May 23 18:02 index drwxr-xr-x 2 git git 4.0K May 13 09:03 info drwxr-xr-x 2 git git 4.0K Apr 23 15:20 logs drwxr-xr-x 147 git git 4.0K May 23 21:17 objects drwxr-xr-x 4 git git 4.0K Feb 18 18:01 refs bash-4.4# ```
Author
Owner

@zeripath commented on GitHub (May 25, 2019):

I mean the mount, not the directory.

@zeripath commented on GitHub (May 25, 2019): I mean the mount, not the directory.
Author
Owner

@ghost commented on GitHub (May 25, 2019):

I use Docker volumes. My docker-compose.yml uses the following statements to mount the volume:

Withhin the service:

volumes:
      - 'main_data:/data'

And the Volumes defintion:

volumes:
  mysql_data:
    driver: local
  main_data:
    driver: local

How do I make it executable?

I tried to execute the post-receive hook from the container and it worked, though.

@ghost commented on GitHub (May 25, 2019): I use Docker volumes. My docker-compose.yml uses the following statements to mount the volume: Withhin the service: ``` volumes: - 'main_data:/data' ``` And the Volumes defintion: ``` volumes: mysql_data: driver: local main_data: driver: local ``` How do I make it executable? I tried to execute the post-receive hook from the container and it worked, though.
Author
Owner

@zeripath commented on GitHub (May 25, 2019):

just check mount from within the gitea container - but the fact that you say you can execute the hooks makes this less suspect.

What is more concerning is that the index, HEAD and ORIG_HEAD being owned by root in that repository.

Being unable to update HEAD could easily be cause for things failing. I'm fairly certain that everything in those repositories should be owned by git.

@zeripath commented on GitHub (May 25, 2019): just check mount from within the gitea container - but the fact that you say you can execute the hooks makes this less suspect. What is more concerning is that the index, HEAD and ORIG_HEAD being owned by root in that repository. Being unable to update HEAD could easily be cause for things failing. I'm fairly certain that everything in those repositories should be owned by git.
Author
Owner

@ghost commented on GitHub (May 25, 2019):

Here is what my mount settings looks from the container:

Mounts
0
Destination /data
Driver local
Mode z
Name gitea_main_data
Propagation
RW true
Source /var/lib/docker/volumes/gitea_main_data/_data
Type volume

I rechecked that I can execute scripts from within the container. I logged in the container, switched from user root to git, created an executable shell script, added some stuff and executed it. Worked like a charm.

I changed recursively the owner to git:git for all files.

I pushed and it's the same issue :-(

@ghost commented on GitHub (May 25, 2019): Here is what my mount settings looks from the container: ``` Mounts 0 Destination /data Driver local Mode z Name gitea_main_data Propagation RW true Source /var/lib/docker/volumes/gitea_main_data/_data Type volume ``` I rechecked that I can execute scripts from within the container. I logged in the container, switched from user root to git, created an executable shell script, added some stuff and executed it. Worked like a charm. I changed recursively the owner to git:git for all files. I pushed and it's the same issue :-(
Author
Owner

@ghost commented on GitHub (May 25, 2019):

Just to be on the safe side:

I added my post-receive hook under

/var/lib/docker/volumes/gitea_main_data/_data/git/repositories/wordpress/ziin_hp_wp.git/hooks/post-receive.d

The file is also called post-receive.

drwxr-xr-x 2 git git 4.0K May 25 19:55 .
drwxr-xr-x 5 git git 4.0K May 24 01:10 ..
-rwxr-xr-x 1 git git   93 Feb 18 19:01 gitea
-rwxr-xr-x 1 git git  967 May 23 20:06 post-receive
root:/var/lib/docker/volumes/gitea_main_data/_data/git/repositories/wordpress/ziin_hp_wp.git/hooks/post-receive.d#
@ghost commented on GitHub (May 25, 2019): Just to be on the safe side: I added my post-receive hook under `/var/lib/docker/volumes/gitea_main_data/_data/git/repositories/wordpress/ziin_hp_wp.git/hooks/post-receive.d` The file is also called `post-receive`. ``` drwxr-xr-x 2 git git 4.0K May 25 19:55 . drwxr-xr-x 5 git git 4.0K May 24 01:10 .. -rwxr-xr-x 1 git git 93 Feb 18 19:01 gitea -rwxr-xr-x 1 git git 967 May 23 20:06 post-receive root:/var/lib/docker/volumes/gitea_main_data/_data/git/repositories/wordpress/ziin_hp_wp.git/hooks/post-receive.d# ```
Author
Owner

@zeripath commented on GitHub (May 25, 2019):

You need to check these things from within the docker itself. It doesn't matter what you can do outside of the docker.

docker exec -it gitea_docker_name "bash"

And then check these things.

@zeripath commented on GitHub (May 25, 2019): You need to check these things from within the docker itself. It doesn't matter what you can do outside of the docker. ``` docker exec -it gitea_docker_name "bash" ``` And then check these things.
Author
Owner

@ghost commented on GitHub (May 26, 2019):

First, I have reset my Docker environment. At least, the edit buttons are now back. It must be something from an older update, I don't know. At least, I see the edit buttons and have now entered the hook over the GUI. Still, it is not executed.

@ghost commented on GitHub (May 26, 2019): First, I have reset my Docker environment. At least, the edit buttons are now back. It must be something from an older update, I don't know. At least, I see the edit buttons and have now entered the hook over the GUI. Still, it is not executed.
Author
Owner

@ghost commented on GitHub (May 26, 2019):

You need to check these things from within the docker itself. It doesn't matter what you can do outside of the docker.

docker exec -it gitea_docker_name "bash"

And then check these things.

bash-4.4# ls -l
total 8
-rwxrwx---    1 git      git             93 May 26 11:39 gitea
-rwxrwx---    1 git      git            965 May 26 11:53 post-receive
bash-4.4# ./post-receive
bash-4.4# pwd
/data/git/repositories/wordpress/ziin_hp_wp.git/hooks/post-receive.d
bash-4.4#

I can successfully execute the hook manually.

@ghost commented on GitHub (May 26, 2019): > You need to check these things from within the docker itself. It doesn't matter what you can do outside of the docker. > > ``` > docker exec -it gitea_docker_name "bash" > ``` > > And then check these things. ``` bash-4.4# ls -l total 8 -rwxrwx--- 1 git git 93 May 26 11:39 gitea -rwxrwx--- 1 git git 965 May 26 11:53 post-receive bash-4.4# ./post-receive bash-4.4# pwd /data/git/repositories/wordpress/ziin_hp_wp.git/hooks/post-receive.d bash-4.4# ``` I can successfully execute the hook manually.
Author
Owner

@ghost commented on GitHub (May 26, 2019):

Ok, it works!!! It was my fault. I tested the hook as root but not as git user. When running as git user, it finally through an error I could trace. The hook is now fired when the icons are visible. On my other instance, it is not fired. So I will use the new instance. Before closing the ticket, I need your help one more time.

The post-receive hook should make a checkout on the same machine but not within the container but on the host (web server). I have added a bind mount to the www directory. As the git user has no privileges on the www folder, I changed the owner to root:git and added the SETUID flag to the post-receive hook for the group and user (as the script can write to the file system as root from the container). However, though using the SETUID, I get a permission error. Is there a way to solve this?

I have also tried to add the git user/group to my docker machine with the same UIDs/GUIs and added the git group as secondary group to the www user without success.

Can you help me with that?

@ghost commented on GitHub (May 26, 2019): Ok, it works!!! It was my fault. I tested the hook as root but not as git user. When running as git user, it finally through an error I could trace. The hook is now fired when the icons are visible. On my other instance, it is not fired. So I will use the new instance. Before closing the ticket, I need your help one more time. The post-receive hook should make a checkout on the same machine but not within the container but on the host (web server). I have added a bind mount to the www directory. As the git user has no privileges on the www folder, I changed the owner to root:git and added the SETUID flag to the post-receive hook for the group and user (as the script can write to the file system as root from the container). However, though using the SETUID, I get a permission error. Is there a way to solve this? I have also tried to add the git user/group to my docker machine with the same UIDs/GUIs and added the git group as secondary group to the www user without success. Can you help me with that?
Author
Owner

@ghost commented on GitHub (May 28, 2019):

Ok, not possible :-), at least with bind mounts. Thanks for all the support!

@ghost commented on GitHub (May 28, 2019): Ok, not possible :-), at least with bind mounts. Thanks for all the support!
Author
Owner

@shanyu-e commented on GitHub (Apr 27, 2020):

#6415 this worked for me - USER_UID=1026 - USER_GID=100,and named volumes I think also can be worked.

@shanyu-e commented on GitHub (Apr 27, 2020): #6415 this worked for me - USER_UID=1026 - USER_GID=100,and named volumes I think also can be worked.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3370