Multiple default branches on project

Summary

I'm trying to produce a script that will initialize and setup multiple projects. One part is to create a new branch and set it as default one.

During my test with API, I ended in a strange state : I've multiple default branches on my project.

I tried it again from another tool (Postman) and ended with the same result.

Steps to reproduce

I did it with a bash script, this is the output to help understanding steps. Note : i'm using only APIs

Steps:

  • use the script to create a branch and set it as default one
  • set the new branch as default one
  • do a GET /projects/id/repository/branches => You got multiple default branches

With my shell script :

--- Handling test-branch-default (id: 54756183) ---
Fetching branches...
GET https://gitlab.com/api/v4/projects/54756183/repository/branches
No errors, keep going
list of branches :
main
test
default branch :
test

Creating new branch
POST https://gitlab.com/api/v4/projects/54756183/repository/branches?branch=2024.1&ref=test
No errors, keep going

Setting new branch (2024.1) as default one
PUT https://gitlab.com/api/v4/projects/54756183?default_branch=2024.1
Done

Then I run it again, with a different version name : (I annoted with <===)

--- Handling test-branch-default (id: 54756183) ---
Fetching branches...
GET https://gitlab.com/api/v4/projects/54756183/repository/branches
No errors, keep going
list of branches :
2024.1
main
test
default branch :
2024.1
test <=== I expected "test" to be removed from default branch list

Creating new branch
POST https://gitlab.com/api/v4/projects/54756183/repository/branches?branch=2024.1&ref=2024.1
test <=== I'm using JQ to handle json. the fact that I've two default branch make this "test" appear each time I use a variable where I did store the value of default branch (it now contains the end of line).

Problem with https://gitlab.com/api/v4/projects/54756183/repository/branches?branch=2024.1&ref=2024.1
test
Response :status code : 000
Error while creating branch, skipping this project

Example Project

https://gitlab.com/RemyVillain-Kereis/test-branch-default

What is the current bug behavior?

I now have multiple default branches.

The GET /projects/id has one field "default_branch" with unique value, but If i do a GET /projects/id/repository/branches and check value of "default_branch" on each branch, I manage to find multiple ones with "true" as value.

I can also check it on gitlab.com see image below

What is the expected correct behavior?

I should only have one default branch. I expected that using the API to set a new default branch will automaticl set the old one to default_branch: false

Relevant logs and/or screenshots

multiple_default.png

Output of checks

I'm using gitlab.com, not sure if I should provide anything so ?

This bug happens on GitLab.com

/label ~"reproduced on GitLab.com"

Possible fixes

I did try to set it back with UI in Settings > Repository > default branch, but it doesn't seems to work.

Update : it looks like after a short period of times (10 or 15 minutes ?), something "clean" the state of branches.

Edited by Rémy VILLAIN