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