Class: Envirobly::Git::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/envirobly/git/commit.rb

Direct Known Subclasses

Unstaged

Defined Under Namespace

Classes: OUTPUT

Instance Method Summary collapse

Constructor Details

#initialize(ref, working_dir: Dir.getwd) ⇒ Commit

Returns a new instance of Commit.



5
6
7
8
# File 'lib/envirobly/git/commit.rb', line 5

def initialize(ref, working_dir: Dir.getwd)
  @ref = ref
  @working_dir = working_dir
end

Instance Method Details

#archive_and_upload(bucket:, credentials:) ⇒ Object



44
45
46
# File 'lib/envirobly/git/commit.rb', line 44

def archive_and_upload(bucket:, credentials:)
  git(%(archive --format=tar.gz #{ref} | #{credentials.as_inline_env_vars} aws s3 cp - #{archive_uri(bucket)}))
end

#dir_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/envirobly/git/commit.rb', line 30

def dir_exists?(path)
  suffix = path.end_with?("/") ? nil : "/"
  git(%(cat-file -t #{@ref}:#{path}#{suffix})).stdout.strip == "tree"
end

#exists?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/envirobly/git/commit.rb', line 10

def exists?
  git(%(cat-file -t #{@ref})).stdout.strip == "commit"
end

#file_content(path) ⇒ Object



35
36
37
# File 'lib/envirobly/git/commit.rb', line 35

def file_content(path)
  git(%(show #{@ref}:#{path})).stdout
end

#file_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/envirobly/git/commit.rb', line 26

def file_exists?(path)
  git(%(cat-file -t #{@ref}:#{path})).stdout.strip == "blob"
end

#messageObject



18
19
20
# File 'lib/envirobly/git/commit.rb', line 18

def message
  git(%(log #{@ref} -n1 --pretty=%B)).stdout.strip
end

#objects_with_checksum_at(path) ⇒ Object



39
40
41
42
# File 'lib/envirobly/git/commit.rb', line 39

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

#refObject



14
15
16
# File 'lib/envirobly/git/commit.rb', line 14

def ref
  @normalized_ref ||= git(%(rev-parse #{@ref})).stdout.strip
end

#timeObject



22
23
24
# File 'lib/envirobly/git/commit.rb', line 22

def time
  Time.parse git(%(log #{@ref} -n1 --date=iso --pretty=format:"%ad")).stdout
end