Skip to content
Snippets Groups Projects
Commit 5ba3a39d authored by Jerry Seto's avatar Jerry Seto :two:
Browse files

Cleanup the ambiguous_ref_modal feature flag

Contributes to: #451208
Changelog: changed
parent 050456d2
No related branches found
No related tags found
2 merge requests!158455Backport Release Environments notification pipeline change to 16.11,!149641Cleanup the ambiguous_ref_modal feature flag
Showing with 5 additions and 221 deletions
......@@ -97,14 +97,10 @@ def check_issues_available!
def set_is_ambiguous_ref
return @is_ambiguous_ref if defined? @is_ambiguous_ref
@is_ambiguous_ref = if Feature.enabled?(:ambiguous_ref_modal, @project)
ExtractsRef::RequestedRef
@is_ambiguous_ref = ExtractsRef::RequestedRef
.new(@project.repository, ref_type: ref_type, ref: @ref)
.find
.fetch(:ambiguous, false)
else
false
end
end
def handle_update_result(result)
......
......@@ -156,12 +156,6 @@ def blob
def check_for_ambiguous_ref
@ref_type = ref_type
return if Feature.enabled?(:ambiguous_ref_modal, @project)
if @ref_type == ExtractsRef::RefExtractor::BRANCH_REF_TYPE && ambiguous_ref?(@project, @ref)
branch = @project.repository.find_branch(@ref)
redirect_to project_blob_path(@project, File.join(branch.target, @path))
end
end
def commit
......
......@@ -29,14 +29,6 @@ def show
return render_404 unless @commit
@ref_type = ref_type
if !Feature.enabled?(:ambiguous_ref_modal,
@project) && (@ref_type == BRANCH_REF_TYPE && ambiguous_ref?(@project, @ref))
branch = @project.repository.find_branch(@ref)
if branch
redirect_to project_tree_path(@project, branch.target)
return
end
end
if tree.entries.empty?
if @repository.blob_at(@commit.id, @path)
......
......@@ -176,15 +176,6 @@ def show
@ref_type = 'heads'
if !Feature.enabled?(:ambiguous_ref_modal, @project) && ambiguous_ref?(@project, @ref)
branch = @project.repository.find_branch(@ref)
# The files view would render a ref other than the default branch
# This redirect can be removed once the view is fixed
redirect_to(project_tree_path(@project, branch.target), alert: _("The default branch of this project clashes with another ref"))
return
end
respond_to do |format|
format.html do
@project = @project.present(current_user: current_user)
......
---
name: ambiguous_ref_modal
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/133093
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/429523
milestone: '16.6'
type: development
group: group::source code
default_enabled: false
......@@ -51369,9 +51369,6 @@ msgstr ""
msgid "The default branch for this project has been changed. Please update your bookmarks."
msgstr ""
 
msgid "The default branch of this project clashes with another ref"
msgstr ""
msgid "The dependency list details information about the components used within your project."
msgstr ""
 
