Commit c2cdefd4 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Force push is handled by Gitaly now

Closes gitlab-org/gitaly#348
parent d04ac745
......@@ -7,18 +7,10 @@ module Gitlab
# Created or deleted branch
return false if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
GitalyClient.migrate(:force_push) do |is_enabled|
if is_enabled
!project
.repository
.gitaly_commit_client
.ancestor?(oldrev, newrev)
else
Gitlab::Git::RevList.new(
project.repository.raw, oldrev: oldrev, newrev: newrev
).missed_ref.present?
end
end
end
end
end
......
......@@ -1476,10 +1476,6 @@ module Gitlab
run_git!(args, lazy_block: block)
end
def missed_ref(oldrev, newrev)
run_git!(['rev-list', '--max-count=1', oldrev, "^#{newrev}"])
end
def with_worktree(worktree_path, branch, sparse_checkout_files: nil, env:)
base_args = %w(worktree add --detach)
......
# Gitaly note: JV: will probably be migrated indirectly by migrating the call sites.
module Gitlab
module Git
class RevList
......@@ -45,13 +43,6 @@ module Gitlab
&lazy_block)
end
# This methods returns an array of missed references
#
# Should become obsolete after https://gitlab.com/gitlab-org/gitaly/issues/348.
def missed_ref
repository.missed_ref(oldrev, newrev).split("\n")
end
private
def execute(args)
......
require 'spec_helper'
describe Gitlab::Checks::ForcePush do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository.raw }
set(:project) { create(:project, :repository) }
context "exit code checking", :skip_gitaly_mock do
it "does not raise a runtime error if the `popen` call to git returns a zero exit code" do
allow(repository).to receive(:popen).and_return(['normal output', 0])
describe '.force_push?' do
it 'returns false if the repo is empty' do
allow(project).to receive(:empty_repo?).and_return(true)
expect { described_class.force_push?(project, 'oldrev', 'newrev') }.not_to raise_error
expect(described_class.force_push?(project, 'HEAD', 'HEAD~')).to be(false)
end
it "raises a GitError error if the `popen` call to git returns a non-zero exit code" do
allow(repository).to receive(:popen).and_return(['error', 1])
expect { described_class.force_push?(project, 'oldrev', 'newrev') }
.to raise_error(Gitlab::Git::Repository::GitError)
it 'checks if old rev is an anchestor' do
expect(described_class.force_push?(project, 'HEAD', 'HEAD~')).to be(true)
end
end
end
......@@ -93,14 +93,4 @@ describe Gitlab::Git::RevList do
expect { |b| rev_list.all_objects(&b) }.to yield_with_args(%w[sha1 sha2])
end
end
context "#missed_ref" do
let(:rev_list) { described_class.new(repository, oldrev: 'oldrev', newrev: 'newrev') }
it 'calls out to `popen`' do
stub_popen_rev_list('--max-count=1', 'oldrev', '^newrev', with_lazy_block: false, output: "sha1\nsha2")
expect(rev_list.missed_ref).to eq(%w[sha1 sha2])
end
end
end
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