Class: Dragnet::Repository

Inherits:
BaseRepository show all
Extended by:
Forwardable
Defined in:
lib/dragnet/repository.rb

Overview

A small wrapper around a Git Repository object. It provides some useful methods needed during the verify process as well as for reporting.

Instance Attribute Summary collapse

Attributes inherited from BaseRepository

#path

Instance Method Summary collapse

Methods inherited from BaseRepository

#branch, #branches, #diff, #repositories

Constructor Details

#initialize(path:) ⇒ Repository

Creates a new instance of the class. Tries to open the given path as a Git repository.

Parameters:

  • path (Pathname)

    The path where the root of the repository is located.

Raises:

  • (ArgumentError)

    If the given path is not a valid git repository.



22
23
24
25
# File 'lib/dragnet/repository.rb', line 22

def initialize(path:)
  super
  @git = Git.open(path)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



14
15
16
# File 'lib/dragnet/repository.rb', line 14

def git
  @git
end

Instance Method Details

#branches_with(commit) ⇒ Array<Git::Branch>

Returns an array of all the branches that include the given commit.

Parameters:

  • commit (String)

    The SHA1 of the commit to look for.

Returns:

  • (Array<Git::Branch>)

    An array with all the branches that contain the given commit.



52
53
54
# File 'lib/dragnet/repository.rb', line 52

def branches_with(commit)
  branches.select { |branch| branch.contains?(commit) }
end

#branches_with_headArray<Git::Branch>

Returns an array of all the branches that include the current HEAD.

Returns:

  • (Array<Git::Branch>)

    An array with all the branches that contain the current HEAD.



59
60
61
# File 'lib/dragnet/repository.rb', line 59

def branches_with_head
  @branches_with_head ||= branches_with(head.sha)
end

#headGit::Object::Commit

Returns The Commit object at the HEAD of the repository.

Returns:

  • (Git::Object::Commit)

    The Commit object at the HEAD of the repository.



29
30
31
# File 'lib/dragnet/repository.rb', line 29

def head
  @head ||= git.object('HEAD')
end

#multi?FalseClass

Returns It always returns false.

Returns:

  • (FalseClass)

    It always returns false



44
45
46
# File 'lib/dragnet/repository.rb', line 44

def multi?
  false
end

#remote_uri_pathString

Returns the URI path of the repository (extracted from its first remote [assumed to be the origin]). Example:

ssh://jenkins@gerrit.int.esrlabs.com:29418/tools/dragnet -> /tools/dragnet

Returns:

  • (String)

    The URI path of the repository



39
40
41
# File 'lib/dragnet/repository.rb', line 39

def remote_uri_path
  Git::URL.parse(git.remotes.first.url).path
end