When generating repo from template, default_branch returns as blank string #8696

Closed
opened 2025-11-02 08:14:51 -06:00 by GiteaMirror · 8 comments
Owner

Originally created by @truesteps on GitHub (Mar 14, 2022).

Gitea Version

1.16.3

Git Version

2.25.1

Operating System

Ubuntu 20.04.3 LTS (Focal Fossa)

How are you running Gitea?

I'm running gitea from the binary, through systemctl. I installed it from a tutorial I found online, recently updating it to the latest version, so I can use the generate repo endpoint.

Database

MySQL

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

Whenever I create a new repo from a template repo, I get back the repository detail as the request response, but the default_branch property is returned as an empty string. I think It should be the default branch, since when I fetch the detail of it in the next request, it's there, therefore I concluded this is a bug.

Allow me to send a gist with the entire response from the API https://gist.github.com/truesteps/43b4b13ac3619c92cbdc70c5622c6e02

Screenshots

Screenshot 2022-03-14 at 16 08 41

Originally created by @truesteps on GitHub (Mar 14, 2022). ### Gitea Version 1.16.3 ### Git Version 2.25.1 ### Operating System Ubuntu 20.04.3 LTS (Focal Fossa) ### How are you running Gitea? I'm running gitea from the binary, through systemctl. I installed it from a tutorial I found online, recently updating it to the latest version, so I can use the generate repo endpoint. ### Database MySQL ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Description Whenever I create a new repo from a template repo, I get back the repository detail as the request response, but the `default_branch` property is returned as an empty string. I think It should be the default branch, since when I fetch the detail of it in the next request, it's there, therefore I concluded this is a bug. Allow me to send a gist with the entire response from the API [https://gist.github.com/truesteps/43b4b13ac3619c92cbdc70c5622c6e02](https://gist.github.com/truesteps/43b4b13ac3619c92cbdc70c5622c6e02) ### Screenshots ![Screenshot 2022-03-14 at 16 08 41](https://user-images.githubusercontent.com/12614944/158201589-15bc3280-689e-424b-8ed7-aeeccf92acad.png)
GiteaMirror added the type/bugmodifies/api labels 2025-11-02 08:14:51 -06:00
Author
Owner

@abheekda1 commented on GitHub (Mar 19, 2022):

60fbaa9068/routers/api/v1/repo/repo.go (L425) not sure, but I think the issue stems from here where the created repo object does not have that value and is created by 60fbaa9068/modules/repository/generate.go (L244-L257)

@abheekda1 commented on GitHub (Mar 19, 2022): https://github.com/go-gitea/gitea/blob/60fbaa90683add2a8af891fc2ca8448b9b75c92e/routers/api/v1/repo/repo.go#L425 not sure, but I think the issue stems from here where the created `repo` object does not have that value and is created by https://github.com/go-gitea/gitea/blob/60fbaa90683add2a8af891fc2ca8448b9b75c92e/modules/repository/generate.go#L244-L257
Author
Owner

@truesteps commented on GitHub (Mar 19, 2022):

@ADawesomeguy I think it would make perfect sense to include the default_branch... Maybe even an option to define default_branch? 👼

@truesteps commented on GitHub (Mar 19, 2022): @ADawesomeguy I think it would make perfect sense to include the default_branch... Maybe even an option to define default_branch? 👼
Author
Owner

@abheekda1 commented on GitHub (Mar 19, 2022):

I just had the generated repo define its default branch using the template repo's default branch, so hopefully that should work @truesteps.

@abheekda1 commented on GitHub (Mar 19, 2022): I just had the generated repo define its default branch using the template repo's default branch, so hopefully that should work @truesteps.
Author
Owner

@truesteps commented on GitHub (Mar 19, 2022):

@ADawesomeguy I have an app where I use the api to generate new repos from templates, I allow the user to select a default branch of the generated repo, because it defaults to template default branch, I need to create new branch, change it to default, remove master basically :). It's a workable workaround It just feels like too many extra steps where it could fail for a basic operation.

Thanks for the tip tho!

@truesteps commented on GitHub (Mar 19, 2022): @ADawesomeguy I have an app where I use the api to generate new repos from templates, I allow the user to select a default branch of the generated repo, because it defaults to template default branch, I need to create new branch, change it to default, remove master basically :). It's a workable workaround It just feels like too many extra steps where it could fail for a basic operation. Thanks for the tip tho!
Author
Owner

@abheekda1 commented on GitHub (Mar 19, 2022):

@truesteps wait sorry could you explain that again? I'm a bit confused as to what you want but I'd be happy to give implementing the ideal situation a shot even though I'm a bit lacking in experience.

@abheekda1 commented on GitHub (Mar 19, 2022): @truesteps wait sorry could you explain that again? I'm a bit confused as to what you want but I'd be happy to give implementing the ideal situation a shot even though I'm a bit lacking in experience.
Author
Owner

@truesteps commented on GitHub (Mar 19, 2022):

Basically I would love to be able to pass a default_branch argument to the generate api, so the generated repo has a specific default branch, if left empty, defaults to default branch in template as the current behaviour dictates.

@ADawesomeguy

@truesteps commented on GitHub (Mar 19, 2022): Basically I would love to be able to pass a default_branch argument to the generate api, so the generated repo has a specific default branch, if left empty, defaults to default branch in template as the current behaviour dictates. @ADawesomeguy
Author
Owner

@abheekda1 commented on GitHub (Mar 19, 2022):

Awesome, I'll see if I can add that to my PR.

@abheekda1 commented on GitHub (Mar 19, 2022): Awesome, I'll see if I can add that to my PR.
Author
Owner

@truesteps commented on GitHub (Mar 19, 2022):

@ADawesomeguy thanks dude :) 👍

@truesteps commented on GitHub (Mar 19, 2022): @ADawesomeguy thanks dude :) 👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8696