Class: Hub::Context::LocalRepo
- Inherits:
-
Struct
- Object
- Struct
- Hub::Context::LocalRepo
- Extended by:
- Forwardable
- Includes:
- GitReaderMethods
- Defined in:
- lib/hub/context.rb
Constant Summary collapse
- ORIGIN_NAMES =
%w[ upstream github origin ]
Class Method Summary collapse
Instance Method Summary collapse
- #current_branch ⇒ Object
- #known_hosts ⇒ Object
- #main_project ⇒ Object
- #master_branch ⇒ Object
- #name ⇒ Object
- #origin_remote ⇒ Object
- #remote_branch_and_project(username_fetcher) ⇒ Object
- #remote_by_name(remote_name) ⇒ Object
- #remotes ⇒ Object
- #remotes_for_publish(owner_name) ⇒ Object
- #remotes_group(name) ⇒ Object
- #repo_host ⇒ Object
- #repo_owner ⇒ Object
- #ssh_config ⇒ Object
Methods included from GitReaderMethods
Class Method Details
.default_host ⇒ Object
205 206 207 |
# File 'lib/hub/context.rb', line 205 def self.default_host ENV['GITHUB_HOST'] || main_host end |
.main_host ⇒ Object
209 210 211 |
# File 'lib/hub/context.rb', line 209 def self.main_host 'github.com' end |
Instance Method Details
#current_branch ⇒ Object
153 154 155 156 157 |
# File 'lib/hub/context.rb', line 153 def current_branch if branch = git_command('symbolic-ref -q HEAD') Branch.new self, branch end end |
#known_hosts ⇒ Object
197 198 199 200 201 202 203 |
# File 'lib/hub/context.rb', line 197 def known_hosts hosts = git_config('hub.host', :all).to_s.split("\n") hosts << default_host # support ssh.github.com # https://help.github.com/articles/using-ssh-over-the-https-port hosts << "ssh.#{default_host}" end |
#main_project ⇒ Object
140 141 142 |
# File 'lib/hub/context.rb', line 140 def main_project remote = origin_remote and remote.project end |
#master_branch ⇒ Object
159 160 161 162 163 164 |
# File 'lib/hub/context.rb', line 159 def master_branch if remote = origin_remote default_branch = git_command("rev-parse --symbolic-full-name #{remote}") end Branch.new(self, default_branch || 'refs/heads/master') end |
#name ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/hub/context.rb', line 122 def name if project = main_project project.name else File.basename(dir) end end |
#origin_remote ⇒ Object
189 190 191 |
# File 'lib/hub/context.rb', line 189 def origin_remote remotes.first end |
#remote_branch_and_project(username_fetcher) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/hub/context.rb', line 144 def remote_branch_and_project(username_fetcher) project = main_project if project and branch = current_branch branch = branch.push_target(username_fetcher.call(project.host)) project = remote_by_name(branch.remote_name).project if branch && branch.remote? end [branch, project] end |
#remote_by_name(remote_name) ⇒ Object
193 194 195 |
# File 'lib/hub/context.rb', line 193 def remote_by_name(remote_name) remotes.find {|r| r.name == remote_name } end |
#remotes ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/hub/context.rb', line 168 def remotes @remotes ||= begin # TODO: is there a plumbing command to get a list of remotes? list = git_command('remote').to_s.split("\n") list = ORIGIN_NAMES.inject([]) { |sorted, name| sorted << list.delete(name) }.compact.concat(list) list.map { |name| Remote.new self, name } end end |
#remotes_for_publish(owner_name) ⇒ Object
179 180 181 182 183 |
# File 'lib/hub/context.rb', line 179 def remotes_for_publish(owner_name) list = ORIGIN_NAMES.map {|n| remote_by_name(n) } list << remotes.find {|r| p = r.project and p.owner == owner_name } list.compact.uniq.reverse end |
#remotes_group(name) ⇒ Object
185 186 187 |
# File 'lib/hub/context.rb', line 185 def remotes_group(name) git_config "remotes.#{name}" end |
#repo_host ⇒ Object
136 137 138 |
# File 'lib/hub/context.rb', line 136 def repo_host project = main_project and project.host end |
#repo_owner ⇒ Object
130 131 132 133 134 |
# File 'lib/hub/context.rb', line 130 def repo_owner if project = main_project project.owner end end |