Class: Hub::Context::LocalRepo
- Inherits:
-
Struct
- Object
- Struct
- Hub::Context::LocalRepo
- Includes:
- GitReaderMethods
- Defined in:
- lib/hub/context.rb
Instance Method Summary collapse
- #current_branch ⇒ Object
- #current_project ⇒ 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_owner ⇒ Object
- #upstream_project ⇒ Object
Methods included from GitReaderMethods
Instance Method Details
#current_branch ⇒ Object
134 135 136 137 138 |
# File 'lib/hub/context.rb', line 134 def current_branch if branch = git_command('symbolic-ref -q HEAD') Branch.new self, branch end end |
#current_project ⇒ Object
130 131 132 |
# File 'lib/hub/context.rb', line 130 def current_project upstream_project || main_project end |
#main_project ⇒ Object
119 120 121 |
# File 'lib/hub/context.rb', line 119 def main_project remote = origin_remote and remote.project end |
#master_branch ⇒ Object
140 141 142 |
# File 'lib/hub/context.rb', line 140 def master_branch Branch.new self, 'refs/heads/master' end |
#name ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/hub/context.rb', line 105 def name if project = main_project project.name else File.basename(dir) end end |
#origin_remote ⇒ Object
158 159 160 |
# File 'lib/hub/context.rb', line 158 def origin_remote remotes.first end |
#remote_by_name(remote_name) ⇒ Object
162 163 164 |
# File 'lib/hub/context.rb', line 162 def remote_by_name(remote_name) remotes.find {|r| r.name == remote_name } end |
#remotes ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/hub/context.rb', line 144 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
154 155 156 |
# File 'lib/hub/context.rb', line 154 def remotes_group(name) git_config "remotes.#{name}" end |
#repo_owner ⇒ Object
113 114 115 116 117 |
# File 'lib/hub/context.rb', line 113 def repo_owner if project = main_project project.owner end end |
#upstream_project ⇒ Object
123 124 125 126 127 128 |
# File 'lib/hub/context.rb', line 123 def upstream_project if upstream = current_branch.upstream remote = remote_by_name upstream.remote_name remote.project end end |