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



195
196
197
# File 'lib/hub/context.rb', line 195

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

.main_hostObject



199
200
201
# File 'lib/hub/context.rb', line 199

def self.main_host
  'github.com'
end

Instance Method Details

#current_branchObject



155
156
157
158
159
# File 'lib/hub/context.rb', line 155

def current_branch
  if branch = git_command('symbolic-ref -q HEAD')
    Branch.new self, branch
  end
end

#current_projectObject



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

def current_project
  upstream_project || main_project
end

#known_hostsObject



187
188
189
190
191
192
193
# File 'lib/hub/context.rb', line 187

def known_hosts
  hosts = git_config('hub.host', :all).to_s.split("\n")
  hosts << default_host
  # support ssh.github.com
  # https://help.github.com/articles/using-ssh-over-the-https-port
  hosts << "ssh.#{default_host}"
end

#main_projectObject



140
141
142
# File 'lib/hub/context.rb', line 140

def main_project
  remote = origin_remote and remote.project
end

#master_branchObject



161
162
163
# File 'lib/hub/context.rb', line 161

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

#nameObject



122
123
124
125
126
127
128
# File 'lib/hub/context.rb', line 122

def name
  if project = main_project
    project.name
  else
    File.basename(dir)
  end
end

#origin_remoteObject



179
180
181
# File 'lib/hub/context.rb', line 179

def origin_remote
  remotes.first
end

#remote_by_name(remote_name) ⇒ Object



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

def remote_by_name(remote_name)
  remotes.find {|r| r.name == remote_name }
end

#remotesObject



165
166
167
168
169
170
171
172
173
# File 'lib/hub/context.rb', line 165

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



175
176
177
# File 'lib/hub/context.rb', line 175

def remotes_group(name)
  git_config "remotes.#{name}"
end

#repo_hostObject



136
137
138
# File 'lib/hub/context.rb', line 136

def repo_host
  project = main_project and project.host
end

#repo_ownerObject



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

def repo_owner
  if project = main_project
    project.owner
  end
end

#ssh_configObject



206
207
208
# File 'lib/hub/context.rb', line 206

def ssh_config
  @ssh_config ||= SshConfig.new
end

#upstream_projectObject



144
145
146
147
148
149
# File 'lib/hub/context.rb', line 144

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