......@@ -29,27 +29,10 @@
let(:id) { "#{ref}/#{path}" }
it_behaves_like '#set_is_ambiguous_ref when ref is ambiguous'
context 'and explicitly requesting a branch' do
let(:ref_type) { 'heads' }
it 'redirects to blob#show with sha for the branch' do
expect(response).to redirect_to(project_blob_path(project, "#{RepoHelpers.another_sample_commit.id}/#{path}"))
end
end
context 'and explicitly requesting a tag' do
let(:ref_type) { 'tags' }
it 'responds with success' do
expect(response).to be_ok
end
end
end
describe '#set_is_ambiguous_ref with no ambiguous ref' do
let(:id) { 'master/invalid-path.rb' }
let(:ambiguous_ref_modal) { true }
it_behaves_like '#set_is_ambiguous_ref when ref is not ambiguous'
end
......
......@@ -47,29 +47,6 @@
end
end
context 'when there is a ref and tag with the same name' do
let(:id) { 'ambiguous_ref' }
let(:params) { { namespace_id: project.namespace, project_id: project, id: id, ref_type: ref_type } }
context 'and explicitly requesting a branch' do
let(:ref_type) { 'heads' }
it 'redirects to blob#show with sha for the branch' do
request
expect(response).to redirect_to(project_tree_path(project, RepoHelpers.another_sample_commit.id))
end
end
context 'and explicitly requesting a tag' do
let(:ref_type) { 'tags' }
it 'responds with success' do
request
expect(response).to be_ok
end
end
end
context "valid branch, no path" do
let(:id) { 'flatten-dir' }
......
......@@ -173,122 +173,6 @@ def get_activity(project)
sign_in(user)
end
context "user has access to project" do
before do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
end
context 'when ambiguous_ref_modal is disabled' do
before do
stub_feature_flags(ambiguous_ref_modal: false)
end
context 'when there is a tag with the same name as the default branch' do
let_it_be(:tagged_project) { create(:project, :public, :custom_repo, files: ['somefile']) }
let(:tree_with_default_branch) do
branch = tagged_project.repository.find_branch(tagged_project.default_branch)
project_tree_path(tagged_project, branch.target)
end
before do
tagged_project.repository.create_file(
tagged_project.creator,
'file_for_tag',
'content for file',
message: "Automatically created file",
branch_name: 'branch-to-tag'
)
tagged_project.repository.add_tag(
tagged_project.creator,
tagged_project.default_branch, # tag name
'branch-to-tag' # target
)
end
it 'redirects to tree view for the default branch' do
get :show, params: { namespace_id: tagged_project.namespace, id: tagged_project }
expect(response).to redirect_to(tree_with_default_branch)
end
end
context 'when the default branch name is ambiguous' do
let_it_be(:project_with_default_branch) do
create(:project, :public, :custom_repo, files: ['somefile'])
end
shared_examples 'ambiguous ref redirects' do
let(:project) { project_with_default_branch }
let(:branch_ref) { "refs/heads/#{ref}" }
let(:repo) { project.repository }
before do
repo.create_branch(branch_ref, 'master')
repo.change_head(ref)
end
after do
repo.change_head('master')
repo.delete_branch(branch_ref)
end
subject do
get(
:show,
params: {
namespace_id: project.namespace,
id: project
}
)
end
context 'when there is no conflicting ref' do
let(:other_ref) { 'non-existent-ref' }
it { is_expected.to have_gitlab_http_status(:ok) }
end
context 'and that other ref exists' do
let(:other_ref) { 'master' }
let(:project_default_root_tree_path) do
sha = repo.find_branch(project.default_branch).target
project_tree_path(project, sha)
end
it 'redirects to tree view for the default branch' do
is_expected.to redirect_to(project_default_root_tree_path)
end
end
end
context 'when ref starts with ref/heads/' do
let(:ref) { "refs/heads/#{other_ref}" }
include_examples 'ambiguous ref redirects'
end
context 'when ref starts with ref/tags/' do
let(:ref) { "refs/tags/#{other_ref}" }
include_examples 'ambiguous ref redirects'
end
context 'when ref starts with heads/' do
let(:ref) { "heads/#{other_ref}" }
include_examples 'ambiguous ref redirects'
end
context 'when ref starts with tags/' do
let(:ref) { "tags/#{other_ref}" }
include_examples 'ambiguous ref redirects'
end
end
end
end
describe "when project repository is disabled" do
render_views
......
# frozen_string_literal: true
RSpec.shared_context 'with ambiguous refs for controllers' do
let(:ambiguous_ref_modal) { false }
before do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original # rubocop:disable RSpec/ExpectInHook
project.repository.add_tag(project.creator, 'ambiguous_ref', RepoHelpers.sample_commit.id)
project.repository.add_branch(project.creator, 'ambiguous_ref', RepoHelpers.another_sample_commit.id)
stub_feature_flags(ambiguous_ref_modal: ambiguous_ref_modal)
end
after do
......
......@@ -4,38 +4,21 @@
context 'when the ref_type is nil' do
let(:ref_type) { nil }
it '@ambiguous_ref return false when ff is disabled' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(false)
end
context 'when the ambiguous_ref_modal ff is enabled' do
let(:ambiguous_ref_modal) { true }
it '@ambiguous_ref return true' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(true)
end
it '@ambiguous_ref return true' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(true)
end
end
context 'when the ref_type is empty' do
let(:ref_type) { '' }
it '@ambiguous_ref return false when ff is disabled' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(false)
end
context 'when the ambiguous_ref_modal ff is enabled' do
let(:ambiguous_ref_modal) { true }
it '@ambiguous_ref return true' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(true)
end
it '@ambiguous_ref return true' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(true)
end
end
context 'when the ref_type is present' do
let(:ref_type) { 'heads' }
let(:ambiguous_ref_modal) { true }
it '@ambiguous_ref return false' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(false)
......@@ -46,7 +29,6 @@
RSpec.shared_examples '#set_is_ambiguous_ref when ref is not ambiguous' do
context 'when the ref_type is nil' do
let(:ref_type) { nil }
let(:ambiguous_ref_modal) { true }
it '@ambiguous_ref return false' do
expect(controller.instance_variable_get(:@is_ambiguous_ref)).to eq(false)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment