Commit 6be56fc8 authored by GitLab Bot's avatar GitLab Bot

Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-08-22

parents e02f4141 8b85d6bc
......@@ -164,7 +164,7 @@ class GitPushService < BaseService
end
def process_default_branch
offset = [push_commits_count - PROCESS_COMMIT_LIMIT, 0].max
offset = [push_commits_count_for_ref - PROCESS_COMMIT_LIMIT, 0].max
@push_commits = project.repository.commits(params[:newrev], offset: offset, limit: PROCESS_COMMIT_LIMIT)
project.after_create_default_branch
......@@ -178,7 +178,7 @@ class GitPushService < BaseService
params[:newrev],
params[:ref],
@push_commits,
commits_count: push_commits_count)
commits_count: commits_count)
end
def push_to_existing_branch?
......@@ -219,8 +219,14 @@ class GitPushService < BaseService
end
end
def push_commits_count
strong_memoize(:push_commits_count) do
def commits_count
return push_commits_count_for_ref if default_branch? && push_to_new_branch?
Array(@push_commits).size
end
def push_commits_count_for_ref
strong_memoize(:push_commits_count_for_ref) do
project.repository.commit_count_for_ref(params[:ref])
end
end
......
---
title: Fix broken Git over HTTP clones with LDAP users
merge_request: 21352
author:
type: fixed
---
title: Fix wrong commit count in push event payload
merge_request: 21338
author:
type: fixed
......@@ -29,6 +29,7 @@ module Gitlab
def self.enabled?(name)
return true if name == 'database'
return true if self.ldap_provider?(name) && providers.include?(name.to_sym)
Gitlab::Auth.omniauth_enabled? && providers.include?(name.to_sym)
end
......
require 'spec_helper'
describe Gitlab::Auth::OAuth::Provider do
describe '.enabled?' do
before do
allow(described_class).to receive(:providers).and_return([:ldapmain, :google_oauth2])
end
context 'when OmniAuth is disabled' do
before do
allow(Gitlab::Auth).to receive(:omniauth_enabled?).and_return(false)
end
it 'allows database auth' do
expect(described_class.enabled?('database')).to be_truthy
end
it 'allows LDAP auth' do
expect(described_class.enabled?('ldapmain')).to be_truthy
end
it 'does not allow other OmniAuth providers' do
expect(described_class.enabled?('google_oauth2')).to be_falsey
end
end
context 'when OmniAuth is enabled' do
before do
allow(Gitlab::Auth).to receive(:omniauth_enabled?).and_return(true)
end
it 'allows database auth' do
expect(described_class.enabled?('database')).to be_truthy
end
it 'allows LDAP auth' do
expect(described_class.enabled?('ldapmain')).to be_truthy
end
it 'allows other OmniAuth providers' do
expect(described_class.enabled?('google_oauth2')).to be_truthy
end
end
end
describe '#config_for' do
context 'for an LDAP provider' do
context 'when the provider exists' do
......
......@@ -226,16 +226,37 @@ describe GitPushService do
end
describe "Push Event" do
let!(:push_data) { push_data_from_service(project, user, oldrev, newrev, ref) }
let(:event) { Event.find_by_action(Event::PUSHED) }
context "with an existing branch" do
let!(:push_data) { push_data_from_service(project, user, oldrev, newrev, ref) }
let(:event) { Event.find_by_action(Event::PUSHED) }
it { expect(event).to be_an_instance_of(PushEvent) }
it { expect(event.project).to eq(project) }
it { expect(event.action).to eq(Event::PUSHED) }
it { expect(event.push_event_payload).to be_an_instance_of(PushEventPayload) }
it { expect(event.push_event_payload.commit_from).to eq(oldrev) }
it { expect(event.push_event_payload.commit_to).to eq(newrev) }
it { expect(event.push_event_payload.ref).to eq('master') }
it 'generates a push event with one commit' do
expect(event).to be_an_instance_of(PushEvent)
expect(event.project).to eq(project)
expect(event.action).to eq(Event::PUSHED)
expect(event.push_event_payload).to be_an_instance_of(PushEventPayload)
expect(event.push_event_payload.commit_from).to eq(oldrev)
expect(event.push_event_payload.commit_to).to eq(newrev)
expect(event.push_event_payload.ref).to eq('master')
expect(event.push_event_payload.commit_count).to eq(1)
end
end
context "with a new branch" do
let!(:new_branch_data) { push_data_from_service(project, user, Gitlab::Git::BLANK_SHA, newrev, ref) }
let(:event) { Event.find_by_action(Event::PUSHED) }
it 'generates a push event with more than one commit' do
expect(event).to be_an_instance_of(PushEvent)
expect(event.project).to eq(project)
expect(event.action).to eq(Event::PUSHED)
expect(event.push_event_payload).to be_an_instance_of(PushEventPayload)
expect(event.push_event_payload.commit_from).to be_nil
expect(event.push_event_payload.commit_to).to eq(newrev)
expect(event.push_event_payload.ref).to eq('master')
expect(event.push_event_payload.commit_count).to be > 1
end
end
context "Updates merge requests" do
it "when pushing a new branch for the first time" do
......@@ -246,6 +267,7 @@ describe GitPushService do
end
describe 'system hooks' do
let!(:push_data) { push_data_from_service(project, user, oldrev, newrev, ref) }
let(:system_hooks_service) { SystemHooksService.new }
it "sends a system hook after pushing a branch" do
......
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