Commit 5adb24dc authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-fix-diff-check-issue-55137' into 'master'

Fix DiffCheck failing due to invalid string argument

See merge request gitlab-org/gitlab-ee!8779
parents 63e9149c cfefab85
...@@ -78,9 +78,10 @@ describe Gitlab::Checks::DiffCheck do ...@@ -78,9 +78,10 @@ describe Gitlab::Checks::DiffCheck do
context 'file lock rules' do context 'file lock rules' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:path_lock) { create(:path_lock, path: 'README', project: project) }
it 'returns an error if the changes update a path locked by another user' do it 'returns an error if the changes update a path locked by another user' do
path_lock = create(:path_lock, path: 'README', project: project) path_lock
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "The path 'README' is locked by #{path_lock.user.name}") expect { subject.validate! }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "The path 'README' is locked by #{path_lock.user.name}")
end end
...@@ -90,6 +91,26 @@ describe Gitlab::Checks::DiffCheck do ...@@ -90,6 +91,26 @@ describe Gitlab::Checks::DiffCheck do
2.times { subject.validate! } 2.times { subject.validate! }
end end
context 'when the branch is being deleted' do
let(:newrev) { Gitlab::Git::BLANK_SHA }
it 'does not run' do
path_lock
expect { subject.validate! }.not_to raise_error
end
end
context 'when there is no valid change' do
let(:changes) { { oldrev: '_any', newrev: nil, ref: nil } }
it 'does not run' do
path_lock
expect { subject.validate! }.not_to raise_error
end
end
end end
end end
end end
...@@ -12,6 +12,7 @@ module Gitlab ...@@ -12,6 +12,7 @@ module Gitlab
}.freeze }.freeze
def validate! def validate!
return if deletion? || newrev.nil?
return unless should_run_diff_validations? return unless should_run_diff_validations?
return if commits.empty? return if commits.empty?
return unless uses_raw_delta_validations? return unless uses_raw_delta_validations?
...@@ -29,7 +30,7 @@ module Gitlab ...@@ -29,7 +30,7 @@ module Gitlab
private private
def should_run_diff_validations? def should_run_diff_validations?
newrev && oldrev && !deletion? && validate_lfs_file_locks? validate_lfs_file_locks?
end end
def validate_lfs_file_locks? def validate_lfs_file_locks?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment