Class: PuppetLibrary::Util::Git
- Inherits:
-
Object
- Object
- PuppetLibrary::Util::Git
show all
- Includes:
- Logging
- Defined in:
- lib/puppet_library/util/git.rb
Defined Under Namespace
Classes: GitCommandError
Constant Summary
collapse
- DEFAULT_CACHE_TTL_SECONDS =
60
Instance Method Summary
collapse
Methods included from Logging
#debug, #info, #logger, #logs, #warn
Constructor Details
#initialize(source, cache_dir, cache_ttl_seconds = DEFAULT_CACHE_TTL_SECONDS) ⇒ Git
Returns a new instance of Git.
29
30
31
32
33
34
35
|
# File 'lib/puppet_library/util/git.rb', line 29
def initialize(source, cache_dir, cache_ttl_seconds = DEFAULT_CACHE_TTL_SECONDS)
@source = source
@cache_dir = cache_dir
@cache_ttl_seconds = cache_ttl_seconds
@git_dir = File.join(@cache_dir.path, ".git")
@mutex = Monitor.new
end
|
Instance Method Details
#clear_cache! ⇒ Object
62
63
64
65
66
67
|
# File 'lib/puppet_library/util/git.rb', line 62
def clear_cache!
@mutex.synchronize do
info "Clearing cache for Git repository #{@source} from #{@git_dir}"
FileUtils.rm_rf @cache_dir.path
end
end
|
#file_exists?(path, tag) ⇒ Boolean
55
56
57
58
59
60
|
# File 'lib/puppet_library/util/git.rb', line 55
def file_exists?(path, tag)
read_file(path, tag)
true
rescue GitCommandError
false
end
|
#read_file(path, tag) ⇒ Object
50
51
52
53
|
# File 'lib/puppet_library/util/git.rb', line 50
def read_file(path, tag)
update_cache!
git "show refs/tags/#{tag}:#{path}"
end
|
37
38
39
40
|
# File 'lib/puppet_library/util/git.rb', line 37
def tags
update_cache!
git("tag").split
end
|
#update_cache! ⇒ Object
69
70
71
72
|
# File 'lib/puppet_library/util/git.rb', line 69
def update_cache!
create_cache unless cache_exists?
update_cache if cache_stale?
end
|
#with_tag(tag) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/puppet_library/util/git.rb', line 42
def with_tag(tag)
update_cache!
PuppetLibrary::Util::TempDir.use "git" do |path|
git "checkout -f #{tag} .", path
yield(path)
end
end
|