Class: Dapp::Dimg::GitRepo::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dapp/dimg/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.



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

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

Instance Attribute Details

#dimgObject (readonly)

Returns the value of attribute dimg.



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

def dimg
  @dimg
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#branchObject



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

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

#commit_at(commit) ⇒ Object



44
45
46
# File 'lib/dapp/dimg/git_repo/base.rb', line 44

def commit_at(commit)
  lookup_commit(commit).time.to_i
end

#commit_exists?(commit) ⇒ Boolean

Returns:

  • (Boolean)


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

def commit_exists?(commit)
  git.exists?(commit)
end

#diff(from, to, **kwargs) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/dapp/dimg/git_repo/base.rb', line 24

def diff(from, to, **kwargs)
  if from.nil?
    Rugged::Tree.diff(git, nil, to, **kwargs)
  else
    lookup_commit(from).diff(lookup_commit(to), **kwargs)
  end
end

#exclude_pathsObject



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

def exclude_paths
  []
end

#find_commit_id_by_message(regex) ⇒ Object



48
49
50
51
52
53
# File 'lib/dapp/dimg/git_repo/base.rb', line 48

def find_commit_id_by_message(regex)
  walker.each do |commit|
    next unless commit.message =~ regex
    return commit.oid
  end
end

#latest_commit(_branch) ⇒ Object



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

def latest_commit(_branch)
  raise
end

#lookup_commit(commit) ⇒ Object



65
66
67
# File 'lib/dapp/dimg/git_repo/base.rb', line 65

def lookup_commit(commit)
  git.lookup(commit)
end

#lookup_object(oid) ⇒ Object



61
62
63
# File 'lib/dapp/dimg/git_repo/base.rb', line 61

def lookup_object(oid)
  git.lookup(oid)
end

#patches(from, to, exclude_paths: [], **kwargs) ⇒ Object



18
19
20
21
22
# File 'lib/dapp/dimg/git_repo/base.rb', line 18

def patches(from, to, exclude_paths: [], **kwargs)
  diff(from, to, **kwargs).patches.select do |patch|
    !exclude_paths.any? { |p| check_path?(patch.delta.new_file[:path], p) }
  end
end

#walkerObject



55
56
57
58
59
# File 'lib/dapp/dimg/git_repo/base.rb', line 55

def walker
  walker = Rugged::Walker.new(git)
  walker.push(git.head.target_id)
  walker
end