Check the exit code while invoking git in the force push check.
Previously, we were calling out to `popen` without asserting on the returned exit-code. Now we raise a `RuntimeError` if the exit code is non-zero.
This commit is contained in:
parent
a2b39feb1a
commit
c937aec1f7
2 changed files with 26 additions and 2 deletions
|
@ -8,8 +8,13 @@ module Gitlab
|
|||
if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
|
||||
false
|
||||
else
|
||||
missed_ref, _ = Gitlab::Git::RevList.new(oldrev, newrev, project: project, env: env).execute
|
||||
missed_ref.present?
|
||||
missed_ref, exit_status = Gitlab::Git::RevList.new(oldrev, newrev, project: project, env: env).execute
|
||||
|
||||
if exit_status == 0
|
||||
missed_ref.present?
|
||||
else
|
||||
raise RuntimeError, "Got a non-zero exit code while calling out to `git rev-list` in the force-push check."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
19
spec/lib/gitlab/checks/force_push_spec.rb
Normal file
19
spec/lib/gitlab/checks/force_push_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Checks::ChangeAccess, lib: true do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
context "exit code checking" do
|
||||
it "does not raise a runtime error if the `popen` call to git returns a zero exit code" do
|
||||
allow(Gitlab::Popen).to receive(:popen).and_return(['normal output', 0])
|
||||
|
||||
expect { Gitlab::Checks::ForcePush.force_push?(project, 'oldrev', 'newrev') }.not_to raise_error
|
||||
end
|
||||
|
||||
it "raises a runtime error if the `popen` call to git returns a non-zero exit code" do
|
||||
allow(Gitlab::Popen).to receive(:popen).and_return(['error', 1])
|
||||
|
||||
expect { Gitlab::Checks::ForcePush.force_push?(project, 'oldrev', 'newrev') }.to raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue