Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
commite4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch)
tree2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /spec/lib/gitlab/git
parentffda4e7bcac36987f936b4ba515995a6698698f0 (diff)
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/git')
-rw-r--r--spec/lib/gitlab/git/base_error_spec.rb29
-rw-r--r--spec/lib/gitlab/git/blame_spec.rb2
-rw-r--r--spec/lib/gitlab/git/blob_spec.rb68
-rw-r--r--spec/lib/gitlab/git/commit_spec.rb5
-rw-r--r--spec/lib/gitlab/git/compare_spec.rb18
-rw-r--r--spec/lib/gitlab/git/diff_collection_spec.rb16
-rw-r--r--spec/lib/gitlab/git/finders/refs_finder_spec.rb62
-rw-r--r--spec/lib/gitlab/git/keep_around_spec.rb15
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb56
-rw-r--r--spec/lib/gitlab/git/tree_spec.rb9
10 files changed, 221 insertions, 59 deletions
diff --git a/spec/lib/gitlab/git/base_error_spec.rb b/spec/lib/gitlab/git/base_error_spec.rb
index d4db7cf2430..6efebd778b7 100644
--- a/spec/lib/gitlab/git/base_error_spec.rb
+++ b/spec/lib/gitlab/git/base_error_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Git::BaseError do
it { is_expected.to eq(result) }
end
- describe "When initialized with GRPC errors" do
+ describe "when initialized with GRPC errors without metadata" do
let(:grpc_error) { GRPC::DeadlineExceeded.new }
let(:git_error) { described_class.new grpc_error }
@@ -29,6 +29,33 @@ RSpec.describe Gitlab::Git::BaseError do
expect(git_error.service).to eq('git')
expect(git_error.status).to eq(4)
expect(git_error.code).to eq('deadline_exceeded')
+ expect(git_error.metadata).to eq({})
+ end
+ end
+
+ describe "when initialized with GRPC errors with metadata" do
+ let(:grpc_error) do
+ GRPC::DeadlineExceeded.new(
+ "deadline exceeded",
+ gitaly_error_metadata: {
+ storage: "default",
+ address: "unix://gitaly.socket",
+ service: :ref_service, rpc: :find_local_branches
+ }
+ )
+ end
+
+ let(:git_error) { described_class.new grpc_error }
+
+ it "has status, code, and metadata fields" do
+ expect(git_error.service).to eq('git')
+ expect(git_error.status).to eq(4)
+ expect(git_error.code).to eq('deadline_exceeded')
+ expect(git_error.metadata).to eq(
+ storage: "default",
+ address: "unix://gitaly.socket",
+ service: :ref_service, rpc: :find_local_branches
+ )
end
end
end
diff --git a/spec/lib/gitlab/git/blame_spec.rb b/spec/lib/gitlab/git/blame_spec.rb
index 45d88f57c09..676ea2663d2 100644
--- a/spec/lib/gitlab/git/blame_spec.rb
+++ b/spec/lib/gitlab/git/blame_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Git::Blame do
let(:path) { 'CONTRIBUTING.md' }
let(:range) { nil }
- subject(:blame) { Gitlab::Git::Blame.new(repository, sha, path, range: range) }
+ subject(:blame) { described_class.new(repository, sha, path, range: range) }
let(:result) do
[].tap do |data|
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb
index d35d288050a..5bb4b84835d 100644
--- a/spec/lib/gitlab/git/blob_spec.rb
+++ b/spec/lib/gitlab/git/blob_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::Git::Blob do
let_it_be(:repository) { project.repository.raw }
describe 'initialize' do
- let(:blob) { Gitlab::Git::Blob.new(name: 'test') }
+ let(:blob) { described_class.new(name: 'test') }
it 'handles nil data' do
expect(described_class).not_to receive(:gitlab_blob_size)
@@ -20,14 +20,14 @@ RSpec.describe Gitlab::Git::Blob do
it 'records blob size' do
expect(described_class).to receive(:gitlab_blob_size).and_call_original
- Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd')
+ described_class.new(name: 'test', size: 4, data: 'abcd')
end
context 'when untruncated' do
it 'attempts to record gitlab_blob_truncated_false' do
expect(described_class).to receive(:gitlab_blob_truncated_false).and_call_original
- Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd')
+ described_class.new(name: 'test', size: 4, data: 'abcd')
end
end
@@ -35,32 +35,32 @@ RSpec.describe Gitlab::Git::Blob do
it 'attempts to record gitlab_blob_truncated_true' do
expect(described_class).to receive(:gitlab_blob_truncated_true).and_call_original
- Gitlab::Git::Blob.new(name: 'test', size: 40, data: 'abcd')
+ described_class.new(name: 'test', size: 40, data: 'abcd')
end
end
end
shared_examples '.find' do
context 'nil path' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], nil) }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], nil) }
it { expect(blob).to eq(nil) }
end
context 'utf-8 branch' do
- let(:blob) { Gitlab::Git::Blob.find(repository, 'Ääh-test-utf-8', "files/ruby/popen.rb") }
+ let(:blob) { described_class.find(repository, 'Ääh-test-utf-8', "files/ruby/popen.rb") }
it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) }
end
context 'blank path' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], '') }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], '') }
it { expect(blob).to eq(nil) }
end
context 'file in subdir' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "files/ruby/popen.rb") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], "files/ruby/popen.rb") }
it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) }
it { expect(blob.name).to eq(SeedRepo::RubyBlob::NAME) }
@@ -72,7 +72,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'file in root' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], ".gitignore") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], ".gitignore") }
it { expect(blob.id).to eq("dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82") }
it { expect(blob.name).to eq(".gitignore") }
@@ -85,7 +85,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'file in root with leading slash' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "/.gitignore") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], "/.gitignore") }
it { expect(blob.id).to eq("dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82") }
it { expect(blob.name).to eq(".gitignore") }
@@ -97,13 +97,13 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'non-exist file' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "missing.rb") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], "missing.rb") }
it { expect(blob).to be_nil }
end
context 'six submodule' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], 'six') }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], 'six') }
it { expect(blob.id).to eq('409f37c4f05865e4fb208c771485f211a22c4c2d') }
it { expect(blob.data).to eq('') }
@@ -119,7 +119,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'large file' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], 'files/images/6049019_460s.jpg') }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], 'files/images/6049019_460s.jpg') }
let(:blob_size) { 111803 }
let(:stub_limit) { 1000 }
@@ -141,7 +141,7 @@ RSpec.describe Gitlab::Git::Blob do
end
it 'marks the blob as binary' do
- expect(Gitlab::Git::Blob).to receive(:new)
+ expect(described_class).to receive(:new)
.with(hash_including(binary: true))
.and_call_original
@@ -167,8 +167,8 @@ RSpec.describe Gitlab::Git::Blob do
end
describe '.raw' do
- let(:raw_blob) { Gitlab::Git::Blob.raw(repository, SeedRepo::RubyBlob::ID) }
- let(:bad_blob) { Gitlab::Git::Blob.raw(repository, SeedRepo::BigCommit::ID) }
+ let(:raw_blob) { described_class.raw(repository, SeedRepo::RubyBlob::ID) }
+ let(:bad_blob) { described_class.raw(repository, SeedRepo::BigCommit::ID) }
it { expect(raw_blob.id).to eq(SeedRepo::RubyBlob::ID) }
it { expect(raw_blob.data[0..10]).to eq("require \'fi") }
@@ -305,7 +305,7 @@ RSpec.describe Gitlab::Git::Blob do
describe '.batch_lfs_pointers' do
let(:non_lfs_blob) do
- Gitlab::Git::Blob.find(
+ described_class.find(
repository,
'master',
'README.md'
@@ -313,7 +313,7 @@ RSpec.describe Gitlab::Git::Blob do
end
let(:lfs_blob) do
- Gitlab::Git::Blob.find(
+ described_class.find(
repository,
TestEnv::BRANCH_SHA['master'],
'files/lfs/lfs_object.iso'
@@ -324,7 +324,7 @@ RSpec.describe Gitlab::Git::Blob do
blobs = described_class.batch_lfs_pointers(repository, [lfs_blob.id])
expect(blobs.count).to eq(1)
- expect(blobs).to all( be_a(Gitlab::Git::Blob) )
+ expect(blobs).to all( be_a(described_class) )
expect(blobs).to be_an(Array)
end
@@ -332,7 +332,7 @@ RSpec.describe Gitlab::Git::Blob do
blobs = described_class.batch_lfs_pointers(repository, [lfs_blob.id].lazy)
expect(blobs.count).to eq(1)
- expect(blobs).to all( be_a(Gitlab::Git::Blob) )
+ expect(blobs).to all( be_a(described_class) )
end
it 'handles empty list of IDs gracefully' do
@@ -361,7 +361,7 @@ RSpec.describe Gitlab::Git::Blob do
describe 'encoding', :aggregate_failures do
context 'file with russian text' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/russian.rb") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/russian.rb") }
it 'has the correct blob attributes' do
expect(blob.name).to eq("russian.rb")
@@ -375,7 +375,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'file with Japanese text' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/テスト.txt") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/テスト.txt") }
it 'has the correct blob attributes' do
expect(blob.name).to eq("テスト.txt")
@@ -387,7 +387,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'file with ISO-8859 text' do
- let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/iso8859.txt") }
+ let(:blob) { described_class.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/iso8859.txt") }
it 'has the correct blob attributes' do
expect(blob.name).to eq("iso8859.txt")
@@ -402,7 +402,7 @@ RSpec.describe Gitlab::Git::Blob do
describe 'mode' do
context 'file regular' do
let(:blob) do
- Gitlab::Git::Blob.find(
+ described_class.find(
repository,
TestEnv::BRANCH_SHA['master'],
'files/ruby/regex.rb'
@@ -417,7 +417,7 @@ RSpec.describe Gitlab::Git::Blob do
context 'file binary' do
let(:blob) do
- Gitlab::Git::Blob.find(
+ described_class.find(
repository,
TestEnv::BRANCH_SHA['with-executables'],
'files/executables/ls'
@@ -432,7 +432,7 @@ RSpec.describe Gitlab::Git::Blob do
context 'file symlink to regular' do
let(:blob) do
- Gitlab::Git::Blob.find(
+ described_class.find(
repository,
'88ce9520c07b7067f589b7f83a30b6250883115c',
'symlink'
@@ -449,7 +449,7 @@ RSpec.describe Gitlab::Git::Blob do
describe 'lfs_pointers' do
context 'file a valid lfs pointer' do
let(:blob) do
- Gitlab::Git::Blob.find(
+ described_class.find(
repository,
TestEnv::BRANCH_SHA['png-lfs'],
'files/images/emoji.png'
@@ -469,7 +469,7 @@ RSpec.describe Gitlab::Git::Blob do
describe '#load_all_data!' do
let(:full_data) { 'abcd' }
- let(:blob) { Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abc') }
+ let(:blob) { described_class.new(name: 'test', size: 4, data: 'abc') }
subject { blob.load_all_data!(repository) }
@@ -483,7 +483,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'with a fully loaded blob' do
- let(:blob) { Gitlab::Git::Blob.new(name: 'test', size: 4, data: full_data) }
+ let(:blob) { described_class.new(name: 'test', size: 4, data: full_data) }
it "doesn't perform any loading" do
expect(repository.gitaly_blob_client).not_to receive(:get_blob)
@@ -497,7 +497,7 @@ RSpec.describe Gitlab::Git::Blob do
describe '#truncated?' do
context 'when blob.size is nil' do
- let(:nil_size_blob) { Gitlab::Git::Blob.new(name: 'test', data: 'abcd') }
+ let(:nil_size_blob) { described_class.new(name: 'test', data: 'abcd') }
it 'returns false' do
expect(nil_size_blob.truncated?).to be_falsey
@@ -505,7 +505,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'when blob.data is missing' do
- let(:nil_data_blob) { Gitlab::Git::Blob.new(name: 'test', size: 4) }
+ let(:nil_data_blob) { described_class.new(name: 'test', size: 4) }
it 'returns false' do
expect(nil_data_blob.truncated?).to be_falsey
@@ -513,7 +513,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'when the blob is truncated' do
- let(:truncated_blob) { Gitlab::Git::Blob.new(name: 'test', size: 40, data: 'abcd') }
+ let(:truncated_blob) { described_class.new(name: 'test', size: 40, data: 'abcd') }
it 'returns true' do
expect(truncated_blob.truncated?).to be_truthy
@@ -521,7 +521,7 @@ RSpec.describe Gitlab::Git::Blob do
end
context 'when the blob is untruncated' do
- let(:untruncated_blob) { Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd') }
+ let(:untruncated_blob) { described_class.new(name: 'test', size: 4, data: 'abcd') }
it 'returns false' do
expect(untruncated_blob.truncated?).to be_falsey
@@ -547,7 +547,7 @@ RSpec.describe Gitlab::Git::Blob do
context 'when the encoding cannot be detected' do
it 'successfully splits the data' do
data = "test\nblob"
- blob = Gitlab::Git::Blob.new(name: 'test', size: data.bytesize, data: data)
+ blob = described_class.new(name: 'test', size: data.bytesize, data: data)
expect(blob).to receive(:ruby_encoding) { nil }
expect(blob.lines).to eq(data.split("\n"))
diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb
index e5f8918f7bb..dd9f77f0211 100644
--- a/spec/lib/gitlab/git/commit_spec.rb
+++ b/spec/lib/gitlab/git/commit_spec.rb
@@ -420,7 +420,7 @@ RSpec.describe Gitlab::Git::Commit, feature_category: :source_code_management do
commits = described_class.batch_by_oid(repository, oids)
expect(commits.count).to eq(2)
- expect(commits).to all( be_a(Gitlab::Git::Commit) )
+ expect(commits).to all( be_a(described_class) )
expect(commits.first.sha).to eq(SeedRepo::Commit::ID)
expect(commits.second.sha).to eq(SeedRepo::FirstCommit::ID)
end
@@ -476,7 +476,7 @@ RSpec.describe Gitlab::Git::Commit, feature_category: :source_code_management do
let(:commit_id) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
it 'returns signature and signed text' do
- signature, signed_text = subject
+ signature, signed_text, signer = subject.values_at(:signature, :signed_text, :signer)
expected_signature = <<~SIGNATURE
-----BEGIN PGP SIGNATURE-----
@@ -509,6 +509,7 @@ RSpec.describe Gitlab::Git::Commit, feature_category: :source_code_management do
expect(signed_text).to eq(expected_signed_text)
expect(signed_text).to be_a_binary_string
+ expect(signer).to eq(:SIGNER_USER)
end
end
diff --git a/spec/lib/gitlab/git/compare_spec.rb b/spec/lib/gitlab/git/compare_spec.rb
index e8c683cf8aa..81b5aa94656 100644
--- a/spec/lib/gitlab/git/compare_spec.rb
+++ b/spec/lib/gitlab/git/compare_spec.rb
@@ -5,8 +5,8 @@ require "spec_helper"
RSpec.describe Gitlab::Git::Compare do
let_it_be(:repository) { create(:project, :repository).repository.raw }
- let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, straight: false) }
- let(:compare_straight) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, straight: true) }
+ let(:compare) { described_class.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, straight: false) }
+ let(:compare_straight) { described_class.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, straight: true) }
describe '#commits' do
subject do
@@ -21,25 +21,25 @@ RSpec.describe Gitlab::Git::Compare do
it { is_expected.not_to include(SeedRepo::BigCommit::PARENT_ID) }
context 'non-existing base ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
+ let(:compare) { described_class.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
it { is_expected.to be_empty }
end
context 'non-existing head ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
+ let(:compare) { described_class.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
it { is_expected.to be_empty }
end
context 'base ref is equal to head ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
+ let(:compare) { described_class.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
it { is_expected.to be_empty }
end
context 'providing nil as base ref or head ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, nil, nil) }
+ let(:compare) { described_class.new(repository, nil, nil) }
it { is_expected.to be_empty }
end
@@ -58,13 +58,13 @@ RSpec.describe Gitlab::Git::Compare do
it { is_expected.not_to include('LICENSE') }
context 'non-existing base ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
+ let(:compare) { described_class.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
it { is_expected.to be_empty }
end
context 'non-existing head ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
+ let(:compare) { described_class.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
it { is_expected.to be_empty }
end
@@ -78,7 +78,7 @@ RSpec.describe Gitlab::Git::Compare do
it { is_expected.to eq(false) }
context 'base ref is equal to head ref' do
- let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
+ let(:compare) { described_class.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
it { is_expected.to eq(true) }
end
diff --git a/spec/lib/gitlab/git/diff_collection_spec.rb b/spec/lib/gitlab/git/diff_collection_spec.rb
index 5fa0447091c..72ddd0759ec 100644
--- a/spec/lib/gitlab/git/diff_collection_spec.rb
+++ b/spec/lib/gitlab/git/diff_collection_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
end
subject do
- Gitlab::Git::DiffCollection.new(
+ described_class.new(
iterator,
max_files: max_files,
max_lines: max_lines,
@@ -495,7 +495,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
end
describe 'empty collection' do
- subject { Gitlab::Git::DiffCollection.new([]) }
+ subject { described_class.new([]) }
it_behaves_like 'overflow stuff'
@@ -533,7 +533,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
describe '#each' do
context 'when diff are too large' do
let(:collection) do
- Gitlab::Git::DiffCollection.new([{ diff: 'a' * 204800 }])
+ described_class.new([{ diff: 'a' * 204800 }])
end
it 'yields Diff instances even when they are too large' do
@@ -612,7 +612,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
let(:iterator) { [fake_diff(1, 1)] * 4 }
before do
- allow(Gitlab::Git::DiffCollection)
+ allow(described_class)
.to receive(:default_limits)
.and_return({ max_files: 2, max_lines: max_lines })
end
@@ -641,7 +641,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
end
before do
- allow(Gitlab::Git::DiffCollection)
+ allow(described_class)
.to receive(:default_limits)
.and_return({ max_files: max_files, max_lines: 80 })
end
@@ -672,7 +672,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
before do
allow(Gitlab::CurrentSettings).to receive(:diff_max_patch_bytes).and_return(1.megabyte)
- allow(Gitlab::Git::DiffCollection)
+ allow(described_class)
.to receive(:default_limits)
.and_return({ max_files: 4, max_lines: 3000 })
end
@@ -713,7 +713,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
context 'when offset_index is given' do
subject do
- Gitlab::Git::DiffCollection.new(
+ described_class.new(
iterator,
max_files: max_files,
max_lines: max_lines,
@@ -760,7 +760,7 @@ RSpec.describe Gitlab::Git::DiffCollection do
end
before do
- allow(Gitlab::Git::DiffCollection)
+ allow(described_class)
.to receive(:default_limits)
.and_return({ max_files: max_files, max_lines: 80 })
end
diff --git a/spec/lib/gitlab/git/finders/refs_finder_spec.rb b/spec/lib/gitlab/git/finders/refs_finder_spec.rb
new file mode 100644
index 00000000000..63d794d1e59
--- /dev/null
+++ b/spec/lib/gitlab/git/finders/refs_finder_spec.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Gitlab::Git::Finders::RefsFinder, feature_category: :source_code_management do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository) }
+
+ let(:repository) { project.repository }
+ let(:finder) { described_class.new(repository, **params) }
+ let(:params) { {} }
+
+ describe "#execute" do
+ subject { finder.execute }
+
+ context "when :ref_type is :branches" do
+ let(:params) do
+ { search: "mast", ref_type: :branches }
+ end
+
+ it { is_expected.to be_an(Array) }
+
+ it "returns matching ref object" do
+ expect(subject.length).to eq(1)
+
+ ref = subject.first
+
+ expect(ref).to be_a(Gitaly::ListRefsResponse::Reference)
+ expect(ref.name).to eq("refs/heads/master")
+ expect(ref.target).to be_a(String)
+ end
+ end
+
+ context "when :ref_type is :tags" do
+ let(:params) do
+ { search: "v1.0.", ref_type: :tags }
+ end
+
+ it { is_expected.to be_an(Array) }
+
+ it "returns matching ref object" do
+ expect(subject.length).to eq(1)
+
+ ref = subject.first
+
+ expect(ref).to be_a(Gitaly::ListRefsResponse::Reference)
+ expect(ref.name).to eq("refs/tags/v1.0.0")
+ expect(ref.target).to be_a(String)
+ end
+ end
+
+ context "when :ref_type is invalid" do
+ let(:params) do
+ { search: "master", ref_type: nil }
+ end
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::UnknownRefTypeError)
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/git/keep_around_spec.rb b/spec/lib/gitlab/git/keep_around_spec.rb
index d6359d55646..65bed3f2ae6 100644
--- a/spec/lib/gitlab/git/keep_around_spec.rb
+++ b/spec/lib/gitlab/git/keep_around_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Gitlab::Git::KeepAround do
let(:repository) { create(:project, :repository).repository }
let(:service) { described_class.new(repository) }
+ let(:keep_around_ref_name) { "refs/#{::Repository::REF_KEEP_AROUND}/#{sample_commit.id}" }
it "does not fail if we attempt to reference bad commit" do
expect(service.kept_around?('abc1234')).to be_falsey
@@ -16,6 +17,7 @@ RSpec.describe Gitlab::Git::KeepAround do
service.execute([sample_commit.id])
expect(service.kept_around?(sample_commit.id)).to be_truthy
+ expect(repository.list_refs([keep_around_ref_name])).not_to be_empty
end
it "does not fail if writting the ref fails" do
@@ -45,4 +47,17 @@ RSpec.describe Gitlab::Git::KeepAround do
expect(service.kept_around?(another_sample_commit.id)).to be_truthy
end
end
+
+ context 'when disable_keep_around_refs feature flag is enabled' do
+ before do
+ stub_feature_flags(disable_keep_around_refs: true)
+ end
+
+ it 'does not create keep-around refs' do
+ service.execute([sample_commit.id])
+
+ expect(service.kept_around?(sample_commit.id)).to be_truthy
+ expect(repository.list_refs([keep_around_ref_name])).to be_empty
+ end
+ end
end
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index b137157f2d5..9ce8a674146 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -285,6 +285,28 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen
subject { repository.size }
it { is_expected.to be > 0 }
+ it { is_expected.to be_a(Float) }
+
+ it "uses repository_info for size" do
+ expect(repository.gitaly_repository_client).to receive(:repository_info).and_call_original
+
+ subject
+ end
+
+ context "when use_repository_info_for_repository_size feature flag is disabled" do
+ before do
+ stub_feature_flags(use_repository_info_for_repository_size: false)
+ end
+
+ it { is_expected.to be > 0 }
+ it { is_expected.to be_a(Float) }
+
+ it "uses repository_size for size" do
+ expect(repository.gitaly_repository_client).to receive(:repository_size).and_call_original
+
+ subject
+ end
+ end
end
describe '#to_s' do
@@ -1151,7 +1173,31 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen
commit_result.newrev
end
- subject { repository.new_blobs(newrevs).to_a }
+ subject { repository.new_blobs(newrevs) }
+
+ describe 'memoization' do
+ before do
+ allow(repository).to receive(:blobs).once.with(["--not", "--all", "--not", "revision1"], kind_of(Hash))
+ .and_return(['first result'])
+ repository.new_blobs(['revision1'])
+ end
+
+ it 'calls blobs only once' do
+ expect(repository.new_blobs(['revision1'])).to eq(['first result'])
+ end
+
+ context 'when called with a different revision' do
+ before do
+ allow(repository).to receive(:blobs).once.with(["--not", "--all", "--not", "revision2"], kind_of(Hash))
+ .and_return(['second result'])
+ repository.new_blobs(['revision2'])
+ end
+
+ it 'memoizes the different arguments' do
+ expect(repository.new_blobs(['revision2'])).to eq(['second result'])
+ end
+ end
+ end
shared_examples '#new_blobs with revisions' do
before do
@@ -1173,7 +1219,9 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen
it 'memoizes results' do
expect(subject).to match_array(expected_blobs)
- expect(subject).to match_array(expected_blobs)
+
+ # call subject again
+ expect(repository.new_blobs(newrevs)).to match_array(expected_blobs)
end
end
@@ -2146,10 +2194,10 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen
expect(repository.refs_by_oid(oid: Gitlab::Git::BLANK_SHA, limit: 0)).to eq([])
end
- it 'returns nil for an empty repo' do
+ it 'returns empty for an empty repo' do
project = create(:project)
- expect(project.repository.refs_by_oid(oid: TestEnv::BRANCH_SHA['master'], limit: 0)).to be_nil
+ expect(project.repository.refs_by_oid(oid: TestEnv::BRANCH_SHA['master'], limit: 0)).to eq([])
end
end
diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb
index 2a68fa66b18..4a20e0b1156 100644
--- a/spec/lib/gitlab/git/tree_spec.rb
+++ b/spec/lib/gitlab/git/tree_spec.rb
@@ -160,6 +160,15 @@ RSpec.describe Gitlab::Git::Tree do
expect(cursor.next_cursor).to be_present
end
end
+
+ context 'and invalid reference is used' do
+ it 'returns no entries and nil cursor' do
+ allow(repository.gitaly_commit_client).to receive(:tree_entries).and_raise(Gitlab::Git::Index::IndexError)
+
+ expect(entries.count).to eq(0)
+ expect(cursor).to be_nil
+ end
+ end
end
end