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
182 183 184 |
# File 'lib/hub/context.rb', line 182 def self.default_host ENV['GITHUB_HOST'] || main_host end |
.main_host ⇒ Object
186 187 188 |
# File 'lib/hub/context.rb', line 186 def self.main_host 'github.com' end |
Instance Method Details
#current_branch ⇒ Object
146 147 148 149 150 |
# File 'lib/hub/context.rb', line 146 def current_branch if branch = git_command('symbolic-ref -q HEAD') Branch.new self, branch end end |
#current_project ⇒ Object
142 143 144 |
# File 'lib/hub/context.rb', line 142 def current_project upstream_project || main_project end |
#known_hosts ⇒ Object
178 179 180 |
# File 'lib/hub/context.rb', line 178 def known_hosts git_config('hub.host', :all).to_s.split("\n") + [default_host] end |
#main_project ⇒ Object
131 132 133 |
# File 'lib/hub/context.rb', line 131 def main_project remote = origin_remote and remote.project end |
#master_branch ⇒ Object
152 153 154 |
# File 'lib/hub/context.rb', line 152 def master_branch Branch.new self, 'refs/heads/master' end |
#name ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/hub/context.rb', line 113 def name if project = main_project project.name else File.basename(dir) end end |
#origin_remote ⇒ Object
170 171 172 |
# File 'lib/hub/context.rb', line 170 def origin_remote remotes.first end |
#remote_by_name(remote_name) ⇒ Object
174 175 176 |
# File 'lib/hub/context.rb', line 174 def remote_by_name(remote_name) remotes.find {|r| r.name == remote_name } end |
#remotes ⇒ Object
156 157 158 159 160 161 162 163 164 |
# File 'lib/hub/context.rb', line 156 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
166 167 168 |
# File 'lib/hub/context.rb', line 166 def remotes_group(name) git_config "remotes.#{name}" end |
#repo_host ⇒ Object
127 128 129 |
# File 'lib/hub/context.rb', line 127 def repo_host project = main_project and project.host end |
#repo_owner ⇒ Object
121 122 123 124 125 |
# File 'lib/hub/context.rb', line 121 def repo_owner if project = main_project project.owner end end |
#ssh_config ⇒ Object
193 194 195 |
# File 'lib/hub/context.rb', line 193 def ssh_config @ssh_config ||= SshConfig.new end |
#upstream_project ⇒ Object
135 136 137 138 139 140 |
# File 'lib/hub/context.rb', line 135 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 |