Class: Grit::Commit

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/robot-army-git-deploy/grit_ext.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/robot-army-git-deploy/grit_ext.rb', line 4

def <=>(other)
  raise ArgumentError unless other.is_a?(Grit::Commit)
  
  if id == other.id
    return 0
  elsif not @repo.commits("#{id}..#{other.id}").empty?
    return -1
  elsif not @repo.commits("#{other.id}..#{id}").empty?
    return 1
  else
    raise ArgumentError, 
      "#{other.inspect} is not an ancestor of #{self.inspect} or vice-versa, and are therefor not comparable"
  end
end