Commit 37904108 authored by Stan Hu's avatar Stan Hu

Fix inconsistent number of branches when remote branches are present

Users of project mirrors would see that the number of branches did not
match the number in the branch dropdown because remote branches were
counted when Rugged was in use. With Gitaly, only local branches
are counted.

Closes #36934
parent 539ed0a6
...@@ -153,7 +153,7 @@ module Gitlab ...@@ -153,7 +153,7 @@ module Gitlab
if is_enabled if is_enabled
gitaly_ref_client.count_branch_names gitaly_ref_client.count_branch_names
else else
rugged.branches.count do |ref| rugged.branches.each(:local).count do |ref|
begin begin
ref.name && ref.target # ensures the branch is valid ref.name && ref.target # ensures the branch is valid
......
...@@ -977,6 +977,36 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -977,6 +977,36 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'returns the number of branches' do it 'returns the number of branches' do
expect(repository.branch_count).to eq(10) expect(repository.branch_count).to eq(10)
end end
context 'with local and remote branches' do
let(:repository) do
Gitlab::Git::Repository.new('default', File.join(TEST_MUTABLE_REPO_PATH, '.git'))
end
before do
create_remote_branch(repository, 'joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master')
end
after do
FileUtils.rm_rf(TEST_MUTABLE_REPO_PATH)
ensure_seeds
end
it 'returns the count of local branches' do
expect(repository.branch_count).to eq(repository.local_branches.count)
end
context 'with Gitaly disabled' do
before do
allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(false)
end
it 'returns the count of local branches' do
expect(repository.branch_count).to eq(repository.local_branches.count)
end
end
end
end end
describe "#ls_files" do describe "#ls_files" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment