public
Description: Rails plugin for managing your site's version number.
Homepage: http://fiatdev.com/2007/03/31/new-rails-plugin-app-version
Clone URL: git://github.com/toland/app_version.git
Add methods to get build number from git.
Phillip Toland (author)
Sun Aug 10 16:32:50 -0700 2008
commit  48055e21bb77ed5ea66d716f284a0f815912e431
tree    6d1f3bfafbd6ef6771b53198cd1523c53087680e
parent  fde48ddda7dc31bd3098a467e061b219a70a0284
...
29
30
31
32
33
34
35
36
 
 
 
 
 
 
 
 
 
 
37
38
39
...
70
71
72
73
 
74
75
76
...
90
91
92
 
 
 
 
 
 
 
 
 
 
 
 
93
94
95
...
29
30
31
 
 
 
 
 
32
33
34
35
36
37
38
39
40
41
42
43
44
...
75
76
77
 
78
79
80
81
...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
0
@@ -29,11 +29,16 @@ class Version
0
         @milestone = int_value(args[:milestone])
0
       end
0
 
0
- if args[:build] == 'svn'
0
- @build = get_build_from_subversion
0
- else
0
- @build = args[:build] && int_value(args[:build])
0
- end
0
+ @build = case args[:build]
0
+ when 'svn'
0
+ get_build_from_subversion
0
+ when 'git-revcount'
0
+ get_revcount_from_git
0
+ when 'git-hash'
0
+ get_hash_from_git
0
+ else
0
+ args[:build] && int_value(args[:build])
0
+ end
0
     end
0
   end
0
 
0
@@ -70,7 +75,7 @@ class Version
0
 
0
     return 0
0
   end
0
-
0
+
0
   def to_s
0
     str = "#{major}.#{minor}"
0
     str << ".#{patch}" unless patch.nil?
0
@@ -90,6 +95,18 @@ private
0
     end
0
   end
0
 
0
+ def get_revcount_from_git
0
+ if File.exists?(".git")
0
+ `git rev-list HEAD|wc -l`.strip
0
+ end
0
+ end
0
+
0
+ def get_hash_from_git
0
+ if File.exists?(".git")
0
+ `git show --pretty=format:%H|head -n1|cut -c 1-6`.strip
0
+ end
0
+ end
0
+
0
   def int_value(value)
0
     value.to_i.abs
0
   end

Comments

    No one has commented yet.