Commit dee5e5e8 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'gitlab-git-update' into 'ce-to-ee'

Fix EE code after gitlab_git update from CE

Closes #842

See merge request !610
parents 4465c13b fd13056f
......@@ -241,7 +241,9 @@ class Repository
def remote_tags(remote)
gitlab_shell.list_remote_tags(storage_path, path_with_namespace, remote).map do |name, target|
Gitlab::Git::Tag.new(name, target)
# Is the tag annotated or lightweight?
object = target.is_a?(Rugged::Tag::Annotation) ? target : nil
Gitlab::Git::Tag.new(raw_repository, object, name, target)
end
end
......@@ -768,7 +770,7 @@ class Repository
name = ref.name.sub(/\Arefs\/remotes\/#{remote_name}\//, '')
begin
branches << Gitlab::Git::Branch.new(name, ref.target)
branches << Gitlab::Git::Branch.new(raw_repository, name, ref.target)
rescue Rugged::ReferenceError
# Omit invalid branch
end
......@@ -890,16 +892,19 @@ class Repository
end
end
def ff_merge(user, source_sha, target_branch, options = {})
def ff_merge(user, source, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
their_commit =
if source.is_a?(Gitlab::Git::Commit)
source.raw_commit
else
rugged.lookup(source)
end
raise "Invalid merge target" if our_commit.nil?
raise "Invalid merge source" if their_commit.nil?
commit_with_hooks(user, target_branch) do
source_sha
end
commit_with_hooks(user, target_branch) { their_commit.oid }
end
def merge(user, merge_request, options = {})
......
......@@ -36,7 +36,7 @@ module Projects
local_branch = local_branches[name]
if local_branch.nil?
result = CreateBranchService.new(project, current_user).execute(name, upstream_branch.target)
result = CreateBranchService.new(project, current_user).execute(name, upstream_branch.target.sha)
if result[:status] == :error
errors << result[:message]
end
......@@ -73,16 +73,17 @@ module Projects
tags.each do |tag|
old_tag = old_tags[tag.name]
old_tag_target = old_tag ? old_tag.target : Gitlab::Git::BLANK_SHA
tag_target = tag.target.sha
old_tag_target = old_tag ? old_tag.target.sha : Gitlab::Git::BLANK_SHA
next if old_tag_target == tag.target
next if old_tag_target == tag_target
GitTagPushService.new(
project,
current_user,
{
oldrev: old_tag_target,
newrev: tag.target,
newrev: tag_target,
ref: "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}",
mirror_update: true
}
......
......@@ -1291,7 +1291,7 @@ describe Repository, models: true do
describe '#remote_tags' do
it 'gets the remote tags' do
masterrev = repository.find_branch('master').target
masterrev = repository.find_branch('master').target.id
expect_any_instance_of(Gitlab::Shell).to receive(:list_remote_tags).
with(repository.storage_path, repository.path_with_namespace, 'upstream').
......@@ -1301,7 +1301,7 @@ describe Repository, models: true do
expect(tags.first).to be_an_instance_of(Gitlab::Git::Tag)
expect(tags.first.name).to eq('v0.0.1')
expect(tags.first.target).to eq(masterrev)
expect(tags.first.target.id).to eq(masterrev)
end
end
......@@ -1368,7 +1368,7 @@ describe Repository, models: true do
def create_remote_branch(remote_name, branch_name, target)
rugged = repository.rugged
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target)
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target.id)
end
end
......@@ -93,7 +93,7 @@ describe Projects::UpdateMirrorService do
def fetch_mirror(repository)
rugged = repository.rugged
masterrev = repository.find_branch('master').target
masterrev = repository.find_branch('master').target.id
parentrev = repository.commit(masterrev).parent_id
rugged.references.create('refs/heads/existing-branch', parentrev)
......
......@@ -12,6 +12,10 @@ describe Projects::UpdateRemoteMirrorService do
before do
create_branch(repository, 'existing-branch')
allow(repository).to receive(:remote_tags) { generate_tags(repository, 'v1.0.0', 'v1.1.0') }
gitlab_shell = Gitlab::Shell.new
allow(repository).to receive(:gitlab_shell).and_return(gitlab_shell)
allow(gitlab_shell).to receive(:push_remote_branches).and_return(true)
end
it "fetches the remote repository" do
......@@ -123,7 +127,7 @@ describe Projects::UpdateRemoteMirrorService do
def create_branch(repository, branch_name)
rugged = repository.rugged
masterrev = repository.find_branch('master').target
masterrev = repository.find_branch('master').target.id
parentrev = repository.commit(masterrev).parent_id
rugged.references.create("refs/heads/#{branch_name}", parentrev)
......@@ -136,13 +140,13 @@ describe Projects::UpdateRemoteMirrorService do
local_branch_names.each do |branch|
target = repository.find_branch(branch).try(:target)
rugged.references.create("refs/remotes/#{remote_name}/#{branch}", target) if target
rugged.references.create("refs/remotes/#{remote_name}/#{branch}", target.id) if target
end
end
def update_branch(repository, branch)
rugged = repository.rugged
masterrev = repository.find_branch('master').target
masterrev = repository.find_branch('master').target.id
# Updated existing branch
rugged.references.create("refs/heads/#{branch}", masterrev, force: true)
......@@ -158,8 +162,8 @@ describe Projects::UpdateRemoteMirrorService do
def generate_tags(repository, *tag_names)
tag_names.each_with_object([]) do |name, tags|
tag_rev = repository.find_tag(name).try(:target)
tags << Gitlab::Git::Tag.new(name, tag_rev)
target_commit = repository.find_tag(name).try(:target).try(:raw_commit)
tags << Gitlab::Git::Tag.new(repository.raw_repository, target_commit, name, target_commit)
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