Commit 53da6aa9 authored by Douwe Maan's avatar Douwe Maan

Merge branch '21040-blob-as-tag' into 'master'

Fix Projects::UpdateMirrorService to allow tags pointing to blob objects

After the release of https://gitlab.com/gitlab-org/gitlab_git/merge_requests/103 we changed the way we return the target of tag objects, now it's a Commit object if there is some and nil in any other case, like when a tag points to a Blob object.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/21040

See merge request !673
parents 9d9ab015 05c65c3c
...@@ -15,6 +15,7 @@ v 8.11.0 (unreleased) ...@@ -15,6 +15,7 @@ v 8.11.0 (unreleased)
- [Elastic] Significant improvement of global search performance - [Elastic] Significant improvement of global search performance
- [Fix] Push rules check existing commits in some cases - [Fix] Push rules check existing commits in some cases
- [ES] Limit amount of retries for sidekiq jobs - [ES] Limit amount of retries for sidekiq jobs
- Fix Projects::UpdateMirrorService to allow tags pointing to blob objects
v 8.10.7 v 8.10.7
- No EE-specific changes - No EE-specific changes
......
...@@ -62,14 +62,14 @@ module Projects ...@@ -62,14 +62,14 @@ module Projects
end end
def update_tags(&block) def update_tags(&block)
old_tags = repository.tags.each_with_object({}) { |tag, tags| tags[tag.name] = tag } old_tags = repository_tags_with_target.each_with_object({}) { |tag, tags| tags[tag.name] = tag }
fetch_result = block.call fetch_result = block.call
return fetch_result unless fetch_result return fetch_result unless fetch_result
repository.expire_tags_cache repository.expire_tags_cache
tags = repository.tags tags = repository_tags_with_target
tags.each do |tag| tags.each do |tag|
old_tag = old_tags[tag.name] old_tag = old_tags[tag.name]
...@@ -92,5 +92,11 @@ module Projects ...@@ -92,5 +92,11 @@ module Projects
fetch_result fetch_result
end end
# In Git is possible to tag blob objects, and those blob objects don't point to a Git commit so those tags
# have no target.
def repository_tags_with_target
repository.tags.select(&:target)
end
end end
end end
...@@ -26,6 +26,15 @@ describe Projects::UpdateMirrorService do ...@@ -26,6 +26,15 @@ describe Projects::UpdateMirrorService do
expect(project.repository.tag_names).to include('new-tag') expect(project.repository.tag_names).to include('new-tag')
end end
it "only invokes GitTagPushService for tags pointing to commits" do
stub_fetch_mirror(project)
expect(GitTagPushService).to receive(:new).
with(project, project.owner, hash_including(ref: 'refs/tags/new-tag')).and_return(double(execute: true))
described_class.new(project, project.owner).execute
end
end end
describe "updating branches" do describe "updating branches" do
...@@ -112,5 +121,8 @@ describe Projects::UpdateMirrorService do ...@@ -112,5 +121,8 @@ describe Projects::UpdateMirrorService do
# New tag # New tag
rugged.references.create('refs/tags/new-tag', masterrev) rugged.references.create('refs/tags/new-tag', masterrev)
# New tag that point to a blob
rugged.references.create('refs/tags/new-tag-on-blob', 'c74175afd117781cbc983664339a0f599b5bb34e')
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