Class: Hub::Context::LocalRepo

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

Instance Method Summary collapse

Methods included from GitReaderMethods

extended

Instance Method Details

#current_branchObject



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

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

#current_projectObject



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

def current_project
  upstream_project || main_project
end

#main_projectObject



119
120
121
# File 'lib/hub/context.rb', line 119

def main_project
  remote = origin_remote and remote.project
end

#master_branchObject



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

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

#nameObject



105
106
107
108
109
110
111
# File 'lib/hub/context.rb', line 105

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

#origin_remoteObject



158
159
160
# File 'lib/hub/context.rb', line 158

def origin_remote
  remotes.first
end

#remote_by_name(remote_name) ⇒ Object



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

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

#remotesObject



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

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



154
155
156
# File 'lib/hub/context.rb', line 154

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

#repo_ownerObject



113
114
115
116
117
# File 'lib/hub/context.rb', line 113

def repo_owner
  if project = main_project
    project.owner
  end
end

#upstream_projectObject



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

def upstream_project
  if upstream = current_branch.upstream
    remote = remote_by_name upstream.remote_name
    remote.project
  end
end