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, prefer_upstream = false) ⇒ Object
- #remote? ⇒ Boolean
- #remote_name ⇒ Object
- #short_name ⇒ Object
- #upstream ⇒ Object
Instance Method Details
#master? ⇒ Boolean
350 351 352 353 354 355 |
# File 'lib/hub/context.rb', line 350 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, prefer_upstream = false) ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/hub/context.rb', line 364 def push_target(owner_name, prefer_upstream = false) 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}" } refs.reverse! if prefer_upstream if branch = refs.detect {|ref| local_repo.file_exist?(ref) } Branch.new(local_repo, branch) end end end |
#remote? ⇒ Boolean
380 381 382 |
# File 'lib/hub/context.rb', line 380 def remote? name.index('refs/remotes/') == 0 end |
#remote_name ⇒ Object
384 385 386 387 |
# File 'lib/hub/context.rb', line 384 def remote_name name =~ %r{^refs/remotes/([^/]+)} and $1 or raise Error, "can't get remote name from #{name.inspect}" end |
#short_name ⇒ Object
346 347 348 |
# File 'lib/hub/context.rb', line 346 def short_name name.sub(%r{^refs/(remotes/)?.+?/}, '') end |
#upstream ⇒ Object
357 358 359 360 361 362 |
# File 'lib/hub/context.rb', line 357 def upstream escaped_name = short_name.gsub("'", "\\'") if branch = local_repo.git_command("rev-parse --symbolic-full-name '#{escaped_name}@{upstream}'") Branch.new local_repo, branch end end |