Class: Hub::Context::LocalRepo
- Inherits:
-
Struct
- Object
- Struct
- Hub::Context::LocalRepo
- Extended by:
- Forwardable
- Includes:
- GitReaderMethods
- Defined in:
- lib/hub/context.rb
Class Method Summary collapse
Instance Method Summary collapse
- #current_branch ⇒ Object
- #current_project ⇒ Object
- #known_hosts ⇒ Object
- #main_project ⇒ Object
- #master_branch ⇒ Object
- #name ⇒ Object
- #origin_remote ⇒ Object
- #remote_by_name(remote_name) ⇒ Object
- #remotes ⇒ Object
- #remotes_group(name) ⇒ Object
- #repo_host ⇒ Object
- #repo_owner ⇒ Object
- #ssh_config ⇒ Object
- #upstream_project ⇒ Object
Methods included from GitReaderMethods
Class Method Details
.default_host ⇒ Object
195 196 197 |
# File 'lib/hub/context.rb', line 195 def self.default_host ENV['GITHUB_HOST'] || main_host end |
.main_host ⇒ Object
199 200 201 |
# File 'lib/hub/context.rb', line 199 def self.main_host 'github.com' end |
Instance Method Details
#current_branch ⇒ Object
155 156 157 158 159 |
# File 'lib/hub/context.rb', line 155 def current_branch if branch = git_command('symbolic-ref -q HEAD') Branch.new self, branch end end |
#current_project ⇒ Object
151 152 153 |
# File 'lib/hub/context.rb', line 151 def current_project upstream_project || main_project end |
#known_hosts ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/hub/context.rb', line 187 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
161 162 163 |
# File 'lib/hub/context.rb', line 161 def master_branch Branch.new self, '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
179 180 181 |
# File 'lib/hub/context.rb', line 179 def origin_remote remotes.first end |
#remote_by_name(remote_name) ⇒ Object
183 184 185 |
# File 'lib/hub/context.rb', line 183 def remote_by_name(remote_name) remotes.find {|r| r.name == remote_name } end |
#remotes ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/hub/context.rb', line 165 def remotes @remotes ||= begin # TODO: is there a plumbing command to get a list of remotes? list = git_command('remote').to_s.split("\n") # force "origin" to be first in the list main = list.delete('origin') and list.unshift(main) list.map { |name| Remote.new self, name } end end |
#remotes_group(name) ⇒ Object
175 176 177 |
# File 'lib/hub/context.rb', line 175 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 |
#ssh_config ⇒ Object
206 207 208 |
# File 'lib/hub/context.rb', line 206 def ssh_config @ssh_config ||= SshConfig.new end |
#upstream_project ⇒ Object
144 145 146 147 148 149 |
# File 'lib/hub/context.rb', line 144 def upstream_project if branch = current_branch and upstream = branch.upstream and upstream.remote? remote = remote_by_name upstream.remote_name remote.project end end |