Class: Hub::Context::LocalRepo

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Includes:
GitReaderMethods
Defined in:
lib/hub/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GitReaderMethods

extended

Class Method Details

.default_hostObject



182
183
184
# File 'lib/hub/context.rb', line 182

def self.default_host
  ENV['GITHUB_HOST'] || main_host
end

.main_hostObject



186
187
188
# File 'lib/hub/context.rb', line 186

def self.main_host
  'github.com'
end

Instance Method Details

#current_branchObject



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_projectObject



142
143
144
# File 'lib/hub/context.rb', line 142

def current_project
  upstream_project || main_project
end

#known_hostsObject



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_projectObject



131
132
133
# File 'lib/hub/context.rb', line 131

def main_project
  remote = origin_remote and remote.project
end

#master_branchObject



152
153
154
# File 'lib/hub/context.rb', line 152

def master_branch
  Branch.new self, 'refs/heads/master'
end

#nameObject



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_remoteObject



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

#remotesObject



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_hostObject



127
128
129
# File 'lib/hub/context.rb', line 127

def repo_host
  project = main_project and project.host
end

#repo_ownerObject



121
122
123
124
125
# File 'lib/hub/context.rb', line 121

def repo_owner
  if project = main_project
    project.owner
  end
end

#ssh_configObject



193
194
195
# File 'lib/hub/context.rb', line 193

def ssh_config
  @ssh_config ||= SshConfig.new
end

#upstream_projectObject



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