Class: Ed::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/ed/repository.rb

Overview

The Repository class provides a interface to talk to a Git repository.
It does not make a copy of the repository but works off the path it is
given.

The RepositoryCopy class provides the same interface as this class but
it creates a working copy of the repository to allow for parallel access.

The default behavior is to use RepositoryCopy when talking to a
repository but if you would like to disable copying you can use the
Config#copy_repository= config option. You should be aware of its
implications, though.

Direct Known Subclasses

RepositoryCopy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Ed::Repository

Returns a instance of Ed::Repository.

Parameters:

  • path (String, #to_s)

    The URI to a git repository.



81
82
83
# File 'lib/ed/repository.rb', line 81

def initialize path
  @path = path
end

Instance Attribute Details

#pathString (readonly)

Returns The path to the repository on local disk.

Returns:

  • (String)

    The path to the repository on local disk.



72
73
74
# File 'lib/ed/repository.rb', line 72

def path
  @path
end

Class Method Details

.local?(path) ⇒ Boolean

Returns true if the path is considered to be local.

Parameters:

  • path (String)

    The URI to a git a repository.

Returns:

  • (Boolean)

    Returns true if the path is considered to be local.



35
36
37
# File 'lib/ed/repository.rb', line 35

def self.local? path
  URI.parse(path).scheme == "file" || !to_s.include?(':')
end

.ls_remote(*args) {|sha, ref| ... } ⇒ Enumerator

Returns a Enumerator if no block is given.

Parameters:

  • *args (String)

    The same commands given to 'git ls-remote'.

Yield Parameters:

  • sha (String)

    The commit SHA.

  • ref (String)

    The reference (e.g: HEAD, tag, or branch)

Returns:

  • (Enumerator)

    Returns a Enumerator if no block is given.

Raises:

  • (ShellCommand::Exception)

    If git exits with a status code that is non-zero.



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ed/repository.rb', line 55

def self.ls_remote *args
  unless block_given?
    return enum_for(:ls_remote, *args)
  end

  output = ShellCommand.run!("git ls-remote #{args.join(' ')}").stdout  

  output.each_line do |line|
    sha, ref = line.split(/\s+/, 2)
    yield sha, ref.chomp
  end
end

.remote?(path) ⇒ Boolean

Returns true if the path is considered to be remote.

Parameters:

  • path (String)

    The URI to a git a repository.

Returns:

  • (Boolean)

    Returns true if the path is considered to be remote.



24
25
26
# File 'lib/ed/repository.rb', line 24

def self.remote? path
  !local?(path)
end

Instance Method Details

#checkout(*args) ⇒ void

This method returns an undefined value.

Parameters:

  • *options (String)

    The same commands given to 'git checkout'



91
92
93
# File 'lib/ed/repository.rb', line 91

def checkout *args
  git "checkout", *args
end