Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
heapifyman opened this issue Jan 31, 2024 · 10 comments · Fixed by #29603
Labels

Comments

@heapifyman
Copy link

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

Branch: "master",

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

@yp05327
Copy link
Contributor

yp05327 commented Jan 31, 2024

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.

@techknowlogick
Copy link
Member

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.

@heapifyman
Copy link
Author

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.

@KN4CK3R
Copy link
Member

KN4CK3R commented Feb 1, 2024

Because Gitea uses the hardcoded master Branch for Wikis.

@techknowlogick techknowlogick changed the title Wiki mIgration from self-hosted GitLab fails if GitLab does not use master as default branch name Wiki migration from self-hosted GitLab fails if GitLab does not use master as default branch name Feb 1, 2024
@heapifyman
Copy link
Author

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.

@lunny
Copy link
Member

lunny commented Feb 2, 2024

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

@heapifyman
Copy link
Author

Ok. Is there anything I could help with?

@lunny
Copy link
Member

lunny commented Feb 4, 2024

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

@KN4CK3R
Copy link
Member

KN4CK3R commented Feb 5, 2024

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

@wxiaoguang
Copy link
Contributor

-> Make wiki default branch name changable #29603

wxiaoguang added a commit that referenced this issue Mar 6, 2024
Fix #29000
Fix #28685
Fix #18568

Related: #27497

And by the way fix #24036, add a Cancel button there (one line)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants