git-version-bump 0.12.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,17 +29,17 @@ end
29
29
 
30
30
  case ARGV[0].downcase
31
31
  when /^maj?o?r?$/
32
- GVB.tag_version "#{GVB.major_version + 1}.0.0", release_notes
32
+ GVB.tag_version "#{GVB.major_version(true) + 1}.0.0", release_notes
33
33
  when /^min?o?r?$/
34
- GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version+1}.0", release_notes
34
+ GVB.tag_version "#{GVB.major_version(true)}.#{GVB.minor_version(true)+1}.0", release_notes
35
35
  when /^pa?t?c?h?$/
36
- GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version}.#{GVB.patch_version+1}", release_notes
36
+ GVB.tag_version "#{GVB.major_version(true)}.#{GVB.minor_version(true)}.#{GVB.patch_version(true)+1}", release_notes
37
37
  when /^sh?o?w?$/
38
- puts GVB.version
38
+ puts GVB.version(true)
39
39
  exit 0
40
40
  else
41
41
  $stderr.puts "Unknown argument: #{ARGV[0]}. Try --help."
42
42
  exit 1
43
43
  end
44
44
 
45
- puts "Version is now #{GVB.version}."
45
+ puts "Version is now #{GVB.version(true)}."
@@ -4,6 +4,12 @@ require 'digest/sha1'
4
4
  module GitVersionBump
5
5
  class VersionUnobtainable < StandardError; end
6
6
 
7
+ def self.git_available?
8
+ system("git --version >/dev/null 2>&1")
9
+
10
+ $? == 0
11
+ end
12
+
7
13
  def self.dirty_tree?
8
14
  # Are we in a dirty, dirty tree?
9
15
  system("! git diff --no-ext-diff --quiet --exit-code || ! git diff-index --cached --quiet HEAD")
@@ -41,9 +47,18 @@ module GitVersionBump
41
47
  "Unable to find gemspec for caller file #{cf}"
42
48
  end
43
49
 
44
- def self.version
45
- # Shell Quoted, for your convenience
46
- sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
50
+ def self.version(use_local_git=false)
51
+ if use_local_git
52
+ unless git_available?
53
+ raise RuntimeError,
54
+ "GVB.version(use_local_git=true) called, but git isn't installed"
55
+ end
56
+
57
+ sq_git_dir = "'#{Dir.pwd.gsub("'", "'\\''")}'"
58
+ else
59
+ # Shell Quoted, for your convenience
60
+ sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
61
+ end
47
62
 
48
63
  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`.
49
64
  strip.
@@ -66,19 +81,29 @@ module GitVersionBump
66
81
  # information out of rubygems, given only the filename of who called
67
82
  # us. This takes a little bit of effort.
68
83
 
84
+ if use_local_git
85
+ raise VersionUnobtainable,
86
+ "Unable to determine version from local git repo. This should never happen."
87
+ end
88
+
69
89
  if spec = caller_gemspec
70
90
  return spec.version.to_s
71
91
  else
72
92
  # If we got here, something went *badly* wrong -- presumably, we
73
93
  # weren't called from within a loaded gem, and so we've got *no*
74
94
  # idea what's going on. Time to bail!
75
- raise VersionUnobtainable,
76
- "GVB.version(#{gem.inspect}) failed. Is git installed?"
95
+ if git_available
96
+ raise VersionUnobtainable,
97
+ "GVB.version(#{use_local_git.inspect}) failed, and I really don't know why."
98
+ else
99
+ raise VersionUnobtainable,
100
+ "GVB.version(#{use_local_git.inspect}) failed; perhaps you need to install git?"
101
+ end
77
102
  end
78
103
  end
79
104
 
80
- def self.major_version
81
- ver = version
105
+ def self.major_version(use_local_git=false)
106
+ ver = version(use_local_git)
82
107
  v = ver.split('.')[0]
83
108
 
84
109
  unless v =~ /^[0-9]+$/
@@ -89,8 +114,8 @@ module GitVersionBump
89
114
  return v.to_i
90
115
  end
91
116
 
92
- def self.minor_version
93
- ver = version
117
+ def self.minor_version(use_local_git=false)
118
+ ver = version(use_local_git)
94
119
  v = ver.split('.')[1]
95
120
 
96
121
  unless v =~ /^[0-9]+$/
@@ -101,8 +126,8 @@ module GitVersionBump
101
126
  return v.to_i
102
127
  end
103
128
 
104
- def self.patch_version
105
- ver = version
129
+ def self.patch_version(use_local_git=false)
130
+ ver = version(use_local_git)
106
131
  v = ver.split('.')[2]
107
132
 
108
133
  unless v =~ /^[0-9]+$/
@@ -113,13 +138,25 @@ module GitVersionBump
113
138
  return v.to_i
114
139
  end
115
140
 
116
- def self.internal_revision
117
- version.split('.', 4)[3].to_s
141
+ def self.internal_revision(use_local_git=false)
142
+ version(use_local_git).split('.', 4)[3].to_s
118
143
  end
119
144
 
120
- def self.date
145
+ def self.date(use_local_git=false)
146
+ if use_local_git
147
+ unless git_available?
148
+ raise RuntimeError,
149
+ "GVB.date(use_local_git=true), but git is not installed"
150
+ end
151
+
152
+ sq_git_dir = "'#{Dir.pwd.gsub("'", "'\\''")}'"
153
+ else
154
+ # Shell Quoted, for your convenience
155
+ sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
156
+ end
157
+
121
158
  # Are we in a git tree?
122
- system("git status >/dev/null 2>&1")
159
+ system("git -C #{sq_git_dir} status >/dev/null 2>&1")
123
160
  if $? == 0
124
161
  # Yes, we're in git.
125
162
 
@@ -127,9 +164,14 @@ module GitVersionBump
127
164
  return Time.now.strftime("%F")
128
165
  else
129
166
  # Clean tree. Date of last commit is needed.
130
- return `git show --format=format:%ad --date=short | head -n 1`.strip
167
+ return `git -C #{sq_git_dir} show --format=format:%ad --date=short | head -n 1`.strip
131
168
  end
132
169
  else
170
+ if use_local_git
171
+ raise RuntimeError,
172
+ "GVB.date(use_local_git=true) called from non-git location"
173
+ end
174
+
133
175
  # Not in git; time to hit the gemspecs
134
176
  if spec = caller_gemspec
135
177
  return spec.date.strftime("%F")
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.12.0
4
+ version: 0.13.1
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-30 00:00:00.000000000 Z
12
+ date: 2014-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: 4388350532020015811
93
+ hash: 3152864882447384015
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: 4388350532020015811
102
+ hash: 3152864882447384015
103
103
  requirements: []
104
104
  rubyforge_project:
105
105
  rubygems_version: 1.8.23