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.
12 13 14 15 |
# File 'lib/envirobly/git/commit.rb', line 12 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.
10 11 12 |
# File 'lib/envirobly/git/commit.rb', line 10 def working_dir @working_dir end |
Instance Method Details
#dir_exists?(path) ⇒ Boolean
41 42 43 44 |
# File 'lib/envirobly/git/commit.rb', line 41 def dir_exists?(path) suffix = path.end_with?("/") ? nil : "/" git(%(cat-file -t #{@ref}:#{path}#{suffix})).stdout.strip == "tree" end |
#exists? ⇒ Boolean
17 18 19 |
# File 'lib/envirobly/git/commit.rb', line 17 def exists? git(%(cat-file -t #{@ref})).stdout.strip == "commit" end |
#file_content(path) ⇒ Object
46 47 48 |
# File 'lib/envirobly/git/commit.rb', line 46 def file_content(path) git(%(show #{@ref}:#{path})).stdout end |
#file_exists?(path) ⇒ Boolean
37 38 39 |
# File 'lib/envirobly/git/commit.rb', line 37 def file_exists?(path) git(%(cat-file -t #{@ref}:#{path})).stdout.strip == "blob" end |
#message ⇒ Object
29 30 31 |
# File 'lib/envirobly/git/commit.rb', line 29 def git(%(log #{@ref} -n1 --pretty=%B)).stdout.strip end |
#object_tree(ref: @ref, chdir: @working_dir) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/envirobly/git/commit.rb', line 50 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::Config::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
71 72 73 74 |
# File 'lib/envirobly/git/commit.rb', line 71 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.
77 78 79 80 |
# File 'lib/envirobly/git/commit.rb', line 77 def objects_with_checksum_at(path) git(%{ls-tree #{@ref} --format='%(objectname) %(path)' #{path}}).stdout.lines.map(&:chomp). reject { _1.split(" ").last == Envirobly::Config::DIR } end |
#ref ⇒ Object
21 22 23 |
# File 'lib/envirobly/git/commit.rb', line 21 def ref @normalized_ref ||= git(%(rev-parse #{@ref})).stdout.strip end |
#short_ref ⇒ Object
25 26 27 |
# File 'lib/envirobly/git/commit.rb', line 25 def short_ref @short_ref ||= ref[0..6] end |
#time ⇒ Object
33 34 35 |
# File 'lib/envirobly/git/commit.rb', line 33 def time Time.parse git(%(log #{@ref} -n1 --date=iso --pretty=format:"%ad")).stdout end |