Class: MultiGit::RuggedBackend::Repository

Inherits:
MultiGit::Repository show all
Extended by:
Forwardable
Defined in:
lib/multi_git/rugged_backend/repository.rb

Constant Summary collapse

TRUE_LAMBDA =
proc{ true }

Instance Method Summary collapse

Methods inherited from MultiGit::Repository

#bare?, #branch, #head, #tag

Methods included from Utils::AbstractMethods

#abstract

Constructor Details

#initialize(path, options = {}) ⇒ Repository

Returns a new instance of Repository.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/multi_git/rugged_backend/repository.rb', line 36

def initialize(path, options = {})
  options = initialize_options(path,options)
  begin
    @git = Rugged::Repository.new(options[:repository])
    if options[:working_directory]
      @git.workdir = options[:working_directory]
    end
  rescue Rugged::RepositoryError, Rugged::OSError
    if options[:init]
      @git = Rugged::Repository.init_at(path, !!options[:bare])
    else
      raise MultiGit::Error::NotARepository, path
    end
  end
  @git.config = Rugged::Config.new(::File.join(@git.path, 'config'))
  verify_bareness(path, options)
end

Instance Method Details

#configObject



121
122
123
# File 'lib/multi_git/rugged_backend/repository.rb', line 121

def config
  @config ||= Config.new(@git.config)
end

#each_branch(filter = :all) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/multi_git/rugged_backend/repository.rb', line 127

def each_branch(filter = :all)
  return to_enum(:each_branch, filter) unless block_given?
  rugged_filter = nil
  if filter == :local || filter == :remote
    rugged_filter = filter
  end
  post_filter = TRUE_LAMBDA
  if filter.kind_of? Regexp
    post_filter = filter
  end
  Rugged::Branch.each(@git, rugged_filter) do |ref|
    next unless post_filter === ref.name
    yield Ref.new(self, ref)
  end
  return self
end

#each_tagObject



144
145
146
147
148
149
150
# File 'lib/multi_git/rugged_backend/repository.rb', line 144

def each_tag
  return to_enum(:each_branch, filter) unless block_given?
  Rugged::Tag.each(@git) do |name|
    yield tag(name)
  end
  return self
end

#git_dirObject



28
29
30
# File 'lib/multi_git/rugged_backend/repository.rb', line 28

def git_dir
  strip_slash @git.path
end

#git_work_treeObject



32
33
34
# File 'lib/multi_git/rugged_backend/repository.rb', line 32

def git_work_tree
  strip_slash @git.workdir
end

#include?(oid) ⇒ Boolean

Parameters:

  • oid (String)

Returns:

  • (Boolean)


117
118
119
# File 'lib/multi_git/rugged_backend/repository.rb', line 117

def include?(oid)
  @git.include?(oid)
end

#parse(oidish) ⇒ String

Parameters:

  • expression (String)

Returns:

  • (String)

    oid

Raises:



105
106
107
108
109
110
111
# File 'lib/multi_git/rugged_backend/repository.rb', line 105

def parse(oidish)
  begin
    return Rugged::Object.rev_parse_oid(@git, oidish)
  rescue Rugged::ReferenceError => e
    raise MultiGit::Error::InvalidReference, e
  end
end

#read(ref) ⇒ MultiGit::Object

Parameters:

  • expression (String)

Returns:

Raises:



86
87
88
89
90
# File 'lib/multi_git/rugged_backend/repository.rb', line 86

def read(ref)
  oid = parse(ref)
  object = @git.lookup(oid)
  return OBJECT_CLASSES[object.type].new(self, oid, object)
end

#ref(name) ⇒ MultiGit::Ref

Parameters:

  • name (String)

Returns:



96
97
98
99
# File 'lib/multi_git/rugged_backend/repository.rb', line 96

def ref(name)
  validate_ref_name(name)
  Ref.new(self, name)
end

#remote(name_or_url) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/multi_git/rugged_backend/repository.rb', line 192

def remote( name_or_url )
  if looks_like_remote_url? name_or_url
    remote = Rugged::Remote.new(__backend__, name_or_url)
  else
    remote = Rugged::Remote.lookup(__backend__, name_or_url)
  end
  if remote
    if remote.name
      return Remote::Persistent.new(self, remote)
    else
      return Remote.new(self, remote)
    end
  else
    return nil
  end
end

#write(content, type = :blob) ⇒ MultiGit::Object

Parameters:

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/multi_git/rugged_backend/repository.rb', line 58

def write(content, type = :blob)
  if content.kind_of? MultiGit::Builder
    return content >> self
  end
  validate_type(type)
  if content.kind_of? MultiGit::Object
    if include?(content.oid)
      return read(content.oid)
    end
    content = content.to_io
  end
  #if content.respond_to? :path
    # file duck-type
  #  oid = @git.hash_file(content.path, type)
  #  return OBJECT_CLASSES[type].new(@git, oid)
  #els
  if content.respond_to? :read
    # IO duck-type
    content = content.read
  end
  oid = @git.write(content.to_s, type)
  return OBJECT_CLASSES[type].new(self, oid)
end