rugged icon indicating copy to clipboard operation
rugged copied to clipboard

Stale Rugged::Config#each_key values if another process changes .git/config

Open stanhu opened this issue 6 years ago • 1 comments

This looks like a regression from libgit2 0.28.0, but I'm not sure yet if it's a Rugged issue or a libgit2 one. Here's a sample reproduction:

require 'rugged'

repo = Rugged::Repository.new('.')
start_values = repo.config.each_key.to_a
system('git config --local core.foobar "asdf"')

new_values = repo.config.each_key.to_a
puts "Inserted value: #{repo.config['core.foobar']}"

system('git config --local --unset core.foobar')

puts start_values == new_values

With Rugged 0.27.5, I get:

Inserted value: asdf
false

With Rugged 0.28.0, I get:

Inserted value: asdf
true

What's curious is that the lookup works fine, but the each_key seems to be cached in the 0.28.0 case.

@pks-t @carlosmn I think this has to do with the in-memory config backend in https://github.com/libgit2/libgit2/pull/4767.

stanhu avatar Feb 28 '19 21:02 stanhu

What's even weirder is that if I do a lookup before running repo.config.each_key, the cache seems to get flushed. This returns the right result for 0.28.0:

require 'rugged'

repo = Rugged::Repository.new('.')
start_values = repo.config.each_key.to_a
system('git config --local core.foobar "asdf"')

# Do a lookup before each_key is called
puts "Inserted value: #{repo.config['core.foobar']}"
new_values = repo.config.each_key.to_a

system('git config --local --unset core.foobar')

puts start_values == new_values

stanhu avatar Feb 28 '19 22:02 stanhu