diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-12-14 01:21:48 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-12-14 01:27:04 +0800 |
commit | 26af4b5a61d5cdaffa7769336f40cd0861f6b1d4 (patch) | |
tree | 805e9e2343f2bb7909535a770ac6dd30a3d70fa6 /app/models | |
parent | e5acebd9b99e3207427700144d9c83bcec4c629c (diff) | |
download | gitlab-ce-26af4b5a61d5cdaffa7769336f40cd0861f6b1d4.tar.gz |
Also check blob path from source branch
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_19747244
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/repository.rb | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 7a7236993a8..2e706b770b2 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -738,19 +738,11 @@ class Repository message:, branch_name:, author_email: nil, author_name: nil, source_branch_name: nil, source_project: project) - if branch_exists?(branch_name) - # tree_entry is private - entry = raw_repository.send(:tree_entry, commit(branch_name), path) - - if entry - if entry[:type] == :blob - raise Gitlab::Git::Repository::InvalidBlobName.new( - "Directory already exists as a file") - else - raise Gitlab::Git::Repository::InvalidBlobName.new( - "Directory already exists") - end - end + check_tree_entry_for_dir(branch_name, path) + + if source_branch_name + source_project.repository. + check_tree_entry_for_dir(source_branch_name, path) end commit_file( @@ -773,11 +765,16 @@ class Repository message:, branch_name:, update: true, author_email: nil, author_name: nil, source_branch_name: nil, source_project: project) - if branch_exists?(branch_name) && update == false - # tree_entry is private - if raw_repository.send(:tree_entry, commit(branch_name), path) - raise Gitlab::Git::Repository::InvalidBlobName.new( - "Filename already exists; update not allowed") + unless update + error_message = "Filename already exists; update not allowed" + + if tree_entry_at(branch_name, path) + raise Gitlab::Git::Repository::InvalidBlobName.new(error_message) + end + + if source_branch_name && + source_project.repository.tree_entry_at(source_branch_name, path) + raise Gitlab::Git::Repository::InvalidBlobName.new(error_message) end end @@ -1140,6 +1137,30 @@ class Repository end end + protected + + def tree_entry_at(branch_name, path) + branch_exists?(branch_name) && + # tree_entry is private + raw_repository.send(:tree_entry, commit(branch_name), path) + end + + def check_tree_entry_for_dir(branch_name, path) + return unless branch_exists?(branch_name) + + entry = tree_entry_at(branch_name, path) + + return unless entry + + if entry[:type] == :blob + raise Gitlab::Git::Repository::InvalidBlobName.new( + "Directory already exists as a file") + else + raise Gitlab::Git::Repository::InvalidBlobName.new( + "Directory already exists") + end + end + private def git_action(index, action) |