diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-02-24 09:32:10 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-24 09:55:01 -0600 |
commit | a530e9da3580e05a171b3ba0a3f4408afc000b10 (patch) | |
tree | 49e3787d12d2e7d3a40e3cdf1af0ff8643ac99e1 /lib/gitlab/git/index.rb | |
parent | 9e39b317a3865688e9fb204fb8680d3e91958fec (diff) | |
download | gitlab-ce-a530e9da3580e05a171b3ba0a3f4408afc000b10.tar.gz |
Address review
Diffstat (limited to 'lib/gitlab/git/index.rb')
-rw-r--r-- | lib/gitlab/git/index.rb | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/gitlab/git/index.rb b/lib/gitlab/git/index.rb index 69a7a513281..546696e4bd1 100644 --- a/lib/gitlab/git/index.rb +++ b/lib/gitlab/git/index.rb @@ -10,20 +10,20 @@ module Gitlab @raw_index = repository.rugged.index end - delegate :read_tree, to: :raw_index + delegate :read_tree, :get, to: :raw_index def write_tree raw_index.write_tree(repository.rugged) end - def get(*args) - raw_index.get(*args) + def dir_exists?(path) + raw_index.find { |entry| entry[:path].start_with?("#{path}/") } end def create(options) - normalize_options!(options) + options = normalize_options(options) - file_entry = raw_index.get(options[:file_path]) + file_entry = get(options[:file_path]) if file_entry raise Gitlab::Git::Repository::InvalidBlobName.new("Filename already exists") end @@ -32,13 +32,17 @@ module Gitlab end def create_dir(options) - normalize_options!(options) + options = normalize_options(options) - file_entry = raw_index.get(options[:file_path]) + file_entry = get(options[:file_path]) if file_entry raise Gitlab::Git::Repository::InvalidBlobName.new("Directory already exists as a file") end + if dir_exists?(options[:file_path]) + raise Gitlab::Git::Repository::InvalidBlobName.new("Directory already exists") + end + options = options.dup options[:file_path] += '/.gitkeep' options[:content] = '' @@ -47,9 +51,9 @@ module Gitlab end def update(options) - normalize_options!(options) + options = normalize_options(options) - file_entry = raw_index.get(options[:file_path]) + file_entry = get(options[:file_path]) unless file_entry raise Gitlab::Git::Repository::InvalidBlobName.new("File doesn't exist") end @@ -58,9 +62,9 @@ module Gitlab end def move(options) - normalize_options!(options) + options = normalize_options(options) - file_entry = raw_index.get(options[:previous_path]) + file_entry = get(options[:previous_path]) unless file_entry raise Gitlab::Git::Repository::InvalidBlobName.new("File doesn't exist") end @@ -71,9 +75,9 @@ module Gitlab end def delete(options) - normalize_options!(options) + options = normalize_options(options) - file_entry = raw_index.get(options[:file_path]) + file_entry = get(options[:file_path]) unless file_entry raise Gitlab::Git::Repository::InvalidBlobName.new("File doesn't exist") end @@ -83,13 +87,15 @@ module Gitlab private - def normalize_options!(options) + def normalize_options(options) + options = options.dup options[:file_path] = normalize_path(options[:file_path]) if options[:file_path] options[:previous_path] = normalize_path(options[:previous_path]) if options[:previous_path] + options end def normalize_path(path) - pathname = Gitlab::Git::PathHelper.normalize_path(path) + pathname = Gitlab::Git::PathHelper.normalize_path(path.dup) if pathname.each_filename.include?('..') raise Gitlab::Git::Repository::InvalidBlobName.new('Invalid path') |