Module: Dockly::Util::Git
- Defined in:
- lib/dockly/util/git.rb
Class Method Summary collapse
Class Method Details
.archive(oid, prefix, output) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dockly/util/git.rb', line 27 def archive(oid, prefix, output) Gem::Package::TarWriter.new(output) do |tar| ls_files(oid).each do |blob| name, mode = blob.values_at(:name, :filemode) prefixed = File.join(prefix, name) tar.add_file(prefixed, mode) do |tar_out| tar_out.write(File.read(name)) end end end end |
.ls_files(oid) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dockly/util/git.rb', line 15 def ls_files(oid) target = repo.lookup(oid) target = target.target until target.type == :commit ary = [] target.tree.walk(:postorder) do |root, entry| next unless entry[:type] == :blob name = File.join(root, entry[:name]).gsub(/\A\//, '') ary << entry.merge(name: name) end ary end |
.repo ⇒ Object
4 5 6 |
# File 'lib/dockly/util/git.rb', line 4 def repo @repo ||= Rugged::Repository.discover('.') end |
.sha ⇒ Object
8 9 10 11 12 13 |
# File 'lib/dockly/util/git.rb', line 8 def sha return @sha if @sha @sha = repo.head.target.oid[0..6] rescue @sha = 'unknown' end |