class Hub::Context::LocalRepo

Constants

ORIGIN_NAMES

Public Class Methods

default_host() click to toggle source
# File lib/hub/context.rb, line 235
def self.default_host
  ENV['GITHUB_HOST'] || main_host
end
main_host() click to toggle source
# File lib/hub/context.rb, line 239
def self.main_host
  'github.com'
end

Public Instance Methods

branch_at_ref(*parts) click to toggle source
# File lib/hub/context.rb, line 168
def branch_at_ref(*parts)
  begin
    head = file_read(*parts)
  rescue Errno::ENOENT
    return nil
  else
    Branch.new(self, head.rstrip) if head.sub!('ref: ', '')
  end
end
current_branch() click to toggle source
# File lib/hub/context.rb, line 164
def current_branch
  @current_branch ||= branch_at_ref('HEAD')
end
file_exist?(*parts) click to toggle source
# File lib/hub/context.rb, line 182
def file_exist?(*parts)
  File.exist?(File.join(git_dir, *parts))
end
file_read(*parts) click to toggle source
# File lib/hub/context.rb, line 178
def file_read(*parts)
  File.read(File.join(git_dir, *parts))
end
known_host?(host) click to toggle source
# File lib/hub/context.rb, line 229
def known_host?(host)
  default = default_host
  default == host || "ssh.#{default}" == host ||
    git_config('hub.host', :all).to_s.split("\n").include?(host)
end
main_project() click to toggle source
# File lib/hub/context.rb, line 151
def main_project
  remote = origin_remote and remote.project
end
master_branch() click to toggle source
# File lib/hub/context.rb, line 186
def master_branch
  if remote = origin_remote
    default_branch = branch_at_ref("refs/remotes/#{remote}/HEAD")
  end
  default_branch || Branch.new(self, 'refs/heads/master')
end
name() click to toggle source
# File lib/hub/context.rb, line 133
def name
  if project = main_project
    project.name
  else
    File.basename(dir)
  end
end
origin_remote() click to toggle source
# File lib/hub/context.rb, line 221
def origin_remote
  remotes.detect {|r| r.urls.any? }
end
remote_branch_and_project(username_fetcher, prefer_upstream = false) click to toggle source
# File lib/hub/context.rb, line 155
def remote_branch_and_project(username_fetcher, prefer_upstream = false)
  project = main_project
  if project and branch = current_branch
    branch = branch.push_target(username_fetcher.call(project.host), prefer_upstream)
    project = remote_by_name(branch.remote_name).project if branch && branch.remote?
  end
  [branch, project]
end
remote_by_name(remote_name) click to toggle source
# File lib/hub/context.rb, line 225
def remote_by_name(remote_name)
  remotes.find {|r| r.name == remote_name }
end
remotes() click to toggle source
# File lib/hub/context.rb, line 195
def remotes
  @remotes ||= begin
    names = []
    url_memo = Hash.new {|h,k| names << k; h[k]=[] }
    git_command('remote -v').to_s.split("\n").map do |line|
      next if line !~ /^(.+?)\t(.+) \(/
      name, url = $1, $2
      url_memo[name] << url
    end
    ((ORIGIN_NAMES + names) & names).map do |name|
      urls = url_memo[name].uniq
      Remote.new(self, name, urls)
    end
  end
end
remotes_for_publish(owner_name) click to toggle source
# File lib/hub/context.rb, line 211
def remotes_for_publish(owner_name)
  list = ORIGIN_NAMES.map {|n| remote_by_name(n) }
  list << remotes.find {|r| p = r.project and p.owner == owner_name }
  list.compact.uniq.reverse
end
remotes_group(name) click to toggle source
# File lib/hub/context.rb, line 217
def remotes_group(name)
  git_config "remotes.#{name}"
end
repo_host() click to toggle source
# File lib/hub/context.rb, line 147
def repo_host
  project = main_project and project.host
end
repo_owner() click to toggle source
# File lib/hub/context.rb, line 141
def repo_owner
  if project = main_project
    project.owner
  end
end
ssh_config() click to toggle source
# File lib/hub/context.rb, line 246
def ssh_config
  @ssh_config ||= SshConfig.new
end