git-version-bump 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/.gitignore +2 -1
  2. data/lib/git-version-bump.rb +56 -44
  3. metadata +3 -3
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
- .bundle
1
+ pkg/
2
+ .bundle/
2
3
  Gemfile.lock
@@ -1,4 +1,34 @@
1
1
  module GitVersionBump
2
+ def self.dirty_tree?
3
+ # Are we in a dirty, dirty tree?
4
+ system("! git diff --no-ext-diff --quiet --exit-code || ! git diff-index --cached --quiet HEAD")
5
+
6
+ $? == 0
7
+ end
8
+
9
+ def self.caller_gemspec
10
+ # First up, who called us? Because this method gets called from other
11
+ # methods within this file, we can't just look at Gem.location_of_caller,
12
+ # but instead we need to parse the whole caller stack ourselves.
13
+ caller_file = caller.
14
+ map { |l| l.split(':')[0] }.
15
+ find { |l| l != __FILE__ }
16
+
17
+ # Next we grovel through all the loaded gems to try and find the gem
18
+ # that contains the caller's file.
19
+ Gem.loaded_specs.values.each do |spec|
20
+ if Dir.
21
+ glob(spec.lib_dirs_glob).
22
+ find { |d| caller_file.index(d) == 0 }
23
+ # The caller_file is in this
24
+ # gem! Woohoo!
25
+ return spec
26
+ end
27
+ end
28
+
29
+ nil
30
+ end
31
+
2
32
  def self.version
3
33
  git_ver = `git describe --dirty --match='v[0-9]*.[0-9]*.*[0-9]' 2>/dev/null`.
4
34
  strip.
@@ -21,7 +51,7 @@ module GitVersionBump
21
51
  # information out of rubygems, given only the filename of who called
22
52
  # us. This takes a little bit of effort.
23
53
 
24
- if spec = GVB.caller_gemspec
54
+ if spec = caller_gemspec
25
55
  return spec.version.to_s
26
56
  else
27
57
  # If we got here, something went *badly* wrong -- presumably, we
@@ -31,9 +61,11 @@ module GitVersionBump
31
61
  "GVB.version called from mysterious, non-gem location."
32
62
  end
33
63
  end
34
-
64
+
65
+ VERSION = version
66
+
35
67
  def self.major_version
36
- ver = GVB.version
68
+ ver = version
37
69
  v = ver.split('.')[0]
38
70
 
39
71
  unless v =~ /^[0-9]+$/
@@ -43,9 +75,11 @@ module GitVersionBump
43
75
 
44
76
  return v.to_i
45
77
  end
46
-
78
+
79
+ MAJOR_VERSION = major_version
80
+
47
81
  def self.minor_version
48
- ver = GVB.version
82
+ ver = version
49
83
  v = ver.split('.')[1]
50
84
 
51
85
  unless v =~ /^[0-9]+$/
@@ -55,9 +89,11 @@ module GitVersionBump
55
89
 
56
90
  return v.to_i
57
91
  end
58
-
92
+
93
+ MINOR_VERSION = minor_version
94
+
59
95
  def self.patch_version
60
- ver = GVB.version
96
+ ver = version
61
97
  v = ver.split('.')[2]
62
98
 
63
99
  unless v =~ /^[0-9]+$/
@@ -67,18 +103,22 @@ module GitVersionBump
67
103
 
68
104
  return v.to_i
69
105
  end
70
-
106
+
107
+ PATCH_VERSION = patch_version
108
+
71
109
  def self.internal_revision
72
- GVB.version.split('.', 4)[3].to_s
110
+ version.split('.', 4)[3].to_s
73
111
  end
74
-
112
+
113
+ INTERNAL_REVISION = internal_revision
114
+
75
115
  def self.date
76
116
  # Are we in a git tree?
77
117
  system("git status >/dev/null 2>&1")
78
118
  if $? == 0
79
119
  # Yes, we're in git.
80
120
 
81
- if GVB.dirty_tree?
121
+ if dirty_tree?
82
122
  return Time.now.strftime("%F")
83
123
  else
84
124
  # Clean tree. Date of last commit is needed.
@@ -86,7 +126,7 @@ module GitVersionBump
86
126
  end
87
127
  else
88
128
  # Not in git; time to hit the gemspecs
89
- if spec = GVB.caller_gemspec
129
+ if spec = caller_gemspec
90
130
  return spec.version.to_s
91
131
  else
92
132
  raise RuntimeError,
@@ -94,45 +134,17 @@ module GitVersionBump
94
134
  end
95
135
  end
96
136
  end
97
-
137
+
138
+ DATE = date
139
+
98
140
  def self.tag_version(v)
99
- if GVB.dirty_tree?
141
+ if dirty_tree?
100
142
  puts "You have uncommitted files. Refusing to tag a dirty tree."
101
143
  else
102
144
  puts "Tagging version #{v}..."
103
145
  system("git tag -a -m 'Version v#{v}' v#{v}")
104
146
  end
105
147
  end
106
-
107
- def self.caller_gemspec
108
- # First up, who called us? Because this method gets called from other
109
- # methods within this file, we can't just look at Gem.location_of_caller,
110
- # but instead we need to parse the whole caller stack ourselves.
111
- caller_file = caller.
112
- map { |l| l.split(':')[0] }.
113
- find { |l| l != __FILE__ }
114
-
115
- # Next we grovel through all the loaded gems to try and find the gem
116
- # that contains the caller's file.
117
- Gem.loaded_specs.values.each do |spec|
118
- if Dir.
119
- glob(spec.lib_dirs_glob).
120
- find { |d| caller_file.index(d) == 0 }
121
- # The caller_file is in this
122
- # gem! Woohoo!
123
- return spec
124
- end
125
- end
126
-
127
- nil
128
- end
129
-
130
- def self.dirty_tree?
131
- # Are we in a dirty, dirty tree?
132
- system("! git diff --no-ext-diff --quiet --exit-code || ! git diff-index --cached --quiet HEAD")
133
-
134
- $? == 0
135
- end
136
148
  end
137
149
 
138
150
  GVB = GitVersionBump
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.1.0
4
+ version: 0.2.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: 4544833629882770877
90
+ hash: 3894791715643148309
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: 4544833629882770877
99
+ hash: 3894791715643148309
100
100
  requirements: []
101
101
  rubyforge_project:
102
102
  rubygems_version: 1.8.23