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 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
-
#initialize(connection) ⇒ Repo
constructor
A new instance of Repo.
- #location ⇒ Object
- #native_commit(sha) ⇒ Object
- #read_file(file_path, options = {}) ⇒ Object
- #ref(ref) ⇒ Object
- #refresh!(async: false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(connection) ⇒ Repo
Returns a new instance of Repo.
10 11 12 13 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 10 def initialize(connection) @connection = connection @branch_location = :local end |
Instance Method Details
#all_commit_times ⇒ Object
Public API for a VersionControl::Adapter Repo ————————————————————————- #
20 21 22 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 20 def all_commit_times `git --git-dir=#{git_dir} log --all --pretty='%at'`.split(/\n/).uniq end |
#all_commits ⇒ Object
24 25 26 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 24 def all_commits `git --git-dir=#{git_dir} log --all --pretty='%H'`.split(/\n/).uniq end |
#ancestors(sha, options = {}) ⇒ Object
28 29 30 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 28 def ancestors(sha, ={}) ancestor_walker(sha, , &method(:to_commit)) end |
#ancestors_until(sha, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 32 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
102 103 104 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 102 def branch(branch) ref("refs/remotes/origin/#{branch}") || ref("refs/heads/#{branch}") end |
#branches ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 43 def branches Hash[connection.branches .each(branch_location) .map { |branch| [name_of_branch(branch), branch.target.oid] }] ensure release end |
#branches_at(sha) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 51 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
127 128 129 130 131 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 127 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
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 60 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
94 95 96 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 94 def exists? File.exists?(connection.path) end |
#find_file(file_path, options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 111 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 |
#location ⇒ Object
73 74 75 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 73 def location connection.path end |
#native_commit(sha) ⇒ Object
77 78 79 80 81 82 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 77 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
84 85 86 87 88 89 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 84 def read_file(file_path, ={}) blob = find_file(file_path, ={}) blob && blob.content ensure release end |
#ref(ref) ⇒ Object
106 107 108 109 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 106 def ref(ref) ref = connection.ref(ref) ref.target.oid if ref end |
#refresh!(async: false) ⇒ Object
91 92 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 91 def refresh!(async: false) end |
#to_s ⇒ Object
133 134 135 |
# File 'app/adapters/houston/adapters/version_control/git_adapter/repo.rb', line 133 def to_s location end |