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
FIXME: Убрать логику исключения путей exclude_paths из данного класса, FIXME: т.к.
- #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
52 53 54 55 56 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 52 def branch git.head.name.sub(/^refs\/heads\//, '') rescue Rugged::ReferenceError => e raise Error::Rugged, code: :git_repository_reference_error, data: { name: name, message: e..downcase } end |
#commit_at(commit) ⇒ Object
58 59 60 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 58 def commit_at(commit) lookup_commit(commit).time.to_i end |
#commit_exists?(commit) ⇒ Boolean
44 45 46 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 44 def commit_exists?(commit) git.exists?(commit) end |
#diff(from, to, **kwargs) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 34 def diff(from, to, **kwargs) if to.nil? raise "Workdir diff not supported for #{self.class}" elsif 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
62 63 64 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 62 def (regex) walker.each { |commit| return commit.oid if commit..encode('UTF-8', invalid: :replace) =~ regex } end |
#latest_commit(_branch) ⇒ Object
48 49 50 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 48 def latest_commit(_branch) raise end |
#lookup_commit(commit) ⇒ Object
76 77 78 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 76 def lookup_commit(commit) git.lookup(commit) end |
#lookup_object(oid) ⇒ Object
72 73 74 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 72 def lookup_object(oid) git.lookup(oid) end |
#patches(from, to, exclude_paths: [], **kwargs) ⇒ Object
FIXME: Убрать логику исключения путей exclude_paths из данного класса, FIXME: т.к. большинство методов не поддерживают инвариант FIXME “всегда выдавать данные с исключенными путями”. FIXME: Например, метод diff выдает данные без учета exclude_paths. FIXME: Лучше перенести фильтрацию в GitArtifact::diff_patches. FIXME: ИЛИ обеспечить этот инвариант, но это ограничит в возможностях FIXME: использование Rugged извне этого класса и это более сложный путь. FIXME: Лучше сейчас убрать фильтрацию, а добавить ее когда наберется достаточно FIXME: примеров использования.
28 29 30 31 32 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 28 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
66 67 68 69 70 |
# File 'lib/dapp/dimg/git_repo/base.rb', line 66 def walker walker = Rugged::Walker.new(git) walker.push(git.head.target_id) walker end |