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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-07-20 18:04:41 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-07-20 18:04:41 +0300
commit51350d20b17c1045dbd4c749b018c481f7662d3c (patch)
tree1e6813407594735f035c07a06b6b463fb21ec1e1
parentd92903b19a0bb3688239cf2a2ca033c2949b5663 (diff)
parentf22fa58fd24f5efd5c8ee5855f1b650ee2fc6713 (diff)
Merge branch 'stop-vendoring-index' into 'master'
Stop vendoring gitlab/git/index.rb See merge request gitlab-org/gitaly!824
-rwxr-xr-x_support/vendor-gitlab-git1
-rw-r--r--changelogs/unreleased/stop-vendoring-index.yml5
-rw-r--r--ruby/lib/gitlab/git/index.rb (renamed from ruby/vendor/gitlab_git/lib/gitlab/git/index.rb)4
-rw-r--r--ruby/spec/lib/gitlab/git/index_spec.rb234
4 files changed, 240 insertions, 4 deletions
diff --git a/_support/vendor-gitlab-git b/_support/vendor-gitlab-git
index aa8db0b20..46fd5b38a 100755
--- a/_support/vendor-gitlab-git
+++ b/_support/vendor-gitlab-git
@@ -22,6 +22,7 @@ EXCLUDE = %w[
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/gitmodules_parser.rb
lib/gitlab/git/hook_env.rb
+ lib/gitlab/git/index.rb
lib/gitlab/git/lfs_changes.rb
lib/gitlab/git/lfs_pointer_file.rb
lib/gitlab/git/rev_list.rb
diff --git a/changelogs/unreleased/stop-vendoring-index.yml b/changelogs/unreleased/stop-vendoring-index.yml
new file mode 100644
index 000000000..5a496525a
--- /dev/null
+++ b/changelogs/unreleased/stop-vendoring-index.yml
@@ -0,0 +1,5 @@
+---
+title: Stop vendoring gitlab/git/index.rb
+merge_request: 824
+author:
+type: other
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/index.rb b/ruby/lib/gitlab/git/index.rb
index d94082a3e..2d4120c8a 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/index.rb
+++ b/ruby/lib/gitlab/git/index.rb
@@ -1,7 +1,3 @@
-# Gitaly note: JV: When the time comes I think we will want to copy this
-# class into Gitaly. None of its methods look like they should be RPC's.
-# The RPC's will be at a higher level.
-
module Gitlab
module Git
class Index
diff --git a/ruby/spec/lib/gitlab/git/index_spec.rb b/ruby/spec/lib/gitlab/git/index_spec.rb
new file mode 100644
index 000000000..6d4da8c6f
--- /dev/null
+++ b/ruby/spec/lib/gitlab/git/index_spec.rb
@@ -0,0 +1,234 @@
+require 'spec_helper'
+
+describe Gitlab::Git::Index do
+ include TestRepo
+
+ let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) }
+ let(:index) { described_class.new(repository) }
+
+ before do
+ index.read_tree(lookup('with-executables').tree)
+ end
+
+ describe '#create' do
+ let(:options) do
+ {
+ content: 'Lorem ipsum...',
+ file_path: 'documents/story.txt'
+ }
+ end
+
+ context 'when no file at that path exists' do
+ it 'creates the file in the index' do
+ index.create(options)
+
+ entry = index.get(options[:file_path])
+
+ expect(entry).not_to be_nil
+ expect(lookup(entry[:oid]).content).to eq(options[:content])
+ end
+ end
+
+ context 'when a file at that path exists' do
+ before do
+ options[:file_path] = 'files/executables/ls'
+ end
+
+ it 'raises an error' do
+ expect { index.create(options) }.to raise_error('A file with this name already exists')
+ end
+ end
+
+ context 'when content is in base64' do
+ before do
+ options[:content] = Base64.encode64(options[:content])
+ options[:encoding] = 'base64'
+ end
+
+ it 'decodes base64' do
+ index.create(options)
+
+ entry = index.get(options[:file_path])
+ expect(lookup(entry[:oid]).content).to eq(Base64.decode64(options[:content]))
+ end
+ end
+
+ context 'when content contains CRLF' do
+ before do
+ repository.autocrlf = :input
+ options[:content] = "Hello,\r\nWorld"
+ end
+
+ it 'converts to LF' do
+ index.create(options)
+
+ entry = index.get(options[:file_path])
+ expect(lookup(entry[:oid]).content).to eq("Hello,\nWorld")
+ end
+ end
+ end
+
+ describe '#create_dir' do
+ let(:options) do
+ {
+ file_path: 'newdir'
+ }
+ end
+
+ context 'when no file or dir at that path exists' do
+ it 'creates the dir in the index' do
+ index.create_dir(options)
+
+ entry = index.get(options[:file_path] + '/.gitkeep')
+
+ expect(entry).not_to be_nil
+ end
+ end
+
+ context 'when a file at that path exists' do
+ before do
+ options[:file_path] = 'files/executables/ls'
+ end
+
+ it 'raises an error' do
+ expect { index.create_dir(options) }.to raise_error('A file with this name already exists')
+ end
+ end
+
+ context 'when a directory at that path exists' do
+ before do
+ options[:file_path] = 'files/executables'
+ end
+
+ it 'raises an error' do
+ expect { index.create_dir(options) }.to raise_error('A directory with this name already exists')
+ end
+ end
+ end
+
+ describe '#update' do
+ let(:options) do
+ {
+ content: 'Lorem ipsum...',
+ file_path: 'README.md'
+ }
+ end
+
+ context 'when no file at that path exists' do
+ before do
+ options[:file_path] = 'documents/story.txt'
+ end
+
+ it 'raises an error' do
+ expect { index.update(options) }.to raise_error("A file with this name doesn't exist")
+ end
+ end
+
+ context 'when a file at that path exists' do
+ it 'updates the file in the index' do
+ index.update(options)
+
+ entry = index.get(options[:file_path])
+
+ expect(lookup(entry[:oid]).content).to eq(options[:content])
+ end
+
+ it 'preserves file mode' do
+ options[:file_path] = 'files/executables/ls'
+
+ index.update(options)
+
+ entry = index.get(options[:file_path])
+
+ expect(entry[:mode]).to eq(0100755)
+ end
+ end
+ end
+
+ describe '#move' do
+ let(:options) do
+ {
+ content: 'Lorem ipsum...',
+ previous_path: 'README.md',
+ file_path: 'NEWREADME.md'
+ }
+ end
+
+ context 'when no file at that path exists' do
+ it 'raises an error' do
+ options[:previous_path] = 'documents/story.txt'
+
+ expect { index.move(options) }.to raise_error("A file with this name doesn't exist")
+ end
+ end
+
+ context 'when a file at the new path already exists' do
+ it 'raises an error' do
+ options[:file_path] = 'CHANGELOG'
+
+ expect { index.move(options) }.to raise_error("A file with this name already exists")
+ end
+ end
+
+ context 'when a file at that path exists' do
+ it 'removes the old file in the index' do
+ index.move(options)
+
+ entry = index.get(options[:previous_path])
+
+ expect(entry).to be_nil
+ end
+
+ it 'creates the new file in the index' do
+ index.move(options)
+
+ entry = index.get(options[:file_path])
+
+ expect(entry).not_to be_nil
+ expect(lookup(entry[:oid]).content).to eq(options[:content])
+ end
+
+ it 'preserves file mode' do
+ options[:previous_path] = 'files/executables/ls'
+
+ index.move(options)
+
+ entry = index.get(options[:file_path])
+
+ expect(entry[:mode]).to eq(0100755)
+ end
+ end
+ end
+
+ describe '#delete' do
+ let(:options) do
+ {
+ file_path: 'README.md'
+ }
+ end
+
+ context 'when no file at that path exists' do
+ before do
+ options[:file_path] = 'documents/story.txt'
+ end
+
+ it 'raises an error' do
+ expect { index.delete(options) }.to raise_error("A file with this name doesn't exist")
+ end
+ end
+
+ context 'when a file at that path exists' do
+ it 'removes the file in the index' do
+ index.delete(options)
+
+ entry = index.get(options[:file_path])
+
+ expect(entry).to be_nil
+ end
+ end
+ end
+
+ def lookup(revision)
+ repository.rugged.rev_parse(revision)
+ end
+end