Class: Dapp::Dimg::GitRepo::Base
- Inherits:
-
Object
- Object
- Dapp::Dimg::GitRepo::Base
- Defined in:
- lib/dapp/dimg/git_repo/base.rb
Overview
Base class for any Git repo (remote, gitkeeper, etc)
Instance Attribute Summary collapse
-
#dimg ⇒ Object
readonly
Returns the value of attribute dimg.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #branch ⇒ Object
- #commit_at(commit) ⇒ Object
- #commit_exists?(commit) ⇒ Boolean
- #diff(from, to, **kwargs) ⇒ Object
- #exclude_paths ⇒ Object
- #find_commit_id_by_message(regex) ⇒ Object
-
#initialize(dimg, name) ⇒ Base
constructor
A new instance of Base.
- #latest_commit(_branch) ⇒ Object
- #lookup_commit(commit) ⇒ Object
- #lookup_object(oid) ⇒ Object
- #patches(from, to, exclude_paths: [], **kwargs) ⇒ Object
- #walker ⇒ Object
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
#dimg ⇒ Object (readonly)
Returns the value of attribute dimg.
6 7 8 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 6 def dimg @dimg end |
#name ⇒ Object (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
#branch ⇒ Object
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
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_paths ⇒ Object
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 (regex) walker.each do |commit| next unless commit. =~ 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 |
#walker ⇒ Object
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 |