Class: Twigg::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/twigg/repo.rb

Overview

Abstraction around a Git repository on disk.

Defined Under Namespace

Classes: InvalidRepoError

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repo

Given ‘path` to a Git repository on disk sets up a `Repo` instance.

Raises an InvalidRepoError if ‘path` does not point to the top level of an existent Git repo.

Raises:



13
14
15
16
# File 'lib/twigg/repo.rb', line 13

def initialize(path)
  @path = Pathname.new(path)
  raise InvalidRepoError unless valid?
end

Instance Method Details

#commits(all: true, since: nil) ⇒ Object

Returns an array of Commit objects reachable from the HEAD of the repo.

There are a number of keyword arguments that correspond to the options of the same name to ‘git log`:

- `all:` : return reachable commits from all branches, not just HEAD
- `since:`: only return commits made since this Time


26
27
28
29
30
31
32
# File 'lib/twigg/repo.rb', line 26

def commits(all: true, since: nil)
  args = []
  args << '--all' if all
  args << "--since=#{since.to_i}" if since
  @commits ||= {}
  @commits[args] ||= parse_log(log(*args))
end


41
42
43
44
45
# File 'lib/twigg/repo.rb', line 41

def link
  if Config.github.organization
    "https://github.com/#{Config.github.organization}/#{name}"
  end
end

#nameObject

Returns the name of the repo.

The name is inferred from the final component of the repo path.



37
38
39
# File 'lib/twigg/repo.rb', line 37

def name
  @path.basename.to_s
end