Class: Envirobly::Git::Commit
- Inherits:
-
Envirobly::Git
- Object
- Envirobly::Git
- Envirobly::Git::Commit
- Defined in:
- lib/envirobly/git/commit.rb
Direct Known Subclasses
Constant Summary collapse
- EXECUTABLE_FILE_MODE =
"100755"- SYMLINK_FILE_MODE =
"120000"
Instance Attribute Summary collapse
-
#working_dir ⇒ Object
readonly
Returns the value of attribute working_dir.
Instance Method Summary collapse
- #dir_exists?(path) ⇒ Boolean
- #exists? ⇒ Boolean
- #file_content(path) ⇒ Object
- #file_exists?(path) ⇒ Boolean
-
#initialize(ref, working_dir: Dir.getwd) ⇒ Commit
constructor
A new instance of Commit.
- #message ⇒ Object
- #object_tree(ref: @ref, chdir: @working_dir) ⇒ Object
- #object_tree_checksum ⇒ Object
- #objects_with_checksum_at(path) ⇒ Object deprecated Deprecated.
- #ref ⇒ Object
- #short_ref ⇒ Object
- #time ⇒ Object
Methods inherited from Envirobly::Git
Constructor Details
#initialize(ref, working_dir: Dir.getwd) ⇒ Commit
Returns a new instance of Commit.
10 11 12 13 |
# File 'lib/envirobly/git/commit.rb', line 10 def initialize(ref, working_dir: Dir.getwd) @ref = ref super working_dir end |
Instance Attribute Details
#working_dir ⇒ Object (readonly)
Returns the value of attribute working_dir.
8 9 10 |
# File 'lib/envirobly/git/commit.rb', line 8 def working_dir @working_dir end |
Instance Method Details
#dir_exists?(path) ⇒ Boolean
39 40 41 42 |
# File 'lib/envirobly/git/commit.rb', line 39 def dir_exists?(path) suffix = path.end_with?("/") ? nil : "/" git(%(cat-file -t #{@ref}:#{path}#{suffix})).stdout.strip == "tree" end |
#exists? ⇒ Boolean
15 16 17 |
# File 'lib/envirobly/git/commit.rb', line 15 def exists? git(%(cat-file -t #{@ref})).stdout.strip == "commit" end |
#file_content(path) ⇒ Object
44 45 46 |
# File 'lib/envirobly/git/commit.rb', line 44 def file_content(path) git(%(show #{@ref}:#{path})).stdout end |
#file_exists?(path) ⇒ Boolean
35 36 37 |
# File 'lib/envirobly/git/commit.rb', line 35 def file_exists?(path) git(%(cat-file -t #{@ref}:#{path})).stdout.strip == "blob" end |
#message ⇒ Object
27 28 29 |
# File 'lib/envirobly/git/commit.rb', line 27 def git(%(log #{@ref} -n1 --pretty=%B)).stdout.strip end |
#object_tree(ref: @ref, chdir: @working_dir) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/envirobly/git/commit.rb', line 48 def object_tree(ref: @ref, chdir: @working_dir) @object_tree ||= begin objects = {} objects[chdir] = [] git(%(ls-tree -r #{ref}), chdir:).stdout.lines.each do |line| mode, type, object_hash, path = line.split(/\s+/) next if path.start_with?("#{Envirobly::Configs::DIR}/") if type == "commit" objects.merge! object_tree(ref: object_hash, chdir: File.join(chdir, path)) else objects[chdir] << [ mode, type, object_hash, path ] end end objects end end |
#object_tree_checksum ⇒ Object
69 70 71 72 |
# File 'lib/envirobly/git/commit.rb', line 69 def object_tree_checksum digestable = object_tree.values.flatten.to_json @object_tree_checksum ||= Digest::SHA256.hexdigest(digestable) end |
#objects_with_checksum_at(path) ⇒ Object
Deprecated.
75 76 77 78 |
# File 'lib/envirobly/git/commit.rb', line 75 def objects_with_checksum_at(path) git(%{ls-tree #{@ref} --format='%(objectname) %(path)' #{path}}).stdout.lines.map(&:chomp). reject { _1.split(" ").last == Envirobly::Configs::DIR } end |
#ref ⇒ Object
19 20 21 |
# File 'lib/envirobly/git/commit.rb', line 19 def ref @normalized_ref ||= git(%(rev-parse #{@ref})).stdout.strip end |
#short_ref ⇒ Object
23 24 25 |
# File 'lib/envirobly/git/commit.rb', line 23 def short_ref @short_ref ||= ref[0..6] end |