e394d2872a
- `raise "string"` raises a `RuntimeError` - no need to be explicit - Remove top-level comment in the `RevList` class - Use `%w()` instead of `%w[]` - Extract an `environment_variables` method to cache `env.slice(*ALLOWED_VARIABLES)` - Use `start_with?` for env variable validation instead of regex match - Validation specs for each allowed environment variable were identical. Build them dynamically. - Minor change to `popen3` expectation.
22 lines
648 B
Ruby
22 lines
648 B
Ruby
module Gitlab
|
|
module Checks
|
|
class ForcePush
|
|
def self.force_push?(project, oldrev, newrev, env: {})
|
|
return false if project.empty_repo?
|
|
|
|
# Created or deleted branch
|
|
if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
|
|
false
|
|
else
|
|
missed_ref, exit_status = Gitlab::Git::RevList.new(oldrev, newrev, project: project, env: env).execute
|
|
|
|
if exit_status == 0
|
|
missed_ref.present?
|
|
else
|
|
raise "Got a non-zero exit code while calling out to `git rev-list` in the force-push check."
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|