git-version-bump 0.4.0 → 0.5.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.rb +33 -24
- metadata +3 -3
data/lib/git-version-bump.rb
CHANGED
@@ -8,8 +8,9 @@ module GitVersionBump
|
|
8
8
|
|
9
9
|
def self.caller_gemspec
|
10
10
|
# First up, who called us? Because this method gets called from other
|
11
|
-
# methods within this file, we can't just look at
|
12
|
-
# but instead we need to parse the
|
11
|
+
# methods within this file, we can't just look at
|
12
|
+
# Gem.location_of_caller, but instead we need to parse the caller
|
13
|
+
# stack ourselves to find which gem we're trying to version all over.
|
13
14
|
caller_file = caller.
|
14
15
|
map { |l| l.split(':')[0] }.
|
15
16
|
find { |l| l != __FILE__ }
|
@@ -29,7 +30,7 @@ module GitVersionBump
|
|
29
30
|
nil
|
30
31
|
end
|
31
32
|
|
32
|
-
def self.version
|
33
|
+
def self.version(gem = nil)
|
33
34
|
git_ver = `git describe --dirty --match='v[0-9]*.[0-9]*.*[0-9]' 2>/dev/null`.
|
34
35
|
strip.
|
35
36
|
gsub(/^v/, '').
|
@@ -47,6 +48,10 @@ module GitVersionBump
|
|
47
48
|
system("git status >/dev/null 2>&1")
|
48
49
|
return "0.0.0.1.ENOTAG" if $? == 0
|
49
50
|
|
51
|
+
if gem
|
52
|
+
return Gem.loaded_specs[gem].version.to_s
|
53
|
+
end
|
54
|
+
|
50
55
|
# We're not in a git repo. This means that we need to get version
|
51
56
|
# information out of rubygems, given only the filename of who called
|
52
57
|
# us. This takes a little bit of effort.
|
@@ -58,14 +63,14 @@ module GitVersionBump
|
|
58
63
|
# weren't called from within a loaded gem, and so we've got *no*
|
59
64
|
# idea what's going on. Time to bail!
|
60
65
|
raise RuntimeError,
|
61
|
-
"GVB.version called from mysterious, non-gem location."
|
66
|
+
"GVB.version(#{gem.inspect}) called from mysterious, non-gem location."
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
|
-
VERSION = version
|
70
|
+
VERSION = version('git-version-bump')
|
66
71
|
|
67
|
-
def self.major_version
|
68
|
-
ver = version
|
72
|
+
def self.major_version(gem = nil)
|
73
|
+
ver = version(gem)
|
69
74
|
v = ver.split('.')[0]
|
70
75
|
|
71
76
|
unless v =~ /^[0-9]+$/
|
@@ -76,10 +81,10 @@ module GitVersionBump
|
|
76
81
|
return v.to_i
|
77
82
|
end
|
78
83
|
|
79
|
-
MAJOR_VERSION = major_version
|
84
|
+
MAJOR_VERSION = major_version('git-version-bump')
|
80
85
|
|
81
|
-
def self.minor_version
|
82
|
-
ver = version
|
86
|
+
def self.minor_version(gem = nil)
|
87
|
+
ver = version(gem)
|
83
88
|
v = ver.split('.')[1]
|
84
89
|
|
85
90
|
unless v =~ /^[0-9]+$/
|
@@ -90,10 +95,10 @@ module GitVersionBump
|
|
90
95
|
return v.to_i
|
91
96
|
end
|
92
97
|
|
93
|
-
MINOR_VERSION = minor_version
|
98
|
+
MINOR_VERSION = minor_version('git-version-bump')
|
94
99
|
|
95
|
-
def self.patch_version
|
96
|
-
ver = version
|
100
|
+
def self.patch_version(gem = nil)
|
101
|
+
ver = version(gem)
|
97
102
|
v = ver.split('.')[2]
|
98
103
|
|
99
104
|
unless v =~ /^[0-9]+$/
|
@@ -104,20 +109,20 @@ module GitVersionBump
|
|
104
109
|
return v.to_i
|
105
110
|
end
|
106
111
|
|
107
|
-
PATCH_VERSION = patch_version
|
112
|
+
PATCH_VERSION = patch_version('git-version-bump')
|
108
113
|
|
109
|
-
def self.internal_revision
|
110
|
-
version.split('.', 4)[3].to_s
|
114
|
+
def self.internal_revision(gem = nil)
|
115
|
+
version(gem).split('.', 4)[3].to_s
|
111
116
|
end
|
112
117
|
|
113
|
-
INTERNAL_REVISION = internal_revision
|
118
|
+
INTERNAL_REVISION = internal_revision('git-version-bump')
|
114
119
|
|
115
|
-
def self.date
|
120
|
+
def self.date(gem = nil)
|
116
121
|
# Are we in a git tree?
|
117
122
|
system("git status >/dev/null 2>&1")
|
118
123
|
if $? == 0
|
119
124
|
# Yes, we're in git.
|
120
|
-
|
125
|
+
|
121
126
|
if dirty_tree?
|
122
127
|
return Time.now.strftime("%F")
|
123
128
|
else
|
@@ -126,16 +131,20 @@ module GitVersionBump
|
|
126
131
|
end
|
127
132
|
else
|
128
133
|
# Not in git; time to hit the gemspecs
|
134
|
+
if gem
|
135
|
+
return Gem.loaded_specs[gem].date.strftime("%F")
|
136
|
+
end
|
137
|
+
|
129
138
|
if spec = caller_gemspec
|
130
|
-
return spec.
|
131
|
-
else
|
132
|
-
raise RuntimeError,
|
133
|
-
"GVB.date called from mysterious, non-gem location."
|
139
|
+
return spec.date.strftime("%F")
|
134
140
|
end
|
141
|
+
|
142
|
+
raise RuntimeError,
|
143
|
+
"GVB.date(#{gem.inspect}) called from mysterious, non-gem location."
|
135
144
|
end
|
136
145
|
end
|
137
146
|
|
138
|
-
DATE = date
|
147
|
+
DATE = date('git-version-bump')
|
139
148
|
|
140
149
|
def self.tag_version(v)
|
141
150
|
if dirty_tree?
|
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.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
segments:
|
89
89
|
- 0
|
90
|
-
hash:
|
90
|
+
hash: 1215033858800300071
|
91
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
92
|
none: false
|
93
93
|
requirements:
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
segments:
|
98
98
|
- 0
|
99
|
-
hash:
|
99
|
+
hash: 1215033858800300071
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
102
|
rubygems_version: 1.8.23
|