Skip to content

DefaultBranch is not set correctly when using template which has 'master' as default #19470

Closed
@sschroe

Description

@sschroe

Description

In #19354 the default branch for new repositories was changed from 'master' to 'main'. When running this new version on existing data where 'master' was still used as default this causes a problem when creating a new repository from a template which still uses 'master'.

The files and master branch are correctly copied to the newly generated repository however giteas internal default branch is set to 'main' instead of 'master'. This causes giteas "Branches" page to remain blank despite showing 1 branch and when cloning the repository git shows warning: remote HEAD refers to nonexistent ref, unable to checkout..

When opening the "Branches" page gitea throws an error: 2022/04/23 10:48:22 ...s/web/repo/branch.go:177:loadBranches() [W] [6263bd56] loadBranches: missing default branch main for 60:sschroe/template_test

Example of a broken repo on the demo site: https://try.gitea.io/steffen/template_test/branches

To reproduce:

  • Run gitea with the default config
  • Create a new template repository and set its main branch to 'master'
  • Create a new repository and select the previously made template with "Git Content(Default Branch)" checked
  • Open the "Branches" page on the new repository

Gitea Version

9550e5a

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

2.36.0

Operating System

Arch Linux

How are you running Gitea?

git clone': git clone --recursive https://github.com/go-gitea/gitea.git
cd gitea
TAGS="bindata sqlite sqlite_unlock_notify" make build
./gitea

Database

SQLite

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/confirmedIssue has been reviewed and confirmed to be present or accepted to be implementedissue/workaroundit is or has a workaroundtype/bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions