Class: Houston::Adapters::VersionControl::GitAdapter::Repo
- Inherits:
-
Object
- Object
- Houston::Adapters::VersionControl::GitAdapter::Repo
- Defined in:
- app/adapters/houston/adapters/version_control/git_adapter/repo.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
-
#all_commit_times ⇒ Object
Public API for a VersionControl::Adapter Repo ————————————————————————- #.
- #all_commits ⇒ Object
- #ancestors(sha, options = {}) ⇒ Object
- #ancestors_until(sha, options = {}) ⇒ Object
- #branch(branch) ⇒ Object
- #branches ⇒ Object
- #branches_at(sha) ⇒ Object
- #changes(old_sha, new_sha) ⇒ Object
- #commits_between(sha1, sha2) ⇒ Object
- #exists? ⇒ Boolean
- #find_file(file_path, options = {}) ⇒ Object
- #git_path ⇒ Object
-
#initialize(location) ⇒ Repo
constructor
A new instance of Repo.
- #native_commit(sha) ⇒ Object
- #read_file(file_path, options = {}) ⇒ Object
- #ref(ref) ⇒ Object
- #refresh!(async: false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(location) ⇒ Repo
Returns a new instance of Repo.
12 13 14 15 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 12 def initialize(location) @location = location.to_s @branch_location = :local end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
8 9 10 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 8 def location @location end |
Instance Method Details
#all_commit_times ⇒ Object
Public API for a VersionControl::Adapter Repo ————————————————————————- #
22 23 24 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 22 def all_commit_times `git --git-dir=#{git_dir} log --all --pretty='%at'`.split(/\n/).uniq end |
#all_commits ⇒ Object
26 27 28 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 26 def all_commits `git --git-dir=#{git_dir} log --all --pretty='%H'`.split(/\n/).uniq end |
#ancestors(sha, options = {}) ⇒ Object
30 31 32 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 30 def ancestors(sha, ={}) ancestor_walker(sha, , &method(:to_commit)) end |
#ancestors_until(sha, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 34 def ancestors_until(sha, ={}) commits = [] ancestor_walker(sha, ) do |commit| commit = to_commit(commit) commits << commit return commits if yield commit end raise CommitNotFound, "No matching ancestor of \"#{sha}\" was found" end |
#branch(branch) ⇒ Object
100 101 102 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 100 def branch(branch) ref("refs/remotes/origin/#{branch}") || ref("refs/heads/#{branch}") end |
#branches ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 45 def branches Hash[connection.branches .each(branch_location) .map { |branch| [name_of_branch(branch), branch.target.oid] }] ensure release end |
#branches_at(sha) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 53 def branches_at(sha) connection.branches .each(branch_location) .select { |branch| branch.target.oid.start_with?(sha) } .map { |branch| name_of_branch(branch) } ensure release end |
#changes(old_sha, new_sha) ⇒ Object
125 126 127 128 129 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 125 def changes(old_sha, new_sha) find_commit old_sha find_commit new_sha DiffChanges.new `git --git-dir=#{git_dir} diff --name-status #{old_sha} #{new_sha}` end |
#commits_between(sha1, sha2) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 62 def commits_between(sha1, sha2) sha1 = sha1.sha if sha1.respond_to?(:sha) sha2 = sha2.sha if sha2.respond_to?(:sha) sha1 = nil if sha1 == Houston::NULL_GIT_COMMIT ancestors(sha2, including_self: true, hide: sha1).reverse rescue $!.additional_information[:repo] = to_s $!.additional_information[:commit_range] = "#{sha1}...#{sha2}" raise end |
#exists? ⇒ Boolean
92 93 94 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 92 def exists? File.exists?(git_path) end |
#find_file(file_path, options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 109 def find_file(file_path, ={}) commit = [:commit] || connection.head.target.oid head = find_commit(commit) tree = head.tree file_path.split("/").each do |segment| object = tree[segment] return nil unless object tree = connection.lookup object[:oid] end tree rescue Rugged::OdbError, Rugged::ReferenceError raise FileNotFound, "\"#{file_path}\" is not in the repo #{to_s}" ensure release end |
#git_path ⇒ Object
131 132 133 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 131 def git_path location end |
#native_commit(sha) ⇒ Object
75 76 77 78 79 80 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 75 def native_commit(sha) return NullCommit.new if sha == Houston::NULL_GIT_COMMIT to_commit find_commit(sha) ensure release end |
#read_file(file_path, options = {}) ⇒ Object
82 83 84 85 86 87 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 82 def read_file(file_path, ={}) blob = find_file(file_path, ={}) blob && blob.content ensure release end |
#ref(ref) ⇒ Object
104 105 106 107 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 104 def ref(ref) ref = connection.ref(ref) ref.target.oid if ref end |
#refresh!(async: false) ⇒ Object
89 90 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 89 def refresh!(async: false) end |
#to_s ⇒ Object
135 136 137 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 135 def to_s location end |