Skip to content

Commit 7da9fa0

Browse files
committed
rebase to main
1 parent 639b7e4 commit 7da9fa0

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

lib/r10k/git/rugged/working_repository.rb

+21-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def fetch(remote_name = 'origin')
9090
proxy = R10K::Git.get_proxy_for_remote(remote)
9191

9292
options = {:credentials => credentials, :proxy_url => proxy, :prune => true}
93-
refspecs = ["+refs/heads/*:refs/remotes/#{remote_name}/*"]
93+
refspecs = ["+refs/heads/*:refs/remotes/#{remote_name}/*", '+refs/tags/*:refs/tags/*']
9494

9595
results = nil
9696

@@ -136,6 +136,26 @@ def dirty?(exclude_spec=true)
136136
end
137137
end
138138

139+
def updatedtags?
140+
with_repo do |repo|
141+
localtags = repo.tags.each_name.to_a
142+
143+
options = { :credentials => credentials }
144+
remote = repo.remotes['origin']
145+
remotetags = []
146+
remote.ls(**options) do |hash|
147+
if hash[:name].start_with?('refs/tags/') && !hash[:name].include?('^{}')
148+
remotetags << hash[:name].split('/').last
149+
end
150+
end
151+
152+
return false unless remotetags.sort != localtags.sort
153+
154+
logger.debug(_("Found different tags in local and remote in %{file_path}" % {file_path: @path}))
155+
return true
156+
end
157+
end
158+
139159
private
140160

141161
def with_repo

lib/r10k/git/shellgit/thin_repository.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def clone(remote, opts = {})
3131

3232
# Fetch refs from the backing bare Git repository.
3333
def fetch(remote = 'cache')
34-
git ['fetch', remote, '--prune'], :path => @path.to_s
34+
git ['fetch', remote, '--prune', '--tags', '--prune-tags'], :path => @path.to_s
35+
end
36+
37+
# Prune deleted branches
38+
def prune
39+
git ['fetch', '--prune'], :path => @path.to_s
3540
end
3641

3742
# @return [String] The origin remote URL

lib/r10k/git/shellgit/working_repository.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def fetch(remote_name='origin')
6464
proxy = R10K::Git.get_proxy_for_remote(remote)
6565

6666
R10K::Git.with_proxy(proxy) do
67-
git ['fetch', remote_name, '--prune'], :path => @path.to_s
67+
git ['fetch', remote_name, '--prune', '--tags', '--prune-tags'], :path => @path.to_s
6868
end
6969
end
7070

@@ -109,4 +109,15 @@ def dirty?(exclude_spec=true)
109109
return false
110110
end
111111
end
112+
113+
def updatedtags?
114+
result = git(['ls-remote', '--tags', '--refs', 'origin'], :path => @path.to_s, :raise_on_fail => false)
115+
remotetags = result.stdout.scan(/refs\/tags\/(\S+)$/).flatten
116+
result = git(['tag'], :path => @path.to_s, :raise_on_fail => false)
117+
localtags = result.stdout.scan(/(\S+)$/).flatten
118+
return false unless remotetags.sort != localtags.sort
119+
120+
logger.debug(_("Found different tags in local and remote in %{file_path}" % {file_path: @path}))
121+
return true
122+
end
112123
end

lib/r10k/git/stateful_repository.rb

+7
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ def sync(ref, force=true, exclude_spec=true)
6363
if force
6464
logger.warn(_("Overwriting local modifications to %{repo_path}") % {repo_path: @repo.path})
6565
logger.debug(_("Updating %{repo_path} to %{ref}") % {repo_path: @repo.path, ref: ref })
66+
@repo.prune
67+
@repo.fetch
6668
@repo.checkout(sha, {:force => force})
6769
else
6870
logger.warn(_("Skipping %{repo_path} due to local modifications") % {repo_path: @repo.path})
6971
updated = false
7072
end
73+
when :updatedtags
74+
logger.debug(_("Updating tags in %{repo_path}") % {repo_path: @repo.path})
75+
@repo.fetch
7176
else
7277
logger.debug(_("%{repo_path} is already at Git ref %{ref}") % {repo_path: @repo.path, ref: ref })
7378
updated = false
@@ -94,6 +99,8 @@ def status(ref, exclude_spec=true)
9499
:outdated
95100
elsif @cache.ref_type(ref) == :branch && !@cache.synced?
96101
:outdated
102+
elsif @repo.updatedtags?
103+
:updatedtags
97104
else
98105
:insync
99106
end

spec/shared-examples/git/working_repository.rb

+39
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,43 @@
206206
end
207207
end
208208
end
209+
210+
shared_examples "unequal tags" do
211+
it "reports tags as unequal" do
212+
expect(subject.logger).to receive(:debug).with(/found different tags in local and remote in/i)
213+
expect(subject.updatedtags?).to be true
214+
end
215+
end
216+
217+
describe "checking if tags are different" do
218+
let(:tag_090) { subject.git_dir + 'refs' + 'tags' + '0.9.0' }
219+
let(:packed_refs) { subject.git_dir + 'packed-refs' }
220+
221+
before(:each) do
222+
subject.clone(remote)
223+
end
224+
225+
context "with equal tags local and remote" do
226+
it "reports tags as equal" do
227+
expect(subject.updatedtags?).to be false
228+
end
229+
end
230+
231+
context "with missing local tag" do
232+
before do
233+
tag_090.delete if tag_090.exist?
234+
packed_refs.delete if packed_refs.exist?
235+
end
236+
237+
it_behaves_like "unequal tags"
238+
end
239+
240+
context "with additional local tag" do
241+
before(:each) do
242+
File.open(File.join(subject.git_dir, 'packed-refs'), 'a') { |f| f.write('157011a4eaa27f1202a9d94335ee4876b26d377e refs/tags/1.0.2') }
243+
end
244+
245+
it_behaves_like "unequal tags"
246+
end
247+
end
209248
end

0 commit comments

Comments
 (0)