diff options
Diffstat (limited to 'spec/lib/gitlab/git/repository_spec.rb')
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 6dfa791f70b..c917945499c 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -929,7 +929,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end context 'with max_count' do - it 'returns the number of commits with path ' do + it 'returns the number of commits with path' do options = { ref: 'master', max_count: 5 } expect(repository.count_commits(options)).to eq(5) @@ -937,7 +937,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end context 'with path' do - it 'returns the number of commits with path ' do + it 'returns the number of commits with path' do options = { ref: 'master', path: 'encoding' } expect(repository.count_commits(options)).to eq(2) @@ -965,7 +965,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end context 'with max_count' do - it 'returns the number of commits with path ' do + it 'returns the number of commits with path' do options = { from: 'fix-mode', to: 'fix-blob-path', left_right: true, max_count: 1 } expect(repository.count_commits(options)).to eq([1, 1]) @@ -1185,6 +1185,66 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end end + describe '#find_changed_paths' do + let(:commit_1) { 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6' } + let(:commit_2) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' } + let(:commit_3) { '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9' } + let(:commit_1_files) do + [ + OpenStruct.new(status: :ADDED, path: "files/executables/ls"), + OpenStruct.new(status: :ADDED, path: "files/executables/touch"), + OpenStruct.new(status: :ADDED, path: "files/links/regex.rb"), + OpenStruct.new(status: :ADDED, path: "files/links/ruby-style-guide.md"), + OpenStruct.new(status: :ADDED, path: "files/links/touch"), + OpenStruct.new(status: :MODIFIED, path: ".gitmodules"), + OpenStruct.new(status: :ADDED, path: "deeper/nested/six"), + OpenStruct.new(status: :ADDED, path: "nested/six") + ] + end + + let(:commit_2_files) do + [OpenStruct.new(status: :ADDED, path: "bin/executable")] + end + + let(:commit_3_files) do + [ + OpenStruct.new(status: :MODIFIED, path: ".gitmodules"), + OpenStruct.new(status: :ADDED, path: "gitlab-shell") + ] + end + + it 'returns a list of paths' do + collection = repository.find_changed_paths([commit_1, commit_2, commit_3]) + + expect(collection).to be_a(Enumerable) + expect(collection.to_a).to eq(commit_1_files + commit_2_files + commit_3_files) + end + + it 'returns no paths when SHAs are invalid' do + collection = repository.find_changed_paths(['invalid', commit_1]) + + expect(collection).to be_a(Enumerable) + expect(collection.to_a).to be_empty + end + + it 'returns a list of paths even when containing a blank ref' do + collection = repository.find_changed_paths([nil, commit_1]) + + expect(collection).to be_a(Enumerable) + expect(collection.to_a).to eq(commit_1_files) + end + + it 'returns no paths when the commits are nil' do + expect_any_instance_of(Gitlab::GitalyClient::CommitService) + .not_to receive(:find_changed_paths) + + collection = repository.find_changed_paths([nil, nil]) + + expect(collection).to be_a(Enumerable) + expect(collection.to_a).to be_empty + end + end + describe "#ls_files" do let(:master_file_paths) { repository.ls_files("master") } let(:utf8_file_paths) { repository.ls_files("ls-files-utf8") } |