Class: Dapp::GitRepo::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dapp/git_repo/base.rb

Overview

Base class for any Git repo (remote, gitkeeper, etc)

Direct Known Subclasses

Own, Remote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, name) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/dapp/git_repo/base.rb', line 8

def initialize(application, name)
  @application = application
  @name = name
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



5
6
7
# File 'lib/dapp/git_repo/base.rb', line 5

def application
  @application
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/dapp/git_repo/base.rb', line 6

def name
  @name
end

Instance Method Details

#branchObject



40
41
42
# File 'lib/dapp/git_repo/base.rb', line 40

def branch
  git_bare('rev-parse --abbrev-ref HEAD').stdout.strip
end

#cleanup!Object



37
38
# File 'lib/dapp/git_repo/base.rb', line 37

def cleanup!
end

#commit_at(commit) ⇒ Object



25
26
27
# File 'lib/dapp/git_repo/base.rb', line 25

def commit_at(commit)
  Time.at Integer git_bare("show -s --format=%ct #{commit}").stdout.strip
end

#container_build_dir_pathObject



13
14
15
# File 'lib/dapp/git_repo/base.rb', line 13

def container_build_dir_path
  application.container_build_path "#{name}.git"
end

#dir_pathObject



17
18
19
# File 'lib/dapp/git_repo/base.rb', line 17

def dir_path
  application.build_path "#{name}.git"
end

#exist_in_commit?(path, commit) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/dapp/git_repo/base.rb', line 33

def exist_in_commit?(path, commit)
  git_bare("cat-file -e #{commit}:#{path}", returns: [0, 128]).status.success?
end

#git_bare(command, **kwargs) ⇒ Object



21
22
23
# File 'lib/dapp/git_repo/base.rb', line 21

def git_bare(command, **kwargs)
  git "--git-dir=#{dir_path} #{command}", **kwargs
end

#latest_commit(branch) ⇒ Object



29
30
31
# File 'lib/dapp/git_repo/base.rb', line 29

def latest_commit(branch)
  git_bare("rev-parse #{branch}").stdout.strip
end