Switch main branch

Hi,

Based on Delete Main Branch?, it’s not currently possible to rename the main branch to e.g. “develop” while preserving the “develop” history.

However, is it possible to make the switch by using a set of SQL queries?

Thank you,
Eduard

Hi Eduard,

No. The DB is a black box. Stick your hand in and it might not come back out. :wink:

More seriously, I can’t advise direct DB changes.

Would you mind sharing why the label is such a big deal?

 
Ann

1 Like

Hi Ann,

For my particular project, the last analysis done 6 months ago on the master branch (most likely before starting branch analysis) shows 100 bugs and 500 code smells.
The develop branch has (as we speak) 0 bugs and 200 code smells, and all our PRs are based on it.

However, in the projects view I’m seeing the old stats. For the current state I have to go into the project and manually select the develop branch.

As such, given that you’re at version 7.9 and you should have lots of customers with (possibly) lots of (somehow “neglected”) repos, I’m sure there is out there a way to persuade the DB to switch the main branch, and I would like to avoid reinventing the wheel.

In my particular case, for my current project, it was easier to simply delete all the other branches and rename master to develop. However, it broke my heart since all my work in the last month to eliminate tens of bugs and hundreds of code smells is not visible anymore.

Also, I guess I’ll have to shorten the report retention period in order to get rid of the last analysis done on the master branch, to get clean stats for the current code.

A lot of work (and lost history) for something that should be as easy as changing a quality profile.

Thank you for caring and have a nice day,
Eduard

Hi Eduard,

Thanks for sharing!

If you’re on a commercial edition, then you can rename the master branch (in the branches dropdown, choose ‘Manage branches’ at the bottom, and then use the cog menu on the master branch), but you still can’t switch which branch is used at the main one. You’re looking for this:

MMF-1335 - Allow a different, existing long-lived branch to be designated the Main Branch

Regarding doing this in the DB, my understanding is that it wouldn’t work because of the way, fundamentally, it was implemented. This isn’t as simple as updating a foreign key because the main branch is the project, and branches are essentially just child records.


Sorry, but I don’t understand this part:

 
Ann

Hi Ann,

The Project Activity widget on the main project page was showing:

  • the 6 months old stats on a few pixels on the left side
  • the current stats on a few pixels on the right side
  • 98% of the graph area consisted of straight lines between the old stats and the new stats

As such, it was pretty useless as it was.

By deleting the old stats, the variations in the project’s stats are visible and the widget is useful again.

Thank you,
Eduard

On the other hand, is it possible to decompose the project into it’s long-lived branches and then recompose it with the new main branch under a new name? Changing project keys it’s a supported operation and we can remove the old project after validating the new one.

Eduard

Hi Eduard,

We haven’t built anything to allow you to move branches from one project to another - assuming that’s what you’re asking about.

Let me point out tho that you can re-run history by checking out old versions and analyzing them with sonar.projectDate. You have to start from the oldest date and go forward, tho. No going backward.

 
Ann

Thank you, it makes sense, but it’s not worth it for my current project.
I’ll wait for the official feature :smiley:

Eduard

@ganncamp I see that Log in - SonarSource was just deleted. Do you know if this request is being tracked somewhere else?

Hi @slstarnes,

I hope that it is, but I can’t answer the question. I’ve forwarded this internally to the folks who should know. Hopefully we’ll both have an answer soon.

 
Ann

Hi,

it’s tracked now at the Sonarqube productboard, see

Gilbert

2 Likes

Thanks Gilbert.
Indeed, I invite you from now on to subscribe to future updates and provide feedback on this feature on our roadmap page.
MMF deletion was not intentional and we’ll try to restore it to inform watchers from this move.

1 Like

Hi, what is the status of this? We are needing to do something like this on one of our repos now. We switched the long live branch for analysis from master to dev. We changed the name of the branch in sonarcloud as noted above, but the Main Analysis is not picking up any merges or changes, stating last change over 6 months ago when we had it set to master still.

Thank you for any help.

Hi @kairilliet,

Look for this feature in SonarQube 10.2. I have no timeline for SonarCloud.

Regarding your problem, it deserves a new thread.

 
HTH,
Ann

thank you. If we can’t get it it figured out, I will start a new thread. Appreciate the help.

1 Like