Class: MultiGit::Repository Abstract

Inherits:
Object
  • Object
show all
Extended by:
Utils::AbstractMethods
Defined in:
lib/multi_git/repository.rb

Overview

This class is abstract.

Abstract base class for all repository implementations.

Examples:

Creating a new repository

# setup:
dir = `mktemp -d`
# example:
repo = MultiGit.open(dir, init: true) #=> be_a MultiGit::Repository
repo.bare? #=> eql false
repo.git_dir #=> eql dir + '/.git'
repo.git_work_tree #=> eql dir
# creating a first commit:
repo.branch('master').commit do
  tree['file'] = 'content'
end
# teardown:
`rm -rf #{dir}`

Object interface collapse

References interface collapse

Instance Method Summary collapse

Methods included from Utils::AbstractMethods

abstract

Instance Method Details

#bare?Object

This method is abstract.

Is this repository bare?



61
# File 'lib/multi_git/repository.rb', line 61

abstract :bare?

#branch(name) ⇒ Ref

Opens a branch

Examples:

# setup:
dir = `mktemp -d`
# example:
repository = MultiGit.open(dir, init: true)
# getting a local branch
repository.branch('master') #=> be_a MultiGit::Ref
# getting a remote branch
repository.branch('origin/master') #=> be_a MultiGit::Ref
# teardown:
`rm -rf #{dir}`

Parameters:

  • name (String)

    branch name

Returns:



162
163
164
165
166
167
168
# File 'lib/multi_git/repository.rb', line 162

def branch(name)
  if name.include? '/'
    ref('refs/remotes/'+name)
  else
    ref('refs/heads/'+name)
  end
end

#configConfig

This method is abstract.

Returns the config

Returns:



44
# File 'lib/multi_git/repository.rb', line 44

abstract :config

#each_branch(filter = :all) {|branch| ... } ⇒ Enumerable<Ref>

Yields either all, local or remote branches. If called with a regular expression it will be used to filter the branches by name.

Parameters:

  • filter (:all, :local, :remote, Regexp) (defaults to: :all)

Yields:

  • branch

Yield Parameters:

Returns:

  • (Enumerable<Ref>)

    if called without block



188
# File 'lib/multi_git/repository.rb', line 188

abstract :each_branch

#each_tag {|tag| ... } ⇒ Enumerable<Ref>

Yields all tags.

Yields:

  • tag

Yield Parameters:

Returns:

  • (Enumerable<Ref>)

    if called without block



197
# File 'lib/multi_git/repository.rb', line 197

abstract :each_tag

#git_dirString

This method is abstract.

Returns the repository directory (the place where the internal stuff is stored)

Returns:

  • (String)


50
# File 'lib/multi_git/repository.rb', line 50

abstract :git_dir

#git_work_treeString

This method is abstract.

Returns the working directory (the place where your files are)

Returns:

  • (String)


56
# File 'lib/multi_git/repository.rb', line 56

abstract :git_work_tree

#headRef

Gets the HEAD ref.

Returns:

  • (Ref)

    head



142
143
144
# File 'lib/multi_git/repository.rb', line 142

def head
  return ref('HEAD')
end

#include?(oid) ⇒ Boolean

This method is abstract.

Checks whether this repository contains a given oid.

Parameters:

  • oid (String)

Returns:

  • (Boolean)


83
# File 'lib/multi_git/repository.rb', line 83

abstract :include?

#parse(expression) ⇒ String

This method is abstract.

Resolves an expression into an oid.

Parameters:

  • expression (String)

Returns:

  • (String)

    oid

Raises:

See Also:



95
# File 'lib/multi_git/repository.rb', line 95

abstract :parse

#read(expression) ⇒ MultiGit::Object

This method is abstract.

Reads an object from the database.

Parameters:

  • expression (String)

Returns:

Raises:

See Also:



76
# File 'lib/multi_git/repository.rb', line 76

abstract :read

#ref(name) ⇒ MultiGit::Ref Also known as: []

This method is abstract.

Opens a reference. A reference is usually known as branch or tag.

Examples:

# setup:
dir = `mktemp -d`
# example:
repo = MultiGit.open(dir, init: true) #=> be_a MultiGit::Repository
master_branch = repo.ref('refs/heads/master')
head = repo.ref('HEAD')
# teardown:
`rm -rf #{dir}`

Parameters:

  • name (String)

Returns:



138
# File 'lib/multi_git/repository.rb', line 138

abstract :ref

#tag(name) ⇒ Ref

Opens a tag

Parameters:

  • name (String)

    tag name

Returns:



174
175
176
# File 'lib/multi_git/repository.rb', line 174

def tag(name)
  ref('refs/tags/'+name)
end

#write(content) ⇒ MultiGit::Object Also known as: <<

This method is abstract.

Writes something to the repository.

If called with a String or an IO, this method creates a Blob with the given content. This is the easiest way to create blobs.

If called with a Object, this method determines if the object does already exist and writes it otherwise.

If called with a Builder, this method inserts the content of the builder to the repository. This is the easiest way to create trees/commits.

Parameters:

Returns:



112
# File 'lib/multi_git/repository.rb', line 112

abstract :write