Class: Hub::Context::Branch
- Inherits:
-
Struct
- Object
- Struct
- Hub::Context::Branch
- Defined in:
- lib/hub/context.rb
Instance Method Summary collapse
- #master? ⇒ Boolean
- #push_target(owner_name) ⇒ Object
- #remote? ⇒ Boolean
- #remote_name ⇒ Object
- #short_name ⇒ Object
- #upstream ⇒ Object
Instance Method Details
#master? ⇒ Boolean
316 317 318 319 320 321 |
# File 'lib/hub/context.rb', line 316 def master? master_name = if local_repo then local_repo.master_branch.short_name else 'master' end short_name == master_name end |
#push_target(owner_name) ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/hub/context.rb', line 329 def push_target(owner_name) push_default = local_repo.git_config('push.default') if %w[upstream tracking].include?(push_default) upstream else short = short_name refs = local_repo.remotes_for_publish(owner_name).map { |remote| "refs/remotes/#{remote}/#{short}" } if branch = refs.detect {|ref| local_repo.git_command("rev-parse -q --verify #{ref}") } Branch.new(local_repo, branch) end end end |
#remote? ⇒ Boolean
344 345 346 |
# File 'lib/hub/context.rb', line 344 def remote? name.index('refs/remotes/') == 0 end |
#remote_name ⇒ Object
348 349 350 351 |
# File 'lib/hub/context.rb', line 348 def remote_name name =~ %r{^refs/remotes/([^/]+)} and $1 or raise Error, "can't get remote name from #{name.inspect}" end |
#short_name ⇒ Object
312 313 314 |
# File 'lib/hub/context.rb', line 312 def short_name name.sub(%r{^refs/(remotes/)?.+?/}, '') end |
#upstream ⇒ Object
323 324 325 326 327 |
# File 'lib/hub/context.rb', line 323 def upstream if branch = local_repo.git_command("rev-parse --symbolic-full-name #{short_name}@{upstream}") Branch.new local_repo, branch end end |