Adding hooks during repository creation #845

Closed
opened 2025-11-02 03:38:48 -06:00 by GiteaMirror · 13 comments
Owner

Originally created by @TomFreudenberg on GitHub (Jun 26, 2017).

  • 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, in case that your discourse forum currently is empty, I hopefully may ask this question here.

I currently use gitolite for a fine granulated rights management but like to replace it due to the nice interface from gitea and easier user experience.

It seems to me easy just to create some additional git-hooks to gitea which are working like gitolite.

Where is the "best place" to automatically integrate such kind of hooks. As I saw, the hooks from gitea, are prepared at models/repo.go->createDelegateHooks

https://github.com/go-gitea/gitea/blob/master/models/repo.go#L948-L981

Would this be the right place to also add some additional default hooks?

Thanks for a short hint how you would suggest to proceed.

Tom

Originally created by @TomFreudenberg on GitHub (Jun 26, 2017). - 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 - [x] Not relevant - Log gist: ## Description Hi, in case that your discourse forum currently is empty, I hopefully may ask this question here. I currently use gitolite for a fine granulated rights management but like to replace it due to the nice interface from gitea and easier user experience. It seems to me easy just to create some additional git-hooks to gitea which are working like gitolite. Where is the "best place" to automatically integrate such kind of hooks. As I saw, the hooks from gitea, are prepared at models/repo.go->createDelegateHooks > https://github.com/go-gitea/gitea/blob/master/models/repo.go#L948-L981 Would this be the right place to also add some additional default hooks? Thanks for a short hint how you would suggest to proceed. Tom
GiteaMirror added the type/proposaltype/feature labels 2025-11-02 03:38:48 -06:00
Author
Owner

@lunny commented on GitHub (Jun 26, 2017):

You can add your hooks on the UI. on every repository's settings -> hooks

@lunny commented on GitHub (Jun 26, 2017): You can add your hooks on the UI. on every repository's settings -> hooks
Author
Owner

@TomFreudenberg commented on GitHub (Jun 26, 2017):

Hi @lunny

thanks for your feedback.

Yes I know, that I can do this manually every time on a repository. I am looking for a solution to do this automatically every time a repo is newly created.

I would like to check also, if there could be an option to integrate within gitea, that maybe also the groups and rights for a user could be used for a granulated rights management.

So my question is: How to add additional hooks by default during gitea repo creation.

Thanks for help

@TomFreudenberg commented on GitHub (Jun 26, 2017): Hi @lunny thanks for your feedback. Yes I know, that I can do this manually every time on a repository. I am looking for a solution to do this automatically every time a repo is newly created. I would like to check also, if there could be an option to integrate within gitea, that maybe also the groups and rights for a user could be used for a granulated rights management. So my question is: How to add additional hooks by default during gitea repo creation. Thanks for help
Author
Owner

@lafriks commented on GitHub (Jun 26, 2017):

You can change default hook templates system-wide in /usr/share/git-core/templates/hooks/

@lafriks commented on GitHub (Jun 26, 2017): You can change default hook templates system-wide in `/usr/share/git-core/templates/hooks/`
Author
Owner

@TomFreudenberg commented on GitHub (Jun 26, 2017):

Hi @lafriks

ok, that is also an option but in case that they will only make sense to gitea integration and I also want them to be administrateable via the gitea gui, I think those should be added into gitea.

That is at least what I would prefer.

@TomFreudenberg commented on GitHub (Jun 26, 2017): Hi @lafriks ok, that is also an option but in case that they will only make sense to gitea integration and I also want them to be administrateable via the gitea gui, I think those should be added into gitea. That is at least what I would prefer.
Author
Owner

@TomFreudenberg commented on GitHub (Jun 26, 2017):

Content moved to https://github.com/go-gitea/gitea/issues/2090

@TomFreudenberg commented on GitHub (Jun 26, 2017): Content moved to https://github.com/go-gitea/gitea/issues/2090
Author
Owner

@lunny commented on GitHub (Jun 27, 2017):

maybe this PR will fix that? @TomFreudenberg #1975

@lunny commented on GitHub (Jun 27, 2017): maybe this PR will fix that? @TomFreudenberg #1975
Author
Owner

@TomFreudenberg commented on GitHub (Jun 27, 2017):

Content moved to #2090

@TomFreudenberg commented on GitHub (Jun 27, 2017): Content moved to #2090
Author
Owner

@TomFreudenberg commented on GitHub (Jun 29, 2017):

Hi @lunny

should I do something else. If you marked that as feature and proposal, this means it can`t work currently? Correct?

Thanks for some guidiance.
Tom

@TomFreudenberg commented on GitHub (Jun 29, 2017): Hi @lunny should I do something else. If you marked that as feature and proposal, this means it can`t work currently? Correct? Thanks for some guidiance. Tom
Author
Owner

@lafriks commented on GitHub (Jun 29, 2017):

It's marked as proposal for initial issue. Not having values in script arguments is other issue and is probably bug

@lafriks commented on GitHub (Jun 29, 2017): It's marked as proposal for initial issue. ~~Not having values in script arguments is other issue and is probably bug~~
Author
Owner

@lafriks commented on GitHub (Jun 29, 2017):

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
@lafriks commented on GitHub (Jun 29, 2017): 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 ```
Author
Owner

@lunny commented on GitHub (Jun 30, 2017):

@TomFreudenberg I added this proposal and feature that you said

I am looking for a solution to do this automatically every time a repo is newly created.

This is a feature that Gitea didn't support. We need some PRs to do that, So I marked this as kind/feature and kind/proposal. Maybe you can try to do that?

Another issue you mentioned above is that custom hooks is not triggered when push, @lafriks has answered that.

Thanks,
Lunny

@lunny commented on GitHub (Jun 30, 2017): @TomFreudenberg I added this proposal and feature that you said > I am looking for a solution to do this automatically every time a repo is newly created. This is a feature that Gitea didn't support. We need some PRs to do that, So I marked this as `kind/feature` and `kind/proposal`. Maybe you can try to do that? Another issue you mentioned above is that custom hooks is not triggered when push, @lafriks has answered that. Thanks, Lunny
Author
Owner

@TomFreudenberg commented on GitHub (Jun 30, 2017):

To do not overload this ticket, I have created a separate one and moved relevant content away. Hopefully you agree to that procedure.

@TomFreudenberg commented on GitHub (Jun 30, 2017): To do not overload this ticket, I have created a separate one and moved relevant content away. Hopefully you agree to that procedure.
Author
Owner

@lunny commented on GitHub (Nov 12, 2019):

Replaced by #7365

@lunny commented on GitHub (Nov 12, 2019): Replaced by #7365
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#845