gitea
gitea copied to clipboard
Wiki migration from self-hosted GitLab fails if GitLab does not use master as default branch name
Description
When migrating a project including Wiki from a self-hosted GitLab instance the Wiki does not get migrated if GitLab does not use master as the default branch name.
Project code will be migrated but Wiki will be empty.
The log shows the following error message:
gitea | 2024/01/31 15:54:13 ...s/repository/repo.go:104:MigrateRepositoryGitData() [W] Clone wiki: exit status 128 - fatal: Remote branch master not found in upstream origin
This is probably caused by hard-coded Branch: "master", in MigrateRepositoryGitData, line 102 - see https://github.com/go-gitea/gitea/blob/0b1a42ce0f7f8e22d7905bde803d60444c9a9f0b/modules/repository/repo.go#L102
Steps to reproduce
- Change default branch name of GitLab instance to
main- this will result in both project repository and wiki repository to usemainas default branch name - In gitea, start a migration from GitLab
- Select "Wiki"
- Click "Migrate repository"
Result
- Code repository is migrated
- Wiki repository is not migrated
Expected Result
both code repository and wiki repository should be migrated
Gitea Version
gitea:latest and gitea:nightly
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
Git Version
2.43.0
Operating System
Linux
How are you running Gitea?
docker compose, following instructions here: https://docs.gitea.com/next/installation/install-with-docker#basics
Database
None
It depends on GitLab's version: https://docs.gitlab.com/ee/user/project/wiki/index.html#configure-a-default-branch-for-your-wiki So maybe we need to add an option in the migration page.
Thanks for your investigation and detailed report @heapifyman. I suspect the fix for this would be to either fetch the branch name from the Gitlab api or from the initial git clone when fetching the wiki.
If I just remove line 102 Branch: "master", build and run ./gitea web locally, the log does not show any error during migration.
The wiki seems to be cloned correctly then. I get:
data/gitea-repositories/user/migrated-repo.gitdata/gitea-repositories/user/migrated-repo.wiki.git.
I can git clone the .wiki.git from gitea, and all data seems to be there.
But it does not show up in the web UI. I still only see the "Welcome to the Wiki" page - see screenshot above.
Because Gitea uses the hardcoded master Branch for Wikis.
Because Gitea uses the hardcoded
masterBranch for Wikis.
Ah, because of https://github.com/go-gitea/gitea/blob/0b1a42ce0f7f8e22d7905bde803d60444c9a9f0b/services/wiki/wiki.go#L30C2-L30C26
I thought it would be main because of
DEFAULT_BRANCH: main: Default branch name of all repositories.
in https://docs.gitea.com/next/administration/config-cheat-sheet#repository-repository
I tried renaming the imported wiki's default branch to "master" during migration - using function RenameBranch. And that seems to work - at least for my test case.
But I guess people won't expect their branch names to change just because of the import to gitea.
Ideally, wiki repositories should be imported as they are, while wikis created in gitea should follow the DEFAULT_BRANCH setting.
We need to store the default branch in database for wiki repository first and then first this problem.
Ok. Is there anything I could help with?
Or we can rename GitLab's default branch to main when migrating.
main may be a better default for GitLab but the name can be anything.
The default branch for your wiki repository depends on your version of GitLab:
- GitLab versions 14.1 and later: Wikis inherit the default branch name configured for your instance or group. If no custom value is configured, GitLab uses main.
- GitLab versions 14.0 and earlier: GitLab uses master.
For any version of GitLab, you can rename this default branch for previously created wikis.
https://docs.gitlab.com/ee/user/project/wiki/#configure-a-default-branch-for-your-wiki
-> Make wiki default branch name changable #29603