git-version-bump 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/git-version-bump/version.rb +8 -0
- data/lib/git-version-bump.rb +39 -51
- metadata +5 -4
data/lib/git-version-bump.rb
CHANGED
@@ -11,35 +11,41 @@ module GitVersionBump
|
|
11
11
|
$? == 0
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.caller_file
|
15
|
+
# Who called us? Because this method gets called from other methods
|
16
|
+
# within this file, we can't just look at Gem.location_of_caller, but
|
17
|
+
# instead we need to parse the caller stack ourselves to find which
|
18
|
+
# gem we're trying to version all over.
|
19
|
+
File.realpath(
|
20
|
+
caller.
|
21
|
+
map { |l| l.split(':')[0] }.
|
22
|
+
find { |l| l != __FILE__ }
|
23
|
+
) rescue nil
|
24
|
+
end
|
25
|
+
|
14
26
|
def self.caller_gemspec
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
# stack ourselves to find which gem we're trying to version all over.
|
19
|
-
caller_file = caller.
|
20
|
-
map { |l| l.split(':')[0] }.
|
21
|
-
find { |l| l != __FILE__ }
|
22
|
-
|
23
|
-
# Real paths, please.
|
24
|
-
caller_file = File.realpath(caller_file)
|
25
|
-
|
26
|
-
# Next we grovel through all the loaded gems to try and find the gem
|
27
|
+
cf = caller_file or return nil
|
28
|
+
|
29
|
+
# Grovel through all the loaded gems to try and find the gem
|
27
30
|
# that contains the caller's file.
|
28
31
|
Gem.loaded_specs.values.each do |spec|
|
29
|
-
if Dir.
|
30
|
-
|
31
|
-
find { |d| caller_file.index(File.realpath(d)) == 0 }
|
32
|
+
if (Dir.glob(spec.lib_dirs_glob) + Dir["#{spec.bin_dir}/*"]).
|
33
|
+
find { |d| cf.index(File.realpath(d)) == 0 }
|
32
34
|
# The caller_file is in this
|
33
35
|
# gem! Woohoo!
|
34
36
|
return spec
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
raise VersionUnobtainable,
|
41
|
+
"Unable to find gemspec for caller file #{cf}"
|
39
42
|
end
|
40
43
|
|
41
|
-
def self.version
|
42
|
-
|
44
|
+
def self.version
|
45
|
+
# Shell Quoted, for your convenience
|
46
|
+
sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
|
47
|
+
|
48
|
+
git_ver = `git -C #{sq_git_dir} describe --dirty='.1.dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}' --match='v[0-9]*.[0-9]*.*[0-9]' 2>/dev/null`.
|
43
49
|
strip.
|
44
50
|
gsub(/^v/, '').
|
45
51
|
gsub('-', '.')
|
@@ -53,13 +59,9 @@ module GitVersionBump
|
|
53
59
|
|
54
60
|
# Are we in a git repo with no tags? If so, dump out our
|
55
61
|
# super-special version and be done with it.
|
56
|
-
system("git status >/dev/null 2>&1")
|
62
|
+
system("git -C #{sq_git_dir} status >/dev/null 2>&1")
|
57
63
|
return "0.0.0.1.ENOTAG" if $? == 0
|
58
64
|
|
59
|
-
if gem
|
60
|
-
return Gem.loaded_specs[gem].version.to_s
|
61
|
-
end
|
62
|
-
|
63
65
|
# We're not in a git repo. This means that we need to get version
|
64
66
|
# information out of rubygems, given only the filename of who called
|
65
67
|
# us. This takes a little bit of effort.
|
@@ -75,10 +77,8 @@ module GitVersionBump
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
def self.major_version(gem = nil)
|
81
|
-
ver = version(gem)
|
80
|
+
def self.major_version
|
81
|
+
ver = version
|
82
82
|
v = ver.split('.')[0]
|
83
83
|
|
84
84
|
unless v =~ /^[0-9]+$/
|
@@ -89,10 +89,8 @@ module GitVersionBump
|
|
89
89
|
return v.to_i
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
def self.minor_version(gem = nil)
|
95
|
-
ver = version(gem)
|
92
|
+
def self.minor_version
|
93
|
+
ver = version
|
96
94
|
v = ver.split('.')[1]
|
97
95
|
|
98
96
|
unless v =~ /^[0-9]+$/
|
@@ -103,10 +101,8 @@ module GitVersionBump
|
|
103
101
|
return v.to_i
|
104
102
|
end
|
105
103
|
|
106
|
-
|
107
|
-
|
108
|
-
def self.patch_version(gem = nil)
|
109
|
-
ver = version(gem)
|
104
|
+
def self.patch_version
|
105
|
+
ver = version
|
110
106
|
v = ver.split('.')[2]
|
111
107
|
|
112
108
|
unless v =~ /^[0-9]+$/
|
@@ -117,15 +113,11 @@ module GitVersionBump
|
|
117
113
|
return v.to_i
|
118
114
|
end
|
119
115
|
|
120
|
-
|
121
|
-
|
122
|
-
def self.internal_revision(gem = nil)
|
123
|
-
version(gem).split('.', 4)[3].to_s
|
116
|
+
def self.internal_revision
|
117
|
+
version.split('.', 4)[3].to_s
|
124
118
|
end
|
125
119
|
|
126
|
-
|
127
|
-
|
128
|
-
def self.date(gem = nil)
|
120
|
+
def self.date
|
129
121
|
# Are we in a git tree?
|
130
122
|
system("git status >/dev/null 2>&1")
|
131
123
|
if $? == 0
|
@@ -139,21 +131,15 @@ module GitVersionBump
|
|
139
131
|
end
|
140
132
|
else
|
141
133
|
# Not in git; time to hit the gemspecs
|
142
|
-
if gem
|
143
|
-
return Gem.loaded_specs[gem].date.strftime("%F")
|
144
|
-
end
|
145
|
-
|
146
134
|
if spec = caller_gemspec
|
147
135
|
return spec.date.strftime("%F")
|
148
136
|
end
|
149
137
|
|
150
138
|
raise RuntimeError,
|
151
|
-
"GVB.date
|
139
|
+
"GVB.date called from mysterious, non-gem location."
|
152
140
|
end
|
153
141
|
end
|
154
142
|
|
155
|
-
DATE = date('git-version-bump')
|
156
|
-
|
157
143
|
def self.tag_version(v, release_notes = false)
|
158
144
|
if dirty_tree?
|
159
145
|
puts "You have uncommitted files. Refusing to tag a dirty tree."
|
@@ -171,7 +157,7 @@ module GitVersionBump
|
|
171
157
|
|
172
158
|
# Write your release notes above. The first line should be the release name.
|
173
159
|
# To help you remember what's in here, the commits since your last release
|
174
|
-
# are listed below.
|
160
|
+
# are listed below. This will become v#{v}
|
175
161
|
#
|
176
162
|
EOF
|
177
163
|
|
@@ -200,4 +186,6 @@ module GitVersionBump
|
|
200
186
|
end
|
201
187
|
end
|
202
188
|
|
203
|
-
GVB = GitVersionBump
|
189
|
+
GVB = GitVersionBump unless defined? GVB
|
190
|
+
|
191
|
+
require_relative 'git-version-bump/version'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-version-bump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- git-version-bump.gemspec
|
76
76
|
- lib/git-version-bump.rb
|
77
77
|
- lib/git-version-bump/rake-tasks.rb
|
78
|
+
- lib/git-version-bump/version.rb
|
78
79
|
homepage: http://theshed.hezmatt.org/git-version-bump
|
79
80
|
licenses: []
|
80
81
|
post_install_message:
|
@@ -89,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
90
|
version: '0'
|
90
91
|
segments:
|
91
92
|
- 0
|
92
|
-
hash:
|
93
|
+
hash: 4388350532020015811
|
93
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
95
|
none: false
|
95
96
|
requirements:
|
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: '0'
|
99
100
|
segments:
|
100
101
|
- 0
|
101
|
-
hash:
|
102
|
+
hash: 4388350532020015811
|
102
103
|
requirements: []
|
103
104
|
rubyforge_project:
|
104
105
|
rubygems_version: 1.8.23
|