summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/rev_list_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/git/rev_list_spec.rb')
-rw-r--r--spec/lib/gitlab/git/rev_list_spec.rb92
1 files changed, 44 insertions, 48 deletions
diff --git a/spec/lib/gitlab/git/rev_list_spec.rb b/spec/lib/gitlab/git/rev_list_spec.rb
index d48629a296d..78894ba9409 100644
--- a/spec/lib/gitlab/git/rev_list_spec.rb
+++ b/spec/lib/gitlab/git/rev_list_spec.rb
@@ -3,58 +3,54 @@ require 'spec_helper'
describe Gitlab::Git::RevList, lib: true do
let(:project) { create(:project, :repository) }
- context "validations" do
- described_class::ALLOWED_VARIABLES.each do |var|
- context var do
- it "accepts values starting with the project repo path" do
- env = { var => "#{project.repository.path_to_repo}/objects" }
- rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
-
- expect(rev_list).to be_valid
- end
-
- it "rejects values starting not with the project repo path" do
- env = { var => "/some/other/path" }
- rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
-
- expect(rev_list).not_to be_valid
- end
-
- it "rejects values containing the project repo path but not starting with it" do
- env = { var => "/some/other/path/#{project.repository.path_to_repo}" }
- rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
-
- expect(rev_list).not_to be_valid
- end
-
- it "ignores nil values" do
- env = { var => nil }
- rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
-
- expect(rev_list).to be_valid
- end
- end
- end
+ before do
+ expect(Gitlab::Git::Env).to receive(:all).and_return({
+ GIT_OBJECT_DIRECTORY: 'foo',
+ GIT_ALTERNATE_OBJECT_DIRECTORIES: 'bar'
+ })
end
- context "#execute" do
- let(:env) { { "GIT_OBJECT_DIRECTORY" => project.repository.path_to_repo } }
- let(:rev_list) { Gitlab::Git::RevList.new('oldrev', 'newrev', project: project, env: env) }
-
- it "calls out to `popen` without environment variables if the record is invalid" do
- allow(rev_list).to receive(:valid?).and_return(false)
-
- expect(Open3).to receive(:popen3).with(hash_excluding(env), any_args)
-
- rev_list.execute
+ context "#new_refs" do
+ let(:rev_list) { Gitlab::Git::RevList.new(newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }
+
+ it 'calls out to `popen`' do
+ expect(Gitlab::Popen).to receive(:popen).with([
+ Gitlab.config.git.bin_path,
+ "--git-dir=#{project.repository.path_to_repo}",
+ 'rev-list',
+ 'newrev',
+ '--not',
+ '--all'
+ ],
+ nil,
+ {
+ 'GIT_OBJECT_DIRECTORY' => 'foo',
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar'
+ }).and_return(["sha1\nsha2", 0])
+
+ expect(rev_list.new_refs).to eq(%w[sha1 sha2])
end
+ end
- it "calls out to `popen` with environment variables if the record is valid" do
- allow(rev_list).to receive(:valid?).and_return(true)
-
- expect(Open3).to receive(:popen3).with(hash_including(env), any_args)
-
- rev_list.execute
+ context "#missed_ref" do
+ let(:rev_list) { Gitlab::Git::RevList.new(oldrev: 'oldrev', newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }
+
+ it 'calls out to `popen`' do
+ expect(Gitlab::Popen).to receive(:popen).with([
+ Gitlab.config.git.bin_path,
+ "--git-dir=#{project.repository.path_to_repo}",
+ 'rev-list',
+ '--max-count=1',
+ 'oldrev',
+ '^newrev'
+ ],
+ nil,
+ {
+ 'GIT_OBJECT_DIRECTORY' => 'foo',
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar'
+ }).and_return(["sha1\nsha2", 0])
+
+ expect(rev_list.missed_ref).to eq(%w[sha1 sha2])
end
end
end