Update Hooks are broken when you move gitea to another folder #206

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

Originally created by @cookiengineer on GitHub (Jan 7, 2017).

  • Gitea version: 1.0.1
  • Git version: ?
  • Operating system: Arch Linux ARM, up-to-date
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

Problem Description / Error Message

  1. You can clone, pull whatever. SSH properly setup and blabla.
  2. Error message on push is the following (where git-mirror is the host for the machine).
[lycheejs] (development)$ git push mirror development
Counting objects: 80, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (76/76), done.
Writing objects: 100% (80/80), 15.28 KiB | 0 bytes/s, done.
Total 80 (delta 50), reused 0 (delta 0)

# XXX: Note this /home/alarm/gitea path, this is the outdated update hook path
remote: hooks/update: line 2: /home/alarm/gitea: Permission denied

remote: error: hook declined to update refs/heads/development
To git-mirror:Artificial-Engineering/lycheejs.git
 ! [remote rejected] development -> development (hook declined)
error: failed to push some refs to 'git@git-mirror:Artificial-Engineering/lycheejs.git'

Steps to reproduce

  1. Installed gitea to /home/alarm to experiment around, start it and configure it.
  2. Setup correct git user account.
  3. Later moved things to /opt/gitea because I have an external HDD mount there (running on a Raspberry Pi 2).
  4. Everything was configurable and modifyable in the custom/conf/app.ini
  5. EXCEPT the update hooks. Those contain static paths to the old binary.

Quickfix for others

I made a little script that assumes the ./gitea-repositories folder is in the same folder as the gitea binary and that fixes all update hooks once run. In my case it's located in /opt/gitea/fix_repos.js where repos are in /opt/gitea/gitea-repositories. Link to the fix_repos.js script.

Problems caused

I saw a couple issues in upstream gogs where people had the same problems. It is totally unclear that you cannot move around gitea because I would assume that a binary can be copy/pasted with its config files and it should work isolated in that folder.

Suggestion

Maybe it makes sense to have a bootup routine that does a sanity checks for all update hooks when the gitea web service is started. So that it just makes sure that all paths are up to date and point to the correct binary.

Originally created by @cookiengineer on GitHub (Jan 7, 2017). - Gitea version: 1.0.1 - Git version: ? - Operating system: Arch Linux ARM, up-to-date - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant ## Description **Problem Description / Error Message** 1. You can clone, pull whatever. SSH properly setup and blabla. 2. Error message on push is the following (where `git-mirror` is the host for the machine). ```bash [lycheejs] (development)$ git push mirror development Counting objects: 80, done. Delta compression using up to 4 threads. Compressing objects: 100% (76/76), done. Writing objects: 100% (80/80), 15.28 KiB | 0 bytes/s, done. Total 80 (delta 50), reused 0 (delta 0) # XXX: Note this /home/alarm/gitea path, this is the outdated update hook path remote: hooks/update: line 2: /home/alarm/gitea: Permission denied remote: error: hook declined to update refs/heads/development To git-mirror:Artificial-Engineering/lycheejs.git ! [remote rejected] development -> development (hook declined) error: failed to push some refs to 'git@git-mirror:Artificial-Engineering/lycheejs.git' ``` **Steps to reproduce** 1. Installed gitea to `/home/alarm` to experiment around, start it and configure it. 2. Setup correct `git` user account. 3. Later moved things to `/opt/gitea` because I have an external HDD mount there (running on a Raspberry Pi 2). 4. Everything was configurable and modifyable in the `custom/conf/app.ini` 5. **EXCEPT** the update hooks. Those contain static paths to the old binary. **Quickfix for others** I made a little script that assumes the `./gitea-repositories` folder is in the same folder as the gitea binary and that fixes all update hooks once run. In my case it's located in `/opt/gitea/fix_repos.js` where repos are in `/opt/gitea/gitea-repositories`. Link to the [fix_repos.js script](https://gist.github.com/cookiengineer/94125ec97f5e0ca7d5d048cfe7ec442e). **Problems caused** I saw a couple issues in upstream gogs where people had the same problems. It is totally unclear that you cannot move around gitea because I would assume that a binary can be copy/pasted with its config files and it should work isolated in that folder. **Suggestion** Maybe it makes sense to have a bootup routine that does a sanity checks for all update hooks when the gitea web service is started. So that it just makes sure that all paths are up to date and point to the correct binary.
GiteaMirror added the issue/not-a-bug label 2025-11-02 03:13:54 -06:00
Author
Owner

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

Enter Gitea admin panel on the UI, run Rewrite '.ssh/authorized_keys' file (caution: non-Gitea keys will be lost) and Rewrite all update hook of repositories (needed when custom config path is changed).

@lunny commented on GitHub (Jan 7, 2017): Enter Gitea admin panel on the UI, run Rewrite '.ssh/authorized_keys' file (caution: non-Gitea keys will be lost) and Rewrite all update hook of repositories (needed when custom config path is changed).
Author
Owner

@tboerger commented on GitHub (Jan 16, 2017):

Since the data is a static part it must be rewritten within the admin ui.

@tboerger commented on GitHub (Jan 16, 2017): Since the data is a static part it must be rewritten within the admin ui.
Author
Owner

@ve3 commented on GitHub (Apr 30, 2019):

First I try to push git but get this error.

[remote rejected] master -> master (pre-receive hook declined)

I run Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.) but got error.

open C:\Windows\system32\config\systemprofile.ssh\authorized_keys.tmp: The system cannot find the path specified.

Then I run Resynchronize pre-receive, update and post-receive hooks of all repositories.

And I try to push again and everything works fine.

I'm not sure is that for this or update .ssh/authorized_keys work even it display error or something but it work! I don't know why.

@ve3 commented on GitHub (Apr 30, 2019): First I try to push git but get this error. > [remote rejected] master -> master (pre-receive hook declined) I run `Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.)` but got error. > open C:\Windows\system32\config\systemprofile\.ssh\authorized_keys.tmp: The system cannot find the path specified. Then I run `Resynchronize pre-receive, update and post-receive hooks of all repositories.` And I try to push again and everything works fine. I'm not sure is that for this or update `.ssh/authorized_keys` work even it display error or something but it work! I don't know why.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#206