gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Wiki migration from self-hosted GitLab fails if GitLab does not use master as default branch name

Open heapifyman opened this issue 1 year ago • 6 comments

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

  1. Change default branch name of GitLab instance to main - this will result in both project repository and wiki repository to use main as default branch name
  2. In gitea, start a migration from GitLab
  3. Select "Wiki"
  4. 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

swappy-20240131_160917

swappy-20240131_163251

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

heapifyman avatar Jan 31 '24 16:01 heapifyman

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.

yp05327 avatar Jan 31 '24 23:01 yp05327

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.

techknowlogick avatar Jan 31 '24 23:01 techknowlogick

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.git
  • data/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.

heapifyman avatar Jan 31 '24 23:01 heapifyman

Because Gitea uses the hardcoded master Branch for Wikis.

KN4CK3R avatar Feb 01 '24 08:02 KN4CK3R

Because Gitea uses the hardcoded master Branch 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.

heapifyman avatar Feb 02 '24 10:02 heapifyman

We need to store the default branch in database for wiki repository first and then first this problem.

lunny avatar Feb 02 '24 14:02 lunny

Ok. Is there anything I could help with?

heapifyman avatar Feb 04 '24 12:02 heapifyman

Or we can rename GitLab's default branch to main when migrating.

lunny avatar Feb 04 '24 15:02 lunny

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

KN4CK3R avatar Feb 05 '24 14:02 KN4CK3R

-> Make wiki default branch name changable #29603

wxiaoguang avatar Mar 05 '24 06:03 wxiaoguang