Redirect to the new default branch from a deleted default branch
What does this MR do?
Adds a column to store the old name of the default branch for a project; stores a value in it every time the default branch changes; and sets up a redirect from the old name to the new name if the old one doesn't exist in the repository any more.
For now, only trigger this for projects/blob#show
and projects/tree#show
. However, we may want to roll it out to a number of other controllers in the future: #329100 (comment 620834617)
When it all works together, we get pages like this when visiting, e.g., http://localhost:3000/gitlab-org/gitlab/-/blob/foo-master/README.md:
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Information for database reviewers
db:migrate
== 20210705124128 AddProjectSettingsPreviousDefaultBranch: migrating ==========
-- add_column(:project_settings, :previous_default_branch, :text)
-> 0.0020s
== 20210705124128 AddProjectSettingsPreviousDefaultBranch: migrated (0.0020s) =
== 20210707173645 AddProjectSettingsPreviousDefaultBranchTextLimit: migrating =
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0003s
-- execute("ALTER TABLE project_settings\nADD CONSTRAINT check_3a03e7557a\nCHECK ( char_length(previous_default_branch) <= 4096 )\nNOT VALID;\n")
-> 0.0025s
-- current_schema()
-> 0.0002s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- execute("ALTER TABLE project_settings VALIDATE CONSTRAINT check_3a03e7557a;")
-> 0.0020s
-- execute("RESET ALL")
-> 0.0005s
== 20210707173645 AddProjectSettingsPreviousDefaultBranchTextLimit: migrated (0.0185s)
db:rollback
== 20210707173645 AddProjectSettingsPreviousDefaultBranchTextLimit: reverting =
-- execute("ALTER TABLE project_settings\nDROP CONSTRAINT IF EXISTS check_3a03e7557a\n")
-> 0.0019s
== 20210707173645 AddProjectSettingsPreviousDefaultBranchTextLimit: reverted (0.0084s)
== 20210705124128 AddProjectSettingsPreviousDefaultBranch: reverting ==========
-- remove_column(:project_settings, :previous_default_branch, :text)
-> 0.0052s
== 20210705124128 AddProjectSettingsPreviousDefaultBranch: reverted (0.0066s) =
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
To test this locally, take a random project in GDK and create a new branch that is a copy of master
(I called mine foo-master
).
Change to that as the default branch; previous_default_branch
will then be master
, but since master
exists, no redirect will happen.
Change the default branch back to master
. Still no redirect, but now previous_default_branch
will be foo-master
.
Delete foo-master
. Now visiting a blob, tree, etc, URL will redirect you to the equivalent page for master
.
Related to #329100 (closed)