Class: Vendorificator::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/vendorificator/commit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rev, git) ⇒ Commit

Public: Initializes the object

rev - The String containing revision expression for this commit. git - The MiniGit instance to use.

Returns Commit object.



13
14
15
16
# File 'lib/vendorificator/commit.rb', line 13

def initialize(rev, git)
  @rev = rev
  @git = git
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



5
6
7
# File 'lib/vendorificator/commit.rb', line 5

def git
  @git
end

#revObject (readonly)

Returns the value of attribute rev.



5
6
7
# File 'lib/vendorificator/commit.rb', line 5

def rev
  @rev
end

Instance Method Details

#branchesObject

Public: Finds branches that contain this commit.

Returns Array of branch names.



21
22
23
24
25
# File 'lib/vendorificator/commit.rb', line 21

def branches
  git.capturing.branch({:contains => true}, rev).split("\n").map do |name|
    name.tr('*', '').strip
  end
end

#exists?Boolean

Public: Checks if such a commit exists in the repository.

Returns Boolean.

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/vendorificator/commit.rb', line 30

def exists?
  git.capturing.rev_parse rev
  true
rescue MiniGit::GitError
  false
end

#notesObject

Public: Returns vendorificator git notes for the commit.

Returns the notes Hash.



40
41
42
# File 'lib/vendorificator/commit.rb', line 40

def notes
  YAML.load(git.capturing.notes({:ref => 'vendor'}, 'show', rev))
end

#notes?Boolean

Public: Returns vendorificator git notes for the commit if it exists.

Returns the notes Hash or an empty one.

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/vendorificator/commit.rb', line 47

def notes?
  if exists?
    YAML.load(git.capturing.notes({:ref => 'vendor'}, 'show', rev))
  else
    {}
  end
end