class GitCompound::Repository::GitRepository

Git repository base class

Public Class Methods

new(source) click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 6
def initialize(source)
  @source = source
end

Public Instance Methods

branch?(branch) click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 43
def branch?(branch)
  matching = refs.select { |refs| refs.include?(branch.to_s) }
  matching.any?
end
branches() click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 28
def branches
  refs_select('heads')
end
clone(destination, options = nil, source = @source) click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 10
def clone(destination, options = nil, source = @source)
  args = "#{source} #{destination}"
  args.prepend(options + ' ') if options
  GitCommand.new(:clone, args).execute
end
file_contents(_file, _ref) click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 62
def file_contents(_file, _ref)
  raise NotImplementedError
end
file_exists?(_file, _ref) click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 66
def file_exists?(_file, _ref)
  raise NotImplementedError
end
files_contents(files, ref) click to toggle source

Returns contents of first file found

# File lib/git_compound/repository/git_repository.rb, line 50
def files_contents(files, ref)
  files.each do |file|
    begin
      return file_contents(file, ref)
    rescue FileNotFoundError
      next
    end
  end
  raise FileNotFoundError,
        "Couldn't find any of #{files} files"
end
refs() click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 21
def refs
  @refs ||= GitCommand.new('ls-remote', @source).execute
  @refs.scan(%r{^(\b[0-9a-f]{5,40}\b)\srefs\/(heads|tags)\/(.+)})
rescue GitCommandError => e
  raise RepositoryUnreachableError, "Could not reach repository: #{e.message}"
end
tags() click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 32
def tags
  all = refs_select('tags')
  annotated = all.select { |tag, _| tag =~ /\^\{\}$/ }
  annotated.each_pair do |annotated_tag, annotated_tag_sha|
    tag = annotated_tag.sub(/\^\{\}$/, '')
    all.delete(annotated_tag)
    all[tag] = annotated_tag_sha
  end
  all
end
versions() click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 16
def versions
  git_versions = tags.map { |tag, sha| GitVersion.new(tag, sha) }
  git_versions.select(&:valid?)
end

Private Instance Methods

refs_select(name) click to toggle source
# File lib/git_compound/repository/git_repository.rb, line 72
def refs_select(name)
  selected_refs = refs.select { |ref| ref[1] == name }
  selected_refs.collect! { |r| [r.last, r.first] }
  Hash[selected_refs]
end