summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-19 23:18:09 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-19 23:18:09 +0000
commit6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch)
treedc4d20fe6064752c0bd323187252c77e0a89144b /spec/lib/gitlab/git
parent9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff)
downloadgitlab-ce-6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde.tar.gz
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/lib/gitlab/git')
-rw-r--r--spec/lib/gitlab/git/blob_spec.rb209
-rw-r--r--spec/lib/gitlab/git/branch_spec.rb2
-rw-r--r--spec/lib/gitlab/git/changed_path_spec.rb2
-rw-r--r--spec/lib/gitlab/git/changes_spec.rb2
-rw-r--r--spec/lib/gitlab/git/commit_spec.rb70
-rw-r--r--spec/lib/gitlab/git/commit_stats_spec.rb16
-rw-r--r--spec/lib/gitlab/git/compare_spec.rb5
-rw-r--r--spec/lib/gitlab/git/conflict/file_spec.rb2
-rw-r--r--spec/lib/gitlab/git/conflict/parser_spec.rb2
-rw-r--r--spec/lib/gitlab/git/cross_repo_comparer_spec.rb2
-rw-r--r--spec/lib/gitlab/git/diff_collection_spec.rb2
-rw-r--r--spec/lib/gitlab/git/diff_spec.rb18
-rw-r--r--spec/lib/gitlab/git/gitmodules_parser_spec.rb2
-rw-r--r--spec/lib/gitlab/git/lfs_pointer_file_spec.rb2
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb613
-rw-r--r--spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb2
-rw-r--r--spec/lib/gitlab/git/tree_spec.rb2
-rw-r--r--spec/lib/gitlab/git/util_spec.rb2
-rw-r--r--spec/lib/gitlab/git/wiki_spec.rb63
19 files changed, 362 insertions, 656 deletions
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb
index 0da7aa7dad0..d35d288050a 100644
--- a/spec/lib/gitlab/git/blob_spec.rb
+++ b/spec/lib/gitlab/git/blob_spec.rb
@@ -2,11 +2,9 @@
require "spec_helper"
-RSpec.describe Gitlab::Git::Blob, :seed_helper do
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
- let(:rugged) do
- Rugged::Repository.new(File.join(TestEnv.repos_path, TEST_REPO_PATH))
- end
+RSpec.describe Gitlab::Git::Blob do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:repository) { project.repository.raw }
describe 'initialize' do
let(:blob) { Gitlab::Git::Blob.new(name: 'test') }
@@ -44,7 +42,7 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
shared_examples '.find' do
context 'nil path' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, nil) }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], nil) }
it { expect(blob).to eq(nil) }
end
@@ -56,30 +54,30 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
end
context 'blank path' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, '') }
+ let(:blob) { Gitlab::Git::Blob.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, SeedRepo::Commit::ID, "files/ruby/popen.rb") }
+ let(:blob) { Gitlab::Git::Blob.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) }
it { expect(blob.path).to eq("files/ruby/popen.rb") }
- it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) }
+ it { expect(blob.commit_id).to eq(TestEnv::BRANCH_SHA['master']) }
it { expect(blob.data[0..10]).to eq(SeedRepo::RubyBlob::CONTENT[0..10]) }
it { expect(blob.size).to eq(669) }
it { expect(blob.mode).to eq("100644") }
end
context 'file in root' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, ".gitignore") }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], ".gitignore") }
it { expect(blob.id).to eq("dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82") }
it { expect(blob.name).to eq(".gitignore") }
it { expect(blob.path).to eq(".gitignore") }
- it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) }
+ it { expect(blob.commit_id).to eq(TestEnv::BRANCH_SHA['master']) }
it { expect(blob.data[0..10]).to eq("*.rbc\n*.sas") }
it { expect(blob.size).to eq(241) }
it { expect(blob.mode).to eq("100644") }
@@ -87,25 +85,25 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
end
context 'file in root with leading slash' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "/.gitignore") }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "/.gitignore") }
it { expect(blob.id).to eq("dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82") }
it { expect(blob.name).to eq(".gitignore") }
it { expect(blob.path).to eq(".gitignore") }
- it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) }
+ it { expect(blob.commit_id).to eq(TestEnv::BRANCH_SHA['master']) }
it { expect(blob.data[0..10]).to eq("*.rbc\n*.sas") }
it { expect(blob.size).to eq(241) }
it { expect(blob.mode).to eq("100644") }
end
context 'non-exist file' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "missing.rb") }
+ let(:blob) { Gitlab::Git::Blob.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, SeedRepo::Commit::ID, 'six') }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], 'six') }
it { expect(blob.id).to eq('409f37c4f05865e4fb208c771485f211a22c4c2d') }
it { expect(blob.data).to eq('') }
@@ -121,7 +119,7 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
end
context 'large file' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, 'files/images/6049019_460s.jpg') }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], 'files/images/6049019_460s.jpg') }
let(:blob_size) { 111803 }
let(:stub_limit) { 1000 }
@@ -159,10 +157,10 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
describe '.find with Rugged enabled', :enable_rugged do
it 'calls out to the Rugged implementation' do
allow_next_instance_of(Rugged) do |instance|
- allow(instance).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original
+ allow(instance).to receive(:rev_parse).with(TestEnv::BRANCH_SHA['master']).and_call_original
end
- described_class.find(repository, SeedRepo::Commit::ID, 'files/images/6049019_460s.jpg')
+ described_class.find(repository, TestEnv::BRANCH_SHA['master'], 'files/images/6049019_460s.jpg')
end
it_behaves_like '.find'
@@ -177,40 +175,13 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
it { expect(raw_blob.size).to eq(669) }
it { expect(raw_blob.truncated?).to be_falsey }
it { expect(bad_blob).to be_nil }
-
- context 'large file' do
- it 'limits the size of a large file' do
- blob_size = Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE + 1
- buffer = Array.new(blob_size, 0)
- rugged_blob = Rugged::Blob.from_buffer(rugged, buffer.join(''))
- blob = Gitlab::Git::Blob.raw(repository, rugged_blob)
-
- expect(blob.size).to eq(blob_size)
- expect(blob.loaded_size).to eq(Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE)
- expect(blob.data.length).to eq(Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE)
- expect(blob.truncated?).to be_truthy
-
- blob.load_all_data!(repository)
- expect(blob.loaded_size).to eq(blob_size)
- end
- end
-
- context 'when sha references a tree' do
- it 'returns nil' do
- tree = rugged.rev_parse('master^{tree}')
-
- blob = Gitlab::Git::Blob.raw(repository, tree.oid)
-
- expect(blob).to be_nil
- end
- end
end
describe '.batch' do
let(:blob_references) do
[
- [SeedRepo::Commit::ID, "files/ruby/popen.rb"],
- [SeedRepo::Commit::ID, 'six']
+ [TestEnv::BRANCH_SHA['master'], "files/ruby/popen.rb"],
+ [TestEnv::BRANCH_SHA['master'], 'six']
]
end
@@ -224,7 +195,7 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) }
it { expect(blob.name).to eq(SeedRepo::RubyBlob::NAME) }
it { expect(blob.path).to eq("files/ruby/popen.rb") }
- it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) }
+ it { expect(blob.commit_id).to eq(TestEnv::BRANCH_SHA['master']) }
it { expect(blob.data[0..10]).to eq(SeedRepo::RubyBlob::CONTENT[0..10]) }
it { expect(blob.size).to eq(669) }
it { expect(blob.mode).to eq("100644") }
@@ -273,21 +244,21 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
context 'when large number of blobs requested' do
let(:first_batch) do
[
- [SeedRepo::Commit::ID, 'files/ruby/popen.rb'],
- [SeedRepo::Commit::ID, 'six']
+ [TestEnv::BRANCH_SHA['master'], 'files/ruby/popen.rb'],
+ [TestEnv::BRANCH_SHA['master'], 'six']
]
end
let(:second_batch) do
[
- [SeedRepo::Commit::ID, 'some'],
- [SeedRepo::Commit::ID, 'other']
+ [TestEnv::BRANCH_SHA['master'], 'some'],
+ [TestEnv::BRANCH_SHA['master'], 'other']
]
end
let(:third_batch) do
[
- [SeedRepo::Commit::ID, 'files']
+ [TestEnv::BRANCH_SHA['master'], 'files']
]
end
@@ -315,8 +286,8 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
describe '.batch_metadata' do
let(:blob_references) do
[
- [SeedRepo::Commit::ID, "files/ruby/popen.rb"],
- [SeedRepo::Commit::ID, 'six']
+ [TestEnv::BRANCH_SHA['master'], "files/ruby/popen.rb"],
+ [TestEnv::BRANCH_SHA['master'], 'six']
]
end
@@ -333,8 +304,6 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
end
describe '.batch_lfs_pointers' do
- let(:tree_object) { rugged.rev_parse('master^{tree}') }
-
let(:non_lfs_blob) do
Gitlab::Git::Blob.find(
repository,
@@ -346,8 +315,8 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
let(:lfs_blob) do
Gitlab::Git::Blob.find(
repository,
- '33bcff41c232a11727ac6d660bd4b0c2ba86d63d',
- 'files/lfs/image.jpg'
+ TestEnv::BRANCH_SHA['master'],
+ 'files/lfs/lfs_object.iso'
)
end
@@ -374,12 +343,6 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
expect(blobs_2).to eq([])
end
- it 'silently ignores tree objects' do
- blobs = described_class.batch_lfs_pointers(repository, [tree_object.oid])
-
- expect(blobs).to eq([])
- end
-
it 'silently ignores non lfs objects' do
blobs = described_class.batch_lfs_pointers(repository, [non_lfs_blob.id])
@@ -398,7 +361,7 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
describe 'encoding', :aggregate_failures do
context 'file with russian text' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "encoding/russian.rb") }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/russian.rb") }
it 'has the correct blob attributes' do
expect(blob.name).to eq("russian.rb")
@@ -412,7 +375,7 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
end
context 'file with Japanese text' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "encoding/テスト.txt") }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/テスト.txt") }
it 'has the correct blob attributes' do
expect(blob.name).to eq("テスト.txt")
@@ -424,12 +387,12 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
end
context 'file with ISO-8859 text' do
- let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::LastCommit::ID, "encoding/iso8859.txt") }
+ let(:blob) { Gitlab::Git::Blob.find(repository, TestEnv::BRANCH_SHA['master'], "encoding/iso8859.txt") }
it 'has the correct blob attributes' do
expect(blob.name).to eq("iso8859.txt")
- expect(blob.loaded_size).to eq(4)
- expect(blob.size).to eq(4)
+ expect(blob.loaded_size).to eq(3)
+ expect(blob.size).to eq(3)
expect(blob.mode).to eq("100644")
expect(blob.truncated?).to be_falsey
end
@@ -441,7 +404,7 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
let(:blob) do
Gitlab::Git::Blob.find(
repository,
- 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6',
+ TestEnv::BRANCH_SHA['master'],
'files/ruby/regex.rb'
)
end
@@ -456,14 +419,14 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
let(:blob) do
Gitlab::Git::Blob.find(
repository,
- 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6',
+ TestEnv::BRANCH_SHA['with-executables'],
'files/executables/ls'
)
end
it { expect(blob.name).to eq('ls') }
it { expect(blob.path).to eq('files/executables/ls') }
- it { expect(blob.size).to eq(110080) }
+ it { expect(blob.size).to eq(23) }
it { expect(blob.mode).to eq("100755") }
end
@@ -471,29 +434,14 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
let(:blob) do
Gitlab::Git::Blob.find(
repository,
- 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6',
- 'files/links/ruby-style-guide.md'
+ '88ce9520c07b7067f589b7f83a30b6250883115c',
+ 'symlink'
)
end
- it { expect(blob.name).to eq('ruby-style-guide.md') }
- it { expect(blob.path).to eq('files/links/ruby-style-guide.md') }
- it { expect(blob.size).to eq(31) }
- it { expect(blob.mode).to eq("120000") }
- end
-
- context 'file symlink to binary' do
- let(:blob) do
- Gitlab::Git::Blob.find(
- repository,
- 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6',
- 'files/links/touch'
- )
- end
-
- it { expect(blob.name).to eq('touch') }
- it { expect(blob.path).to eq('files/links/touch') }
- it { expect(blob.size).to eq(20) }
+ it { expect(blob.name).to eq('symlink') }
+ it { expect(blob.path).to eq('symlink') }
+ it { expect(blob.size).to eq(6) }
it { expect(blob.mode).to eq("120000") }
end
end
@@ -503,79 +451,20 @@ RSpec.describe Gitlab::Git::Blob, :seed_helper do
let(:blob) do
Gitlab::Git::Blob.find(
repository,
- '33bcff41c232a11727ac6d660bd4b0c2ba86d63d',
- 'files/lfs/image.jpg'
+ TestEnv::BRANCH_SHA['png-lfs'],
+ 'files/images/emoji.png'
)
end
it { expect(blob.lfs_pointer?).to eq(true) }
- it { expect(blob.lfs_oid).to eq("4206f951d2691c78aac4c0ce9f2b23580b2c92cdcc4336e1028742c0274938e0") }
- it { expect(blob.lfs_size).to eq(19548) }
- it { expect(blob.id).to eq("f4d76af13003d1106be7ac8c5a2a3d37ddf32c2a") }
- it { expect(blob.name).to eq("image.jpg") }
- it { expect(blob.path).to eq("files/lfs/image.jpg") }
- it { expect(blob.size).to eq(130) }
+ it { expect(blob.lfs_oid).to eq("96f74c6fe7a2979eefb9ec74a5dfc6888fb25543cf99b77586b79afea1da6f97") }
+ it { expect(blob.lfs_size).to eq(1219696) }
+ it { expect(blob.id).to eq("ff0ab3afd1616ff78d0331865d922df103b64cf0") }
+ it { expect(blob.name).to eq("emoji.png") }
+ it { expect(blob.path).to eq("files/images/emoji.png") }
+ it { expect(blob.size).to eq(132) }
it { expect(blob.mode).to eq("100644") }
end
-
- describe 'file an invalid lfs pointer' do
- context 'with correct version header but incorrect size and oid' do
- let(:blob) do
- Gitlab::Git::Blob.find(
- repository,
- '33bcff41c232a11727ac6d660bd4b0c2ba86d63d',
- 'files/lfs/archive-invalid.tar'
- )
- end
-
- it { expect(blob.lfs_pointer?).to eq(false) }
- it { expect(blob.lfs_oid).to eq(nil) }
- it { expect(blob.lfs_size).to eq(nil) }
- it { expect(blob.id).to eq("f8a898db217a5a85ed8b3d25b34c1df1d1094c46") }
- it { expect(blob.name).to eq("archive-invalid.tar") }
- it { expect(blob.path).to eq("files/lfs/archive-invalid.tar") }
- it { expect(blob.size).to eq(43) }
- it { expect(blob.mode).to eq("100644") }
- end
-
- context 'with correct version header and size but incorrect size and oid' do
- let(:blob) do
- Gitlab::Git::Blob.find(
- repository,
- '33bcff41c232a11727ac6d660bd4b0c2ba86d63d',
- 'files/lfs/picture-invalid.png'
- )
- end
-
- it { expect(blob.lfs_pointer?).to eq(false) }
- it { expect(blob.lfs_oid).to eq(nil) }
- it { expect(blob.lfs_size).to eq(1575078) }
- it { expect(blob.id).to eq("5ae35296e1f95c1ef9feda1241477ed29a448572") }
- it { expect(blob.name).to eq("picture-invalid.png") }
- it { expect(blob.path).to eq("files/lfs/picture-invalid.png") }
- it { expect(blob.size).to eq(57) }
- it { expect(blob.mode).to eq("100644") }
- end
-
- context 'with correct version header and size but invalid size and oid' do
- let(:blob) do
- Gitlab::Git::Blob.find(
- repository,
- '33bcff41c232a11727ac6d660bd4b0c2ba86d63d',
- 'files/lfs/file-invalid.zip'
- )
- end
-
- it { expect(blob.lfs_pointer?).to eq(false) }
- it { expect(blob.lfs_oid).to eq(nil) }
- it { expect(blob.lfs_size).to eq(nil) }
- it { expect(blob.id).to eq("d831981bd876732b85a1bcc6cc01210c9f36248f") }
- it { expect(blob.name).to eq("file-invalid.zip") }
- it { expect(blob.path).to eq("files/lfs/file-invalid.zip") }
- it { expect(blob.size).to eq(60) }
- it { expect(blob.mode).to eq("100644") }
- end
- end
end
describe '#load_all_data!' do
diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb
index feaa1f6595c..95cc833390f 100644
--- a/spec/lib/gitlab/git/branch_spec.rb
+++ b/spec/lib/gitlab/git/branch_spec.rb
@@ -111,7 +111,7 @@ RSpec.describe Gitlab::Git::Branch do
end
def create_commit
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: 'HEAD',
message: 'commit message',
diff --git a/spec/lib/gitlab/git/changed_path_spec.rb b/spec/lib/gitlab/git/changed_path_spec.rb
index 93db107ad5c..ef51021ba4c 100644
--- a/spec/lib/gitlab/git/changed_path_spec.rb
+++ b/spec/lib/gitlab/git/changed_path_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require "spec_helper"
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::ChangedPath do
subject(:changed_path) { described_class.new(path: path, status: status) }
diff --git a/spec/lib/gitlab/git/changes_spec.rb b/spec/lib/gitlab/git/changes_spec.rb
index 310be7a3731..7cded9740ee 100644
--- a/spec/lib/gitlab/git/changes_spec.rb
+++ b/spec/lib/gitlab/git/changes_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::Changes do
let(:changes) { described_class.new }
diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb
index 95b49186d0f..d873151421d 100644
--- a/spec/lib/gitlab/git/commit_spec.rb
+++ b/spec/lib/gitlab/git/commit_spec.rb
@@ -2,8 +2,8 @@
require "spec_helper"
-RSpec.describe Gitlab::Git::Commit, :seed_helper do
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
+RSpec.describe Gitlab::Git::Commit do
+ let(:repository) { create(:project, :repository).repository.raw }
let(:commit) { described_class.find(repository, SeedRepo::Commit::ID) }
describe "Commit info from gitaly commit" do
@@ -121,14 +121,6 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
it "returns nil for id containing NULL" do
expect(described_class.find(repository, "HE\x00AD")).to be_nil
end
-
- context 'with broken repo' do
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_BROKEN_REPO_PATH, '', 'group/project') }
-
- it 'returns nil' do
- expect(described_class.find(repository, SeedRepo::Commit::ID)).to be_nil
- end
- end
end
describe '.find with Gitaly enabled' do
@@ -154,7 +146,7 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
describe '#id' do
subject { super().id }
- it { is_expected.to eq(SeedRepo::LastCommit::ID) }
+ it { is_expected.to eq(TestEnv::BRANCH_SHA['master']) }
end
end
@@ -223,7 +215,7 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
expect(subject.size).to eq(10)
end
- it { is_expected.to include(SeedRepo::EmptyCommit::ID) }
+ it { is_expected.to include(TestEnv::BRANCH_SHA['master']) }
end
context 'path is nil' do
@@ -242,28 +234,7 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
expect(subject.size).to eq(10)
end
- it { is_expected.to include(SeedRepo::EmptyCommit::ID) }
- end
-
- context 'ref is branch name' do
- subject do
- commits = described_class.where(
- repo: repository,
- ref: 'master',
- path: 'files',
- limit: 3,
- offset: 1
- )
-
- commits.map { |c| c.id }
- end
-
- it 'has 3 elements' do
- expect(subject.size).to eq(3)
- end
-
- it { is_expected.to include("d14d6c0abdd253381df51a723d58691b2ee1ab08") }
- it { is_expected.not_to include("eb49186cfa5c4338011f5f590fac11bd66c5c631") }
+ it { is_expected.to include(TestEnv::BRANCH_SHA['master']) }
end
context 'ref is commit id' do
@@ -323,13 +294,12 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
context 'requesting a commit range' do
let(:from) { 'v1.0.0' }
- let(:to) { 'v1.2.0' }
+ let(:to) { 'v1.1.0' }
let(:commits_in_range) do
%w[
570e7b2abdd848b95f2f578043fc23bd6f6fd24d
5937ac0a7beb003549fc5fd26fc247adbce4a52e
- eb49186cfa5c4338011f5f590fac11bd66c5c631
]
end
@@ -338,9 +308,9 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
end
context 'limited' do
- let(:limit) { 2 }
+ let(:limit) { 1 }
- it { expect(commit_ids).to eq(commits_in_range.last(2)) }
+ it { expect(commit_ids).to eq(commits_in_range.last(1)) }
end
end
end
@@ -383,16 +353,8 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
commits.map(&:id)
end
- it 'has 34 elements' do
- expect(subject.size).to eq(34)
- end
-
- it 'includes the expected commits' do
- expect(subject).to include(
- SeedRepo::Commit::ID,
- SeedRepo::Commit::PARENT_ID,
- SeedRepo::FirstCommit::ID
- )
+ it 'has maximum elements' do
+ expect(subject.size).to eq(50)
end
end
@@ -408,13 +370,13 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
commits.map(&:id)
end
- it 'has 24 elements' do
- expect(subject.size).to eq(24)
+ it 'has 36 elements' do
+ expect(subject.size).to eq(36)
end
it 'includes the expected commits' do
expect(subject).to include(SeedRepo::Commit::ID, SeedRepo::FirstCommit::ID)
- expect(subject).not_to include(SeedRepo::LastCommit::ID)
+ expect(subject).not_to include(TestEnv::BRANCH_SHA['master'])
end
end
end
@@ -650,8 +612,8 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
subject { commit.ref_names(repository) }
- it 'has 2 element' do
- expect(subject.size).to eq(2)
+ it 'has 3 elements' do
+ expect(subject.size).to eq(3)
end
it { is_expected.to include("master") }
@@ -681,6 +643,8 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
end
it 'gets messages in one batch', :request_store do
+ repository # preload repository so that the project factory does not pollute request counts
+
expect { subject.map(&:itself) }.to change { Gitlab::GitalyClient.get_request_count }.by(1)
end
end
diff --git a/spec/lib/gitlab/git/commit_stats_spec.rb b/spec/lib/gitlab/git/commit_stats_spec.rb
index 29d3909efec..81d9dda4b8f 100644
--- a/spec/lib/gitlab/git/commit_stats_spec.rb
+++ b/spec/lib/gitlab/git/commit_stats_spec.rb
@@ -2,17 +2,19 @@
require "spec_helper"
-RSpec.describe Gitlab::Git::CommitStats, :seed_helper do
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
- let(:commit) { Gitlab::Git::Commit.find(repository, SeedRepo::Commit::ID) }
+RSpec.describe Gitlab::Git::CommitStats do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:repository) { project.repository.raw }
+
+ let(:commit) { Gitlab::Git::Commit.find(repository, TestEnv::BRANCH_SHA['feature']) }
def verify_stats!
stats = described_class.new(repository, commit)
expect(stats).to have_attributes(
- additions: eq(11),
- deletions: eq(6),
- total: eq(17)
+ additions: eq(5),
+ deletions: eq(0),
+ total: eq(5)
)
end
@@ -21,7 +23,7 @@ RSpec.describe Gitlab::Git::CommitStats, :seed_helper do
verify_stats!
- expect(Rails.cache.fetch("commit_stats:group/project:#{commit.id}")).to eq([11, 6])
+ expect(Rails.cache.fetch("commit_stats:#{repository.gl_project_path}:#{commit.id}")).to eq([5, 0])
expect(repository.gitaly_commit_client).not_to receive(:commit_stats)
diff --git a/spec/lib/gitlab/git/compare_spec.rb b/spec/lib/gitlab/git/compare_spec.rb
index 51043355ede..e8c683cf8aa 100644
--- a/spec/lib/gitlab/git/compare_spec.rb
+++ b/spec/lib/gitlab/git/compare_spec.rb
@@ -2,8 +2,9 @@
require "spec_helper"
-RSpec.describe Gitlab::Git::Compare, :seed_helper do
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
+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) }
diff --git a/spec/lib/gitlab/git/conflict/file_spec.rb b/spec/lib/gitlab/git/conflict/file_spec.rb
index 6eb7a7e394e..fb1bec0a554 100644
--- a/spec/lib/gitlab/git/conflict/file_spec.rb
+++ b/spec/lib/gitlab/git/conflict/file_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::Conflict::File do
let(:conflict) { { ancestor: { path: 'ancestor' }, theirs: { path: 'foo', mode: 33188 }, ours: { path: 'foo', mode: 33188 } } }
diff --git a/spec/lib/gitlab/git/conflict/parser_spec.rb b/spec/lib/gitlab/git/conflict/parser_spec.rb
index 7d81af92412..67f288e0299 100644
--- a/spec/lib/gitlab/git/conflict/parser_spec.rb
+++ b/spec/lib/gitlab/git/conflict/parser_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::Conflict::Parser do
describe '.parse' do
diff --git a/spec/lib/gitlab/git/cross_repo_comparer_spec.rb b/spec/lib/gitlab/git/cross_repo_comparer_spec.rb
index 1c49486b7b1..7888e224d59 100644
--- a/spec/lib/gitlab/git/cross_repo_comparer_spec.rb
+++ b/spec/lib/gitlab/git/cross_repo_comparer_spec.rb
@@ -110,7 +110,7 @@ RSpec.describe Gitlab::Git::CrossRepoComparer do
def create_commit(user, repo, branch)
action = { action: :create, file_path: '/FILE', content: 'content' }
- result = repo.multi_action(user, branch_name: branch, message: 'Commit', actions: [action])
+ result = repo.commit_files(user, branch_name: branch, message: 'Commit', actions: [action])
result.newrev
end
diff --git a/spec/lib/gitlab/git/diff_collection_spec.rb b/spec/lib/gitlab/git/diff_collection_spec.rb
index 0e3e92e03cf..7fa5bd8a92b 100644
--- a/spec/lib/gitlab/git/diff_collection_spec.rb
+++ b/spec/lib/gitlab/git/diff_collection_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
+RSpec.describe Gitlab::Git::DiffCollection do
before do
stub_const('MutatingConstantIterator', Class.new)
diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb
index 2c931a999f1..6745c700b92 100644
--- a/spec/lib/gitlab/git/diff_spec.rb
+++ b/spec/lib/gitlab/git/diff_spec.rb
@@ -2,8 +2,10 @@
require "spec_helper"
-RSpec.describe Gitlab::Git::Diff, :seed_helper do
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
+RSpec.describe Gitlab::Git::Diff do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:repository) { project.repository }
+
let(:gitaly_diff) do
Gitlab::GitalyClient::Diff.new(
from_path: '.gitmodules',
@@ -190,16 +192,6 @@ EOT
expect(binary_diff(project).diff).not_to be_empty
end
end
-
- context 'when convert_diff_to_utf8_with_replacement_symbol feature flag is disabled' do
- before do
- stub_feature_flags(convert_diff_to_utf8_with_replacement_symbol: false)
- end
-
- it 'will not try to convert invalid characters' do
- expect(Gitlab::EncodingHelper).not_to receive(:encode_utf8_with_replacement_character?)
- end
- end
end
context 'when replace_invalid_utf8_chars is false' do
@@ -218,7 +210,7 @@ EOT
let(:diffs) { described_class.between(repository, 'feature', 'master', options) }
it 'has the correct size' do
- expect(diffs.size).to eq(24)
+ expect(diffs.size).to eq(21)
end
context 'diff' do
diff --git a/spec/lib/gitlab/git/gitmodules_parser_spec.rb b/spec/lib/gitlab/git/gitmodules_parser_spec.rb
index 0e386c7f3d1..33268b4edcb 100644
--- a/spec/lib/gitlab/git/gitmodules_parser_spec.rb
+++ b/spec/lib/gitlab/git/gitmodules_parser_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::GitmodulesParser do
it 'parses a .gitmodules file correctly' do
diff --git a/spec/lib/gitlab/git/lfs_pointer_file_spec.rb b/spec/lib/gitlab/git/lfs_pointer_file_spec.rb
index f45c7cccca0..b210c86c3d1 100644
--- a/spec/lib/gitlab/git/lfs_pointer_file_spec.rb
+++ b/spec/lib/gitlab/git/lfs_pointer_file_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::LfsPointerFile do
let(:data) { "1234\n" }
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index a1fb8b70bd7..9a87911b6e8 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-RSpec.describe Gitlab::Git::Repository, :seed_helper do
+RSpec.describe Gitlab::Git::Repository do
include Gitlab::EncodingHelper
include RepoHelpers
using RSpec::Parameterized::TableSyntax
@@ -21,13 +21,11 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
- let(:mutable_repository) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '', 'group/project') }
- let(:mutable_repository_path) { File.join(TestEnv.repos_path, mutable_repository.relative_path) }
- let(:mutable_repository_rugged) { Rugged::Repository.new(mutable_repository_path) }
- let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
- let(:repository_path) { File.join(TestEnv.repos_path, repository.relative_path) }
- let(:repository_rugged) { Rugged::Repository.new(repository_path) }
- let(:storage_path) { TestEnv.repos_path }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:repository) { project.repository.raw }
+
+ let(:mutable_project) { create(:project, :repository) }
+ let(:mutable_repository) { mutable_project.repository.raw }
let(:user) { build(:user) }
describe "Respond to" do
@@ -61,8 +59,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#branch_names' do
subject { repository.branch_names }
- it 'has SeedRepo::Repo::BRANCHES.size elements' do
- expect(subject.size).to eq(SeedRepo::Repo::BRANCHES.size)
+ it 'has TestRepo::BRANCH_SHA.size elements' do
+ expect(subject.size).to eq(TestEnv::BRANCH_SHA.size)
end
it 'returns UTF-8' do
@@ -85,8 +83,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it { is_expected.to be_kind_of Array }
- it 'has SeedRepo::Repo::TAGS.size elements' do
- expect(subject.size).to eq(SeedRepo::Repo::TAGS.size)
+ it 'has some elements' do
+ expect(subject.size).to be >= 1
end
it 'returns UTF-8' do
@@ -96,63 +94,24 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#last' do
subject { super().last }
- it { is_expected.to eq("v1.2.1") }
+ it { is_expected.to eq("v1.1.1") }
end
+
it { is_expected.to include("v1.0.0") }
it { is_expected.not_to include("v5.0.0") }
- it 'gets the tag names from GitalyClient' do
- expect_any_instance_of(Gitlab::GitalyClient::RefService).to receive(:tag_names)
- subject
- end
-
it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RefService, :tag_names
end
describe '#tags' do
subject { repository.tags }
- it 'gets tags from GitalyClient' do
- expect_next_instance_of(Gitlab::GitalyClient::RefService) do |service|
- expect(service).to receive(:tags)
- end
-
- subject
- end
-
- context 'with sorting option' do
- subject { repository.tags(sort_by: 'name_asc') }
-
- it 'gets tags from GitalyClient' do
- expect_next_instance_of(Gitlab::GitalyClient::RefService) do |service|
- expect(service).to receive(:tags).with(sort_by: 'name_asc', pagination_params: nil)
- end
-
- subject
- end
- end
-
- context 'with pagination option' do
- subject { repository.tags(pagination_params: { limit: 5, page_token: 'refs/tags/v1.0.0' }) }
-
- it 'gets tags from GitalyClient' do
- expect_next_instance_of(Gitlab::GitalyClient::RefService) do |service|
- expect(service).to receive(:tags).with(
- sort_by: nil,
- pagination_params: { limit: 5, page_token: 'refs/tags/v1.0.0' }
- )
- end
-
- subject
- end
- end
-
it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RefService, :tags
end
describe '#archive_metadata' do
let(:storage_path) { '/tmp' }
- let(:cache_key) { File.join(repository.gl_repository, SeedRepo::LastCommit::ID) }
+ let(:cache_key) { File.join(repository.gl_repository, TestEnv::BRANCH_SHA['master']) }
let(:append_sha) { true }
let(:ref) { 'master' }
@@ -162,12 +121,12 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:expected_extension) { 'tar.gz' }
let(:expected_filename) { "#{expected_prefix}.#{expected_extension}" }
let(:expected_path) { File.join(storage_path, cache_key, "@v2", expected_filename) }
- let(:expected_prefix) { "gitlab-git-test-#{ref}-#{SeedRepo::LastCommit::ID}" }
+ let(:expected_prefix) { "gitlab-git-test-#{ref}-#{TestEnv::BRANCH_SHA['master']}" }
subject(:metadata) { repository.archive_metadata(ref, storage_path, 'gitlab-git-test', format, append_sha: append_sha, path: path) }
it 'sets CommitId to the commit SHA' do
- expect(metadata['CommitId']).to eq(SeedRepo::LastCommit::ID)
+ expect(metadata['CommitId']).to start_with(TestEnv::BRANCH_SHA['master'])
end
it 'sets ArchivePrefix to the expected prefix' do
@@ -175,7 +134,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
it 'sets ArchivePath to the expected globally-unique path' do
- expect(expected_path).to include(File.join(repository.gl_repository, SeedRepo::LastCommit::ID))
+ expect(expected_path).to include(File.join(repository.gl_repository, TestEnv::BRANCH_SHA['master']))
expect(metadata['ArchivePath']).to eq(expected_path)
end
@@ -190,7 +149,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
context 'append_sha varies archive path and filename' do
where(:append_sha, :ref, :expected_prefix) do
- sha = SeedRepo::LastCommit::ID
+ sha = TestEnv::BRANCH_SHA['master']
true | 'master' | "gitlab-git-test-master-#{sha}"
true | sha | "gitlab-git-test-#{sha}-#{sha}"
@@ -224,13 +183,13 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#size' do
subject { repository.size }
- it { is_expected.to be < 2 }
+ it { is_expected.to be > 0 }
end
describe '#to_s' do
subject { repository.to_s }
- it { is_expected.to eq("<Gitlab::Git::Repository: group/project>") }
+ it { is_expected.to eq("<Gitlab::Git::Repository: #{project.full_path}>") }
end
describe '#object_directory_size' do
@@ -259,26 +218,25 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#first' do
subject { super().first }
- it { is_expected.to eq('feature') }
+ it { is_expected.to eq(TestEnv::BRANCH_SHA.keys.min) }
end
describe '#last' do
subject { super().last }
- it { is_expected.to eq('v1.2.1') }
+ it { is_expected.to eq('v1.1.1') }
end
end
describe '#submodule_url_for' do
- let(:ref) { 'master' }
+ let(:ref) { 'submodule_inside_folder' }
def submodule_url(path)
repository.submodule_url_for(ref, path)
end
it { expect(submodule_url('six')).to eq('git://github.com/randx/six.git') }
- it { expect(submodule_url('nested/six')).to eq('git://github.com/randx/six.git') }
- it { expect(submodule_url('deeper/nested/six')).to eq('git://github.com/randx/six.git') }
+ it { expect(submodule_url('test_inside_folder/another_folder/six')).to eq('git://github.com/randx/six.git') }
it { expect(submodule_url('invalid/path')).to eq(nil) }
context 'uncommitted submodule dir' do
@@ -288,7 +246,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
context 'tags' do
- let(:ref) { 'v1.2.1' }
+ let(:ref) { 'v1.1.1' }
it { expect(submodule_url('six')).to eq('git://github.com/randx/six.git') }
end
@@ -313,17 +271,15 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
urls = repository.submodule_urls_for(ref)
expect(urls).to eq({
- "deeper/nested/six" => "git://github.com/randx/six.git",
- "gitlab-grack" => "https://gitlab.com/gitlab-org/gitlab-grack.git",
- "gitlab-shell" => "https://github.com/gitlabhq/gitlab-shell.git",
- "nested/six" => "git://github.com/randx/six.git",
+ "gitlab-grack" => "https://gitlab.com/gitlab-org/gitlab-grack.git",
+ "gitlab-shell" => "https://github.com/gitlabhq/gitlab-shell.git",
"six" => "git://github.com/randx/six.git"
})
end
end
describe '#commit_count' do
- it { expect(repository.commit_count("master")).to eq(25) }
+ it { expect(repository.commit_count("master")).to eq(37) }
it { expect(repository.commit_count("feature")).to eq(9) }
it { expect(repository.commit_count("does-not-exist")).to eq(0) }
@@ -353,7 +309,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch('right-branch')
left.times do |i|
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: 'left-branch',
message: 'some more content for a',
@@ -366,7 +322,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
right.times do |i|
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: 'right-branch',
message: 'some more content for b',
@@ -411,7 +367,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch('right-branch')
left.times do |i|
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: 'left-branch',
message: 'some more content for a',
@@ -424,7 +380,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
right.times do |i|
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: 'right-branch',
message: 'some more content for b',
@@ -461,47 +417,32 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#has_local_branches?' do
context 'check for local branches' do
it { expect(repository.has_local_branches?).to eq(true) }
+ end
+ end
- context 'mutable' do
- let(:repository) { mutable_repository }
+ describe '#delete_branch' do
+ let(:repository) { mutable_repository }
- after do
- ensure_seeds
- end
+ it 'deletes a branch' do
+ expect(repository.find_branch('feature')).not_to be_nil
- it 'returns false when there are no branches' do
- # Sanity check
- expect(repository.has_local_branches?).to eq(true)
+ repository.delete_branch('feature')
- FileUtils.rm_rf(File.join(repository_path, 'packed-refs'))
- heads_dir = File.join(repository_path, 'refs/heads')
- FileUtils.rm_rf(heads_dir)
- FileUtils.mkdir_p(heads_dir)
+ expect(repository.find_branch('feature')).to be_nil
+ end
- repository.expire_has_local_branches_cache
- expect(repository.has_local_branches?).to eq(false)
- end
- end
+ it 'deletes a fully qualified branch' do
+ expect(repository.find_branch('feature')).not_to be_nil
- context 'memoizes the value' do
- it 'returns true' do
- expect(repository).to receive(:uncached_has_local_branches?).once.and_call_original
+ repository.delete_branch('refs/heads/feature')
- 2.times do
- expect(repository.has_local_branches?).to eq(true)
- end
- end
- end
+ expect(repository.find_branch('feature')).to be_nil
end
end
describe '#delete_refs' do
let(:repository) { mutable_repository }
- after do
- ensure_seeds
- end
-
it 'deletes the ref' do
repository.delete_refs('refs/heads/feature')
@@ -548,9 +489,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
subject { repository.refs_hash }
it "has as many entries as branches and tags" do
- expected_refs = SeedRepo::Repo::BRANCHES + SeedRepo::Repo::TAGS
# We flatten in case a commit is pointed at by more than one branch and/or tag
- expect(subject.values.flatten.size).to eq(expected_refs.size)
+ expect(subject.values.flatten.size).to be > 0
end
it 'has valid commit ids as keys' do
@@ -598,7 +538,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
before do
repository.create_branch(ref)
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: ref,
message: 'committing something',
@@ -608,7 +548,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
content: content
}]
)
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: ref,
message: 'committing something',
@@ -620,10 +560,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
)
end
- after do
- ensure_seeds
- end
-
subject do
repository.search_files_by_content(content, ref)
end
@@ -647,8 +583,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:filter) { 'files\/.*\/.*\.rb' }
it 'returns matched files' do
- expect(result).to contain_exactly('files/links/regex.rb',
- 'files/ruby/popen.rb',
+ expect(result).to contain_exactly('files/ruby/popen.rb',
'files/ruby/regex.rb',
'files/ruby/version_info.rb')
end
@@ -673,6 +608,61 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
+ describe '#search_files_by_name' do
+ let(:ref) { 'master' }
+
+ subject(:result) { mutable_repository.search_files_by_name(query, ref) }
+
+ context 'when sending a valid name' do
+ let(:query) { 'files/ruby/popen.rb' }
+
+ it 'returns matched files' do
+ expect(result).to contain_exactly('files/ruby/popen.rb')
+ end
+ end
+
+ context 'when sending a name with space' do
+ let(:query) { 'file with space.md' }
+
+ before do
+ mutable_repository.commit_files(
+ user,
+ actions: [{ action: :create, file_path: "file with space.md", content: "Test content" }],
+ branch_name: ref, message: "Test"
+ )
+ end
+
+ it 'returns matched files' do
+ expect(result).to contain_exactly('file with space.md')
+ end
+ end
+
+ context 'when sending a name with special ASCII characters' do
+ let(:file_name) { 'Hello !@#$%^&*()' }
+ let(:query) { file_name }
+
+ before do
+ mutable_repository.commit_files(
+ user,
+ actions: [{ action: :create, file_path: file_name, content: "Test content" }],
+ branch_name: ref, message: "Test"
+ )
+ end
+
+ it 'returns matched files' do
+ expect(result).to contain_exactly(file_name)
+ end
+ end
+
+ context 'when sending a non-existing name' do
+ let(:query) { 'please do not exist.md' }
+
+ it 'raises error' do
+ expect(result).to eql([])
+ end
+ end
+ end
+
describe '#find_remote_root_ref' do
it 'gets the remote root ref from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::RemoteService)
@@ -720,7 +710,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
before do
# Add new commits so that there's a renamed file in the commit history
- @commit_with_old_name_id = repository.multi_action(
+ @commit_with_old_name_id = repository.commit_files(
user,
branch_name: repository.root_ref,
message: 'Update CHANGELOG',
@@ -730,7 +720,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
content: 'CHANGELOG'
}]
).newrev
- @rename_commit_id = repository.multi_action(
+ @rename_commit_id = repository.commit_files(
user,
branch_name: repository.root_ref,
message: 'Move CHANGELOG to encoding/',
@@ -741,7 +731,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
content: 'CHANGELOG'
}]
).newrev
- @commit_with_new_name_id = repository.multi_action(
+ @commit_with_new_name_id = repository.commit_files(
user,
branch_name: repository.root_ref,
message: 'Edit encoding/CHANGELOG',
@@ -755,7 +745,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
after do
# Erase our commits so other tests get the original repo
- repository.write_ref(repository.root_ref, SeedRepo::LastCommit::ID)
+ repository.write_ref(repository.root_ref, TestEnv::BRANCH_SHA['master'])
end
context "where 'follow' == true" do
@@ -908,16 +898,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
expect(log_commits).not_to include(commit_with_new_name)
end
end
-
- context "and 'path' includes a directory that used to be a file" do
- let(:log_commits) do
- repository.log(options.merge(ref: "refs/heads/fix-blob-path", path: "files/testdir/file.txt"))
- end
-
- it "returns a list of commits" do
- expect(log_commits.size).to eq(1)
- end
- end
end
context "where provides 'after' timestamp" do
@@ -981,7 +961,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it 'returns a list of commits' do
commits = repository.log({ all: true, limit: 50 })
- expect(commits.size).to eq(37)
+ expect(commits.size).to eq(50)
end
end
end
@@ -992,7 +972,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe '#blobs' do
- let_it_be(:commit_oid) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
+ let_it_be(:commit_oid) { TestEnv::BRANCH_SHA['master'] }
shared_examples 'a blob enumeration' do
it 'enumerates blobs' do
@@ -1008,7 +988,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
context 'single revision' do
let(:revisions) { [commit_oid] }
- let(:expected_blobs) { 53 }
+ let(:expected_blobs) { 52 }
it_behaves_like 'a blob enumeration'
end
@@ -1038,48 +1018,31 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it_behaves_like 'a blob enumeration'
end
-
- context 'partially blank revisions' do
- let(:revisions) { [::Gitlab::Git::BLANK_SHA, commit_oid] }
- let(:expected_blobs) { 53 }
-
- before do
- expect_next_instance_of(Gitlab::GitalyClient::BlobService) do |service|
- expect(service)
- .to receive(:list_blobs)
- .with([commit_oid], kind_of(Hash))
- .and_call_original
- end
- end
-
- it_behaves_like 'a blob enumeration'
- end
end
describe '#new_blobs' do
let(:repository) { mutable_repository }
- let(:repository_rugged) { mutable_repository_rugged }
- let(:blob) { create_blob('This is a new blob') }
- let(:commit) { create_commit('nested/new-blob.txt' => blob) }
-
- def create_blob(content)
- repository_rugged.write(content, :blob)
- end
+ let(:commit) { create_commit('nested/new-blob.txt' => 'This is a new blob') }
def create_commit(blobs)
- author = { name: 'Test User', email: 'mail@example.com', time: Time.now }
+ commit_result = repository.commit_files(
+ user,
+ branch_name: 'a-new-branch',
+ message: 'Add a file',
+ actions: blobs.map do |path, content|
+ {
+ action: :create,
+ file_path: path,
+ content: content
+ }
+ end
+ )
- index = repository_rugged.index
- blobs.each do |path, oid|
- index.add(path: path, oid: oid, mode: 0100644)
- end
+ # new_blobs only returns unreferenced blobs because it is used for hooks.
+ # Gitaly does not allow us to create loose objects via the RPC.
+ repository.delete_branch('a-new-branch')
- Rugged::Commit.create(repository_rugged,
- author: author,
- committer: author,
- message: "Message",
- parents: [],
- tree: index.write_tree(repository_rugged))
+ commit_result.newrev
end
subject { repository.new_blobs(newrevs).to_a }
@@ -1112,7 +1075,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:newrevs) { commit }
let(:expected_newrevs) { ['--not', '--all', '--not', newrevs] }
let(:expected_blobs) do
- [have_attributes(class: Gitlab::Git::Blob, id: blob, path: 'nested/new-blob.txt', size: 18)]
+ [have_attributes(class: Gitlab::Git::Blob, id: an_instance_of(String), path: 'nested/new-blob.txt', size: 18)]
end
it_behaves_like '#new_blobs with revisions'
@@ -1122,20 +1085,19 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:newrevs) { [commit] }
let(:expected_newrevs) { ['--not', '--all', '--not'] + newrevs }
let(:expected_blobs) do
- [have_attributes(class: Gitlab::Git::Blob, id: blob, path: 'nested/new-blob.txt', size: 18)]
+ [have_attributes(class: Gitlab::Git::Blob, id: an_instance_of(String), path: 'nested/new-blob.txt', size: 18)]
end
it_behaves_like '#new_blobs with revisions'
end
context 'with multiple revisions' do
- let(:another_blob) { create_blob('Another blob') }
- let(:newrevs) { [commit, create_commit('another_path.txt' => another_blob)] }
+ let(:newrevs) { [commit, create_commit('another_path.txt' => 'Another blob')] }
let(:expected_newrevs) { ['--not', '--all', '--not'] + newrevs.sort }
let(:expected_blobs) do
[
- have_attributes(class: Gitlab::Git::Blob, id: blob, path: 'nested/new-blob.txt', size: 18),
- have_attributes(class: Gitlab::Git::Blob, id: another_blob, path: 'another_path.txt', size: 12)
+ have_attributes(class: Gitlab::Git::Blob, id: an_instance_of(String), path: 'nested/new-blob.txt', size: 18),
+ have_attributes(class: Gitlab::Git::Blob, id: an_instance_of(String), path: 'another_path.txt', size: 12)
]
end
@@ -1147,7 +1109,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:expected_newrevs) { ['--not', '--all', '--not', commit] }
let(:expected_blobs) do
[
- have_attributes(class: Gitlab::Git::Blob, id: blob, path: 'nested/new-blob.txt', size: 18)
+ have_attributes(class: Gitlab::Git::Blob, id: an_instance_of(String), path: 'nested/new-blob.txt', size: 18)
]
end
@@ -1159,7 +1121,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:expected_newrevs) { ['--not', '--all', '--not', commit] }
let(:expected_blobs) do
[
- have_attributes(class: Gitlab::Git::Blob, id: blob, path: 'nested/new-blob.txt', size: 18)
+ have_attributes(class: Gitlab::Git::Blob, id: an_instance_of(String), path: 'nested/new-blob.txt', size: 18)
]
end
@@ -1212,14 +1174,22 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#new_commits' do
let(:repository) { mutable_repository }
let(:new_commit) do
- author = { name: 'Test User', email: 'mail@example.com', time: Time.now }
+ commit_result = repository.commit_files(
+ user,
+ branch_name: 'a-new-branch',
+ message: 'Message',
+ actions: [{
+ action: :create,
+ file_path: 'some_file.txt',
+ content: 'This is a file'
+ }]
+ )
+
+ # new_commits only returns unreferenced commits because it is used for
+ # hooks. Gitaly does not allow us to create loose objects via the RPC.
+ repository.delete_branch('a-new-branch')
- Rugged::Commit.create(repository_rugged,
- author: author,
- committer: author,
- message: "Message",
- parents: [],
- tree: "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
+ commit_result.newrev
end
let(:expected_commits) { 1 }
@@ -1248,7 +1218,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#count_commits_between' do
subject { repository.count_commits_between('feature', 'master') }
- it { is_expected.to eq(17) }
+ it { is_expected.to eq(29) }
end
describe '#raw_changes_between' do
@@ -1275,26 +1245,26 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
- context 'with valid revs' do
- let(:old_rev) { 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6' }
- let(:new_rev) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
+ context 'with valid revs', :aggregate_failures do
+ let(:old_rev) { TestEnv::BRANCH_SHA['feature'] }
+ let(:new_rev) { TestEnv::BRANCH_SHA['master'] }
it 'returns the changes' do
- expect(changes.size).to eq(9)
- expect(changes.first.operation).to eq(:modified)
- expect(changes.first.new_path).to eq('.gitmodules')
+ expect(changes.size).to eq(21)
+ expect(changes.first.operation).to eq(:deleted)
+ expect(changes.first.old_path).to eq('.DS_Store')
expect(changes.last.operation).to eq(:added)
- expect(changes.last.new_path).to eq('files/lfs/picture-invalid.png')
+ expect(changes.last.new_path).to eq('with space/README.md')
end
end
end
describe '#merge_base' do
where(:from, :to, :result) do
- '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' | '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d'
- '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d'
- '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | 'foobar' | nil
- 'foobar' | '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | nil
+ 'master' | 'feature' | 'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
+ 'feature' | 'master' | 'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
+ 'master' | 'foobar' | nil
+ 'foobar' | 'master' | nil
end
with_them do
@@ -1308,7 +1278,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it 'returns the number of commits after timestamp' do
options = { ref: 'master', after: Time.iso8601('2013-03-03T20:15:01+00:00') }
- expect(repository.count_commits(options)).to eq(25)
+ expect(repository.count_commits(options)).to eq(37)
end
end
@@ -1337,28 +1307,28 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
context 'with option :from and option :to' do
- it 'returns the number of commits ahead for fix-mode..fix-blob-path' do
- options = { from: 'fix-mode', to: 'fix-blob-path' }
+ it 'returns the number of commits ahead for master..feature' do
+ options = { from: 'master', to: 'feature' }
- expect(repository.count_commits(options)).to eq(2)
+ expect(repository.count_commits(options)).to eq(1)
end
- it 'returns the number of commits ahead for fix-blob-path..fix-mode' do
- options = { from: 'fix-blob-path', to: 'fix-mode' }
+ it 'returns the number of commits ahead for feature..master' do
+ options = { from: 'feature', to: 'master' }
- expect(repository.count_commits(options)).to eq(1)
+ expect(repository.count_commits(options)).to eq(29)
end
context 'with option :left_right' do
- it 'returns the number of commits for fix-mode...fix-blob-path' do
- options = { from: 'fix-mode', to: 'fix-blob-path', left_right: true }
+ it 'returns the number of commits for master..feature' do
+ options = { from: 'master', to: 'feature', left_right: true }
- expect(repository.count_commits(options)).to eq([1, 2])
+ expect(repository.count_commits(options)).to eq([29, 1])
end
context 'with max_count' do
- it 'returns the number of commits with path' do
- options = { from: 'fix-mode', to: 'fix-blob-path', left_right: true, max_count: 1 }
+ it 'returns the number of commits' do
+ options = { from: 'feature', to: 'master', left_right: true, max_count: 1 }
expect(repository.count_commits(options)).to eq([1, 1])
end
@@ -1378,7 +1348,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it "returns the number of commits in the whole repository" do
options = { all: true }
- expect(repository.count_commits(options)).to eq(34)
+ expect(repository.count_commits(options)).to eq(314)
end
end
@@ -1416,10 +1386,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch('local_branch')
end
- after do
- ensure_seeds
- end
-
it 'returns the local and remote branches' do
expect(subject.any? { |b| b.name == 'joe/remote_branch' }).to eq(true)
expect(subject.any? { |b| b.name == 'local_branch' }).to eq(true)
@@ -1431,7 +1397,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#branch_count' do
it 'returns the number of branches' do
- expect(repository.branch_count).to eq(11)
+ expect(repository.branch_count).to eq(TestEnv::BRANCH_SHA.size)
end
context 'with local and remote branches' do
@@ -1442,10 +1408,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch('local_branch')
end
- after do
- ensure_seeds
- end
-
it 'returns the count of local branches' do
expect(repository.branch_count).to eq(repository.local_branches.count)
end
@@ -1488,21 +1450,16 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
context 'when no branch names are specified' do
+ let(:repository) { mutable_repository }
+
before do
repository.create_branch('identical')
end
- after do
- ensure_seeds
- end
-
it 'returns all merged branch names except for identical one' do
names = repository.merged_branch_names
- expect(names).to include('merge-test')
- expect(names).to include('fix-mode')
- expect(names).not_to include('feature')
- expect(names).not_to include('identical')
+ expect(names).to match_array(["'test'", "branch-merged", "flatten-dir", "improve/awesome", "merge-test"])
end
end
end
@@ -1556,24 +1513,15 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe '#find_changed_paths' do
- let(:commit_1) { 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6' }
- let(:commit_2) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
+ let(:commit_1) { TestEnv::BRANCH_SHA['with-executables'] }
+ let(:commit_2) { TestEnv::BRANCH_SHA['master'] }
let(:commit_3) { '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9' }
let(:commit_1_files) do
- [
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/executables/ls"),
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/executables/touch"),
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/links/regex.rb"),
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/links/ruby-style-guide.md"),
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/links/touch"),
- Gitlab::Git::ChangedPath.new(status: :MODIFIED, path: ".gitmodules"),
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "deeper/nested/six"),
- Gitlab::Git::ChangedPath.new(status: :ADDED, path: "nested/six")
- ]
+ [Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/executables/ls")]
end
let(:commit_2_files) do
- [Gitlab::Git::ChangedPath.new(status: :ADDED, path: "bin/executable")]
+ [Gitlab::Git::ChangedPath.new(status: :ADDED, path: "bar/branch-test.txt")]
end
let(:commit_3_files) do
@@ -1621,7 +1569,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:not_existed_branch) { repository.ls_files("not_existed_branch") }
it "read every file paths of master branch" do
- expect(master_file_paths.length).to equal(40)
+ expect(master_file_paths.length).to equal(38)
end
it "reads full file paths of master branch" do
@@ -1646,11 +1594,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe "#copy_gitattributes" do
- let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') }
-
- after do
- FileUtils.rm_rf(attributes_path) if Dir.exist?(attributes_path)
- end
+ let(:repository) { mutable_repository }
it "raises an error with invalid ref" do
expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef)
@@ -1673,63 +1617,10 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository
end
end
-
- context "with no .gitattrbutes" do
- before do
- repository.copy_gitattributes("master")
- end
-
- it "does not have an info/attributes" do
- expect(File.exist?(attributes_path)).to be_falsey
- end
- end
-
- context "with .gitattrbutes" do
- before do
- repository.copy_gitattributes("gitattributes")
- end
-
- it "has an info/attributes" do
- expect(File.exist?(attributes_path)).to be_truthy
- end
-
- it "has the same content in info/attributes as .gitattributes" do
- contents = File.open(attributes_path, "rb") { |f| f.read }
- expect(contents).to eq("*.md binary\n")
- end
- end
-
- context "with updated .gitattrbutes" do
- before do
- repository.copy_gitattributes("gitattributes")
- repository.copy_gitattributes("gitattributes-updated")
- end
-
- it "has an info/attributes" do
- expect(File.exist?(attributes_path)).to be_truthy
- end
-
- it "has the updated content in info/attributes" do
- contents = File.read(attributes_path)
- expect(contents).to eq("*.txt binary\n")
- end
- end
-
- context "with no .gitattrbutes in HEAD but with previous info/attributes" do
- before do
- repository.copy_gitattributes("gitattributes")
- repository.copy_gitattributes("master")
- end
-
- it "does not have an info/attributes" do
- expect(File.exist?(attributes_path)).to be_falsey
- end
- end
end
describe '#gitattribute' do
- let(:project) { create(:project, :repository) }
- let(:repository) { project.repository }
+ let(:repository) { mutable_repository }
context 'with gitattributes' do
before do
@@ -1808,10 +1699,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch('local_branch')
end
- after do
- ensure_seeds
- end
-
it 'returns the local branches' do
expect(repository.local_branches.any? { |branch| branch.name == 'remote_branch' }).to eq(false)
expect(repository.local_branches.any? { |branch| branch.name == 'local_branch' }).to eq(true)
@@ -1880,7 +1767,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#languages' do
it 'returns exactly the expected results' do
- languages = repository.languages('4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6')
+ languages = repository.languages(TestEnv::BRANCH_SHA['master'])
expect(languages).to match_array([
{ value: a_value_within(0.1).of(66.7), label: "Ruby", color: "#701516", highlight: "#701516" },
@@ -1918,18 +1805,15 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#fetch_source_branch!' do
let(:local_ref) { 'refs/merge-requests/1/head' }
+ let(:repository) { create(:project, :repository).repository.raw }
let(:source_repository) { mutable_repository }
- after do
- ensure_seeds
- end
-
context 'when the branch exists' do
context 'when the commit does not exist locally' do
let(:source_branch) { 'new-branch-for-fetch-source-branch' }
let!(:new_oid) do
- source_repository.multi_action(
+ source_repository.commit_files(
user,
branch_name: source_branch,
message: 'Add a file',
@@ -1949,14 +1833,14 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
context 'when the commit exists locally' do
let(:source_branch) { 'master' }
- let(:expected_oid) { SeedRepo::LastCommit::ID }
+ let(:expected_oid) { TestEnv::BRANCH_SHA['master'] }
it 'writes the ref' do
# Sanity check: the commit should already exist
expect(repository.commit(expected_oid)).not_to be_nil
expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true)
- expect(repository.commit(local_ref).sha).to eq(expected_oid)
+ expect(repository.commit(local_ref).sha).to start_with(expected_oid)
end
end
end
@@ -2012,9 +1896,9 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
it 'writes other refs' do
- repository.write_ref('refs/heads/feature', SeedRepo::Commit::ID)
+ repository.write_ref('refs/heads/feature', TestEnv::BRANCH_SHA['master'])
- expect(repository.commit('feature').sha).to eq(SeedRepo::Commit::ID)
+ expect(repository.commit('feature').sha).to start_with(TestEnv::BRANCH_SHA['master'])
end
end
@@ -2052,28 +1936,28 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it 'returns nil for an empty repo' do
project = create(:project)
- expect(project.repository.refs_by_oid(oid: SeedRepo::Commit::ID, limit: 0)).to be_nil
+ expect(project.repository.refs_by_oid(oid: TestEnv::BRANCH_SHA['master'], limit: 0)).to be_nil
end
end
describe '#set_full_path' do
+ let(:full_path) { 'some/path' }
+
before do
- repository.set_full_path(full_path: repository_path)
+ repository.set_full_path(full_path: full_path)
end
- context 'is given a path' do
- it 'writes it to disk' do
- repository.set_full_path(full_path: "not-the/real-path.git")
+ it 'writes full_path to gitaly' do
+ repository.set_full_path(full_path: "not-the/real-path.git")
- expect(repository.full_path).to eq('not-the/real-path.git')
- end
+ expect(repository.full_path).to eq('not-the/real-path.git')
end
context 'it is given an empty path' do
it 'does not write it to disk' do
repository.set_full_path(full_path: "")
- expect(repository.full_path).to eq(repository_path)
+ expect(repository.full_path).to eq(full_path)
end
end
@@ -2145,10 +2029,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch(target_branch, '6d394385cf567f80a8fd85055db1ab4c5295806f')
end
- after do
- ensure_seeds
- end
-
it 'can perform a merge' do
merge_commit_id = nil
result = repository.merge(user, source_sha, target_branch, 'Test merge') do |commit_id|
@@ -2185,10 +2065,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.create_branch(target_branch, branch_head)
end
- after do
- ensure_seeds
- end
-
subject { repository.ff_merge(user, source_sha, target_branch) }
shared_examples '#ff_merge' do
@@ -2242,14 +2118,10 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:repository) { mutable_repository }
before do
- repository.write_ref("refs/delete/a", "0b4bc9a49b562e85de7cc9e834518ea6828729b9")
- repository.write_ref("refs/also-delete/b", "12d65c8dd2b2676fa3ac47d955accc085a37a9c1")
- repository.write_ref("refs/keep/c", "6473c90867124755509e100d0d35ebdc85a0b6ae")
- repository.write_ref("refs/also-keep/d", "0b4bc9a49b562e85de7cc9e834518ea6828729b9")
- end
-
- after do
- ensure_seeds
+ repository.write_ref("refs/delete/a", TestEnv::BRANCH_SHA['master'])
+ repository.write_ref("refs/also-delete/b", TestEnv::BRANCH_SHA['master'])
+ repository.write_ref("refs/keep/c", TestEnv::BRANCH_SHA['master'])
+ repository.write_ref("refs/also-keep/d", TestEnv::BRANCH_SHA['master'])
end
it 'deletes all refs except those with the specified prefixes' do
@@ -2272,11 +2144,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it 'saves a bundle to disk' do
repository.bundle_to_disk(save_path)
- success = system(
- *%W(#{Gitlab.config.git.bin_path} -C #{repository_path} bundle verify #{save_path}),
- [:out, :err] => '/dev/null'
- )
- expect(success).to be true
+ expect(File).to exist(save_path)
end
end
@@ -2326,41 +2194,22 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#checksum' do
it 'calculates the checksum for non-empty repo' do
- expect(repository.checksum).to eq '51d0a9662681f93e1fee547a6b7ba2bcaf716059'
- end
-
- it 'returns 0000000000000000000000000000000000000000 for an empty repo' do
- FileUtils.rm_rf(File.join(storage_path, 'empty-repo.git'))
-
- system(git_env, *%W(#{Gitlab.config.git.bin_path} init --bare empty-repo.git),
- chdir: storage_path,
- out: '/dev/null',
- err: '/dev/null')
-
- empty_repo = described_class.new('default', 'empty-repo.git', '', 'group/empty-repo')
-
- expect(empty_repo.checksum).to eq '0000000000000000000000000000000000000000'
+ expect(repository.checksum.length).to be(40)
+ expect(Gitlab::Git.blank_ref?(repository.checksum)).to be false
end
- it 'raises Gitlab::Git::Repository::InvalidRepository error for non-valid git repo' do
- FileUtils.rm_rf(File.join(storage_path, 'non-valid.git'))
-
- system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} non-valid.git),
- chdir: SEED_STORAGE_PATH,
- out: '/dev/null',
- err: '/dev/null')
-
- File.truncate(File.join(storage_path, 'non-valid.git/HEAD'), 0)
+ it 'returns a blank sha for an empty repo' do
+ repository = create(:project, :empty_repo).repository
- non_valid = described_class.new('default', 'non-valid.git', '', 'a/non-valid')
-
- expect { non_valid.checksum }.to raise_error(Gitlab::Git::Repository::InvalidRepository)
+ expect(Gitlab::Git.blank_ref?(repository.checksum)).to be true
end
- it 'raises Gitlab::Git::Repository::NoRepository error when there is no repo' do
- broken_repo = described_class.new('default', 'a/path.git', '', 'a/path')
+ it 'raises NoRepository for a non-existent repo' do
+ repository = create(:project).repository
- expect { broken_repo.checksum }.to raise_error(Gitlab::Git::Repository::NoRepository)
+ expect do
+ repository.checksum
+ end.to raise_error(described_class::NoRepository)
end
end
@@ -2375,7 +2224,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#squash' do
let(:branch_name) { 'fix' }
- let(:start_sha) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
+ let(:start_sha) { TestEnv::BRANCH_SHA['master'] }
let(:end_sha) { '12d65c8dd2b2676fa3ac47d955accc085a37a9c1' }
subject do
@@ -2412,7 +2261,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
context 'when the diff contains a rename' do
let(:end_sha) do
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: repository.root_ref,
message: 'Move CHANGELOG to encoding/',
@@ -2427,7 +2276,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
after do
# Erase our commits so other tests get the original repo
- repository.write_ref(repository.root_ref, SeedRepo::LastCommit::ID)
+ repository.write_ref(repository.root_ref, TestEnv::BRANCH_SHA['master'])
end
it 'does not include the renamed file in the sparse checkout' do
@@ -2480,9 +2329,9 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe '#disconnect_alternates' do
- let(:project) { create(:project, :repository) }
+ let(:project) { mutable_project }
+ let(:repository) { mutable_repository }
let(:pool_repository) { create(:pool_repository) }
- let(:repository) { project.repository }
let(:object_pool) { pool_repository.object_pool }
before do
@@ -2495,7 +2344,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it 'can still access objects in the object pool' do
object_pool.link(repository)
- new_commit_id = object_pool.repository.multi_action(
+ new_commit_id = object_pool.repository.commit_files(
project.owner,
branch_name: object_pool.repository.root_ref,
message: 'Add a file',
@@ -2515,8 +2364,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe '#rename' do
- let(:project) { create(:project, :repository) }
- let(:repository) { project.repository }
+ let(:repository) { mutable_repository }
it 'moves the repository' do
checksum = repository.checksum
@@ -2531,15 +2379,14 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe '#remove' do
- let(:project) { create(:project, :repository) }
- let(:repository) { project.repository }
+ let(:repository) { mutable_repository }
it 'removes the repository' do
expect(repository.exists?).to be true
repository.remove
- expect(repository.raw_repository.exists?).to be false
+ expect(repository.exists?).to be false
end
context 'when the repository does not exist' do
@@ -2550,15 +2397,14 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
repository.remove
- expect(repository.raw_repository.exists?).to be false
+ expect(repository.exists?).to be false
end
end
end
describe '#import_repository' do
- let_it_be(:project) { create(:project) }
+ let_it_be(:repository) { create(:project).repository }
- let(:repository) { project.repository }
let(:url) { 'http://invalid.invalid' }
it 'raises an error if a relative path is provided' do
@@ -2584,11 +2430,9 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
describe '#replicate' do
let(:new_repository) do
- Gitlab::Git::Repository.new('test_second_storage', TEST_REPO_PATH, '', 'group/project')
+ Gitlab::Git::Repository.new('test_second_storage', repository.relative_path, '', 'group/project')
end
- let(:new_repository_path) { File.join(TestEnv::SECOND_STORAGE_PATH, new_repository.relative_path) }
-
subject { new_repository.replicate(repository) }
before do
@@ -2622,7 +2466,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
context 'with keep-around refs' do
- let(:sha) { SeedRepo::Commit::ID }
+ let(:repository) { mutable_repository }
+ let(:sha) { TestEnv::BRANCH_SHA['master'] }
let(:keep_around_ref) { "refs/keep-around/#{sha}" }
let(:tmp_ref) { "refs/tmp/#{SecureRandom.hex}" }
diff --git a/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb b/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb
index 03d1c125e36..747611a59e6 100644
--- a/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb
+++ b/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
require 'json'
require 'tempfile'
-RSpec.describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
+RSpec.describe Gitlab::Git::RuggedImpl::UseRugged do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:feature_flag_name) { wrapper.rugged_feature_keys.first }
diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb
index 2e4520cd3a0..7c84c737c00 100644
--- a/spec/lib/gitlab/git/tree_spec.rb
+++ b/spec/lib/gitlab/git/tree_spec.rb
@@ -95,7 +95,7 @@ RSpec.describe Gitlab::Git::Tree do
let(:subdir_file) { entries.first }
# rubocop: enable Rails/FindBy
let!(:sha) do
- repository.multi_action(
+ repository.commit_files(
user,
branch_name: 'HEAD',
message: "Create #{filename}",
diff --git a/spec/lib/gitlab/git/util_spec.rb b/spec/lib/gitlab/git/util_spec.rb
index a0237c821b5..dd925a902ab 100644
--- a/spec/lib/gitlab/git/util_spec.rb
+++ b/spec/lib/gitlab/git/util_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Git::Util do
describe '#count_lines' do
diff --git a/spec/lib/gitlab/git/wiki_spec.rb b/spec/lib/gitlab/git/wiki_spec.rb
index dddcf8c40fc..05c7ac149e4 100644
--- a/spec/lib/gitlab/git/wiki_spec.rb
+++ b/spec/lib/gitlab/git/wiki_spec.rb
@@ -8,9 +8,15 @@ RSpec.describe Gitlab::Git::Wiki do
let(:project) { create(:project) }
let(:user) { project.first_owner }
let(:project_wiki) { ProjectWiki.new(project, user) }
+ let(:repository) { project_wiki.repository }
+ let(:default_branch) { described_class.default_ref(project) }
subject(:wiki) { project_wiki.wiki }
+ before do
+ repository.create_if_not_exists(project_wiki.default_branch)
+ end
+
describe '#pages' do
before do
create_page('page1', 'content')
@@ -44,7 +50,7 @@ RSpec.describe Gitlab::Git::Wiki do
after do
destroy_page('page1')
- destroy_page('page1', 'foo')
+ destroy_page('foo/page1')
end
it 'returns the right page' do
@@ -71,20 +77,20 @@ RSpec.describe Gitlab::Git::Wiki do
end
describe '#preview_slug' do
- where(:title, :format, :expected_slug) do
- 'The Best Thing' | :markdown | 'The-Best-Thing'
- 'The Best Thing' | :md | 'The-Best-Thing'
- 'The Best Thing' | :txt | 'The-Best-Thing'
- 'A Subject/Title Here' | :txt | 'A-Subject/Title-Here'
- 'A subject' | :txt | 'A-subject'
- 'A 1/B 2/C 3' | :txt | 'A-1/B-2/C-3'
- 'subject/title' | :txt | 'subject/title'
- 'subject/title.md' | :txt | 'subject/title.md'
- 'foo<bar>+baz' | :txt | 'foo-bar--baz'
- 'foo%2Fbar' | :txt | 'foo%2Fbar'
- '' | :markdown | '.md'
- '' | :md | '.md'
- '' | :txt | '.txt'
+ where(:title, :file_extension, :format, :expected_slug) do
+ 'The Best Thing' | :md | :markdown | 'The-Best-Thing'
+ 'The Best Thing' | :md | :md | 'The-Best-Thing'
+ 'The Best Thing' | :txt | :txt | 'The-Best-Thing'
+ 'A Subject/Title Here' | :txt | :txt | 'A-Subject/Title-Here'
+ 'A subject' | :txt | :txt | 'A-subject'
+ 'A 1/B 2/C 3' | :txt | :txt | 'A-1/B-2/C-3'
+ 'subject/title' | :txt | :txt | 'subject/title'
+ 'subject/title.md' | :txt | :txt | 'subject/title.md'
+ 'foo<bar>+baz' | :txt | :txt | 'foo-bar--baz'
+ 'foo%2Fbar' | :txt | :txt | 'foo%2Fbar'
+ '' | :md | :markdown | '.md'
+ '' | :md | :md | '.md'
+ '' | :txt | :txt | '.txt'
end
with_them do
@@ -97,7 +103,7 @@ RSpec.describe Gitlab::Git::Wiki do
it 'matches the slug generated by gitaly' do
skip('Gitaly cannot generate a slug for an empty title') unless title.present?
- create_page(title, 'content', format: format)
+ create_page(title, 'content', file_extension)
gitaly_slug = wiki.list_pages.first.url_path
@@ -106,16 +112,23 @@ RSpec.describe Gitlab::Git::Wiki do
end
end
- def create_page(name, content, format: :markdown)
- wiki.write_page(name, format, content, commit_details(name))
- end
-
- def commit_details(name)
- Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}")
+ def create_page(name, content, extension = :md)
+ repository.create_file(
+ user, ::Wiki.sluggified_full_path(name, extension.to_s), content,
+ branch_name: default_branch,
+ message: "created page #{name}",
+ author_email: user.email,
+ author_name: user.name
+ )
end
- def destroy_page(title, dir = '')
- page = wiki.page(title: title, dir: dir)
- project_wiki.delete_page(page, "test commit")
+ def destroy_page(name, extension = :md)
+ repository.delete_file(
+ user, ::Wiki.sluggified_full_path(name, extension.to_s),
+ branch_name: described_class.default_ref(project),
+ message: "delete page #{name}",
+ author_email: user.email,
+ author_name: user.name
+ )
end
end