-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Set the default branch for repositories generated from templates #19136
Conversation
Not sure if the most recent commit will work, if anyone has any suggestions please let me know how to best approach making this simple change functional. |
Will review when I get to my machine, but the CI is failing because you need to |
Yep, thanks :) Oh wait I did it manually based on the diff in the Drone console, hopefully it works just fine 👀 Ok it didn't, I'm just gonna run the command now. I think it was some weird formatting stuff with Vim. |
2010f3e
to
3fbbbe0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, this should also be added to the UI, as currently it only uses default branch.
Second, the current changes are only setting the default in the database, however they are not being passed along to any of the git commands when the repo is initialized.
The API response gives the input default branch, but the actual repository doesn't reflect it.
Particularly, if you follow
gitea/services/repository/template.go
Line 36 in 60fbaa9
if err = repo_module.GenerateGitContent(ctx, templateRepo, generateRepo); err != nil { |
gitea/modules/repository/generate.go Line 211 in 60fbaa9
It seems this is where the default branch for the generated repo is being defined. A request missing the key for Something like: if strings.TrimSpace(repo.DefaultBranch) == "" {
repo.DefaultBranch = templateRepo.DefaultBranch
} |
I think once the API is figured out the UI can be implemented as well. |
Default branch is also used here gitea/modules/repository/init.go Line 106 in 60fbaa9
|
@jolheiser think that should also be implemented in a similar way as of the latest commit. |
e854af1
to
e5f19d0
Compare
Hey @jolheiser sorry to bother you but I think I got it now, would you mind taking a look? |
It looks like this is working via API now. |
Is there anything left for me to do or is this PR mostly set? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see this available in the UI for parity, but I suppose that can be a separate PR since this one also fixes a bug.
Codecov Report
@@ Coverage Diff @@
## main #19136 +/- ##
========================================
Coverage 46.55% 46.56%
========================================
Files 856 857 +1
Lines 123018 123341 +323
========================================
+ Hits 57277 57428 +151
- Misses 58814 58967 +153
- Partials 6927 6946 +19
Continue to review full report at Codecov.
|
Any clue why this is failing CI? |
it's not your fault - it's this TestRepoIndexer. The test is inherently racey and things have now started to become super racey there. I've added #19225 which should resolve the issue. |
Alright, nice! Seems like it finally passed this time. |
…gitea#19136) * Set the default branch for repositories generated from templates * Allows default branch to be set through the API for repos generated from templates * Update swagger API template * Only set default branch to the one from the template if not specified * Use specified default branch if it exists while generating git commits Fix go-gitea#19082 Co-authored-by: John Olheiser <[email protected]> Co-authored-by: zeripath <[email protected]>
Should fix #19082
The generate repository function generates a repository from a template, but when used from the API, it does not seem to have any value returned for the default branch. Seeing as the API was simply returning the generated repository object converted to JSON using a function (which did indeed have the default branch filled out), it seemed likely that the default branch was just not being set for the generate repository. This was fixed simply enough (hopefully correctly) with this PR. Please let me know if I missed something, did something wrong, or anything else :)