Commit c0f0ccf2 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'zj-force-push-opt-out' into 'master'

Force push is handled by Gitaly now

Closes gitaly#348

See merge request gitlab-org/gitlab-ce!19992
parents 38edd5c3 c2cdefd4
...@@ -7,18 +7,10 @@ module Gitlab ...@@ -7,18 +7,10 @@ module Gitlab
# Created or deleted branch # Created or deleted branch
return false if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev) return false if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
GitalyClient.migrate(:force_push) do |is_enabled|
if is_enabled
!project !project
.repository .repository
.gitaly_commit_client .gitaly_commit_client
.ancestor?(oldrev, newrev) .ancestor?(oldrev, newrev)
else
Gitlab::Git::RevList.new(
project.repository.raw, oldrev: oldrev, newrev: newrev
).missed_ref.present?
end
end
end end
end end
end end
......
...@@ -1484,10 +1484,6 @@ module Gitlab ...@@ -1484,10 +1484,6 @@ module Gitlab
run_git!(args, lazy_block: block) run_git!(args, lazy_block: block)
end 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:) def with_worktree(worktree_path, branch, sparse_checkout_files: nil, env:)
base_args = %w(worktree add --detach) base_args = %w(worktree add --detach)
......
# Gitaly note: JV: will probably be migrated indirectly by migrating the call sites.
module Gitlab module Gitlab
module Git module Git
class RevList class RevList
...@@ -45,13 +43,6 @@ module Gitlab ...@@ -45,13 +43,6 @@ module Gitlab
&lazy_block) &lazy_block)
end 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 private
def execute(args) def execute(args)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Checks::ForcePush do describe Gitlab::Checks::ForcePush do
let(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
let(:repository) { project.repository.raw }
context "exit code checking", :skip_gitaly_mock do describe '.force_push?' do
it "does not raise a runtime error if the `popen` call to git returns a zero exit code" do it 'returns false if the repo is empty' do
allow(repository).to receive(:popen).and_return(['normal output', 0]) 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 end
it "raises a GitError error if the `popen` call to git returns a non-zero exit code" do it 'checks if old rev is an anchestor' do
allow(repository).to receive(:popen).and_return(['error', 1]) expect(described_class.force_push?(project, 'HEAD', 'HEAD~')).to be(true)
expect { described_class.force_push?(project, 'oldrev', 'newrev') }
.to raise_error(Gitlab::Git::Repository::GitError)
end end
end end
end end
...@@ -93,14 +93,4 @@ describe Gitlab::Git::RevList do ...@@ -93,14 +93,4 @@ describe Gitlab::Git::RevList do
expect { |b| rev_list.all_objects(&b) }.to yield_with_args(%w[sha1 sha2]) expect { |b| rev_list.all_objects(&b) }.to yield_with_args(%w[sha1 sha2])
end end
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 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