aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorVlad Shablinsky2016-06-18 20:33:03 +0300
committerXu Cheng2016-07-16 20:39:13 +0800
commit80489dcb499a727c7613284aea4e744a690f12dc (patch)
tree4b9b0ec917b203ab2f2c78cfa165c05ff42e57d2 /Library
parent90e84453f9adda65de6b9274987d06e46caa5d37 (diff)
downloadbrew-80489dcb499a727c7613284aea4e744a690f12dc.tar.bz2
version: introduce HeadVersion
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/version.rb37
1 files changed, 36 insertions, 1 deletions
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
index 02f442f5d..002bd5372 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -179,6 +179,18 @@ class Version
end
end
+ def self.create(val)
+ unless val.respond_to?(:to_str)
+ raise TypeError, "Version value must be a string; got a #{val.class} (#{val})"
+ end
+
+ if val.to_str.start_with?("HEAD")
+ HeadVersion.new(val)
+ else
+ Version.new(val)
+ end
+ end
+
def initialize(val)
if val.respond_to?(:to_str)
@version = val.to_str
@@ -192,7 +204,7 @@ class Version
end
def head?
- version == "HEAD"
+ false
end
def <=>(other)
@@ -200,6 +212,7 @@ class Version
return 0 if version == other.version
return 1 if head? && !other.head?
return -1 if !head? && other.head?
+ return 0 if head? && other.head?
ltokens = tokens
rtokens = other.tokens
@@ -379,3 +392,25 @@ class Version
return m.captures.first unless m.nil?
end
end
+
+class HeadVersion < Version
+ attr_reader :commit
+
+ def initialize(val)
+ super
+ @commit = @version[/^HEAD-(.+)$/, 1]
+ end
+
+ def update_commit(commit)
+ @commit = commit
+ @version = if commit
+ "HEAD-#{commit}"
+ else
+ "HEAD"
+ end
+ end
+
+ def head?
+ true
+ end
+end