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(dimg, name) ⇒ Base

Returns a new instance of Base.



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

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

Instance Attribute Details

#dimgObject (readonly)

Returns the value of attribute dimg.



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

def dimg
  @dimg
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



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

def branch
  git_bare.head.name.sub(/^refs\/heads\//, '')
end

#cleanup!Object



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

def cleanup!
end

#commit_at(commit) ⇒ Object



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

def commit_at(commit)
  git_bare.lookup(commit).time.to_i
end

#container_pathObject



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

def container_path
  dimg.container_tmp_path "#{name}.git"
end

#git_bareObject



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

def git_bare
  @git_bare ||= Rugged::Repository.new(path, bare: true)
end

#latest_commit(branch) ⇒ Object



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

def latest_commit(branch)
  return git_bare.head.target_id if branch == 'HEAD'
  git_bare.branches[branch].target_id
end

#old_git_bare(command, **kwargs) ⇒ Object



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

def old_git_bare(command, **kwargs)
  old_git "--git-dir=#{path} #{command}", **kwargs
end

#pathObject



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

def path
  dimg.tmp_path("#{name}.git").to_s
end