git-version-bump 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94d95a18eae098b144f0f9afff676405cb1a05cf35b6786410e160269d7b34ec
4
- data.tar.gz: db3e976ffa2d7e5493c957d340aafaffdd570d45bc3db83e2f0d6f70742e58c0
3
+ metadata.gz: ed72f5f43e0499fd3173d49cba195cc578b5caed0469ecae7d6767c5e138ed25
4
+ data.tar.gz: 738c6792fccd8af5808ed0c682fe4bac074bb0b0cdc26a54d2468f20077ed2b6
5
5
  SHA512:
6
- metadata.gz: 4c2a692ace08cda02976a2647dec09b978a82829e51e7bdec4a93c7954d3e4728e24bcac211fa128861fec979f5f41290e88ca40f6e04feb371f362854abf9e3
7
- data.tar.gz: 737dd2b41d89ca7d33722948e69a9de74f10e260d4776aba82cfee9f6b4a15df28042b86d839ceb53012ac7a1247278b8e46b259e10ced7cae904cadb512510d
6
+ metadata.gz: '06647807704eb29d67b960a806159f01353f0f220cce1340fccf4c0413a71ec80f7f0898a59929996a18a147f8c7938c1ce61c146946edb442889a872c97b407'
7
+ data.tar.gz: 4d540d47ddb7ef19f99b7402a2d4e695672aabfea51f2f94a5617b5576dde50225d7e6254902eef672608b69d95e1b0dbb1a8f64175407ea7d2a9ba10caaf15d
data/README.md CHANGED
@@ -99,7 +99,7 @@ gemspec, like this:
99
99
  Gem::Specification.new do |s|
100
100
  s.version = GVB.version
101
101
  s.date = GVB.date
102
-
102
+
103
103
  ...
104
104
  end
105
105
 
@@ -118,7 +118,7 @@ what version of a library you're running, then you probably like to define a
118
118
  to do:
119
119
 
120
120
  require 'git-version-bump'
121
-
121
+
122
122
  class Foobar
123
123
  VERSION = GVB.version
124
124
  end
@@ -126,6 +126,20 @@ to do:
126
126
  This will work correctly inside your git tree, and also in your installed
127
127
  gem. Magical!
128
128
 
129
+ #### For projects using lite tags
130
+
131
+ If you are using GitHub releases for your project or some other method that
132
+ involves light tags (tags with no annotations), you might notice that these
133
+ tags are not detected by git-version-bump by default. If you want these
134
+ commits to be detected then use the following configuration:
135
+
136
+ require 'git-version-bump'
137
+
138
+ class Foobar
139
+ # First parameter is use_local_git, second is include_lite_tags
140
+ VERSION = GVB.version(false, true)
141
+ end
142
+
129
143
 
130
144
  # Contributing
131
145
 
@@ -18,11 +18,13 @@ if ARGV[0].nil? or
18
18
 
19
19
  -d, --dry-run: Calculate and return the bump value, but don't update git workspace or remote
20
20
  -n, --notes: Prompt for "release notes" to add to the release tag
21
+ -l, --lite-tags: Include non-annotated git tags
21
22
  EOF
22
23
  end
23
24
 
24
25
  release_notes = ARGV.delete('-n') || ARGV.delete('--notes')
25
26
  dry_run = ARGV.delete('-d') || ARGV.delete('--dry-run')
27
+ lite_tags = ARGV.delete('-l') || ARGV.delete('--lite-tags')
26
28
 
27
29
  if ARGV[0].nil? or ARGV[0].empty?
28
30
  exit 1
@@ -48,6 +50,6 @@ end
48
50
  if dry_run
49
51
  puts result
50
52
  else
51
- GVB.tag_version result, release_notes
53
+ GVB.tag_version result, release_notes, lite_tags
52
54
  puts "Version is now #{GVB.version(true)}."
53
55
  end
@@ -5,9 +5,11 @@ require 'pathname'
5
5
  module GitVersionBump
6
6
  class VersionUnobtainable < StandardError; end
7
7
 
8
+ VERSION_TAG_GLOB = 'v[0-9]*.[0-9]*.*[0-9]'
9
+
8
10
  DEVNULL = Gem.win_platform? ? "NUL" : "/dev/null"
9
11
 
10
- def self.version(use_local_git=false)
12
+ def self.version(use_local_git=false, include_lite_tags=false)
11
13
  if use_local_git
12
14
  unless git_available?
13
15
  raise RuntimeError,
@@ -19,7 +21,10 @@ module GitVersionBump
19
21
  sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
20
22
  end
21
23
 
22
- 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> #{DEVNULL}`.
24
+ git_cmd = "git -C #{sq_git_dir} describe --dirty='.1.dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}' --match='#{VERSION_TAG_GLOB}'"
25
+ git_cmd << " --tags" if include_lite_tags
26
+
27
+ git_ver = `#{git_cmd} 2> #{DEVNULL}`.
23
28
  strip.
24
29
  gsub(/^v/, '').
25
30
  gsub('-', '.')
@@ -31,15 +36,17 @@ module GitVersionBump
31
36
  # git failed us; we're either not in a git repo or else we've never
32
37
  # tagged anything before.
33
38
 
34
- # Are we in a git repo with no tags? If so, dump out our
35
- # super-special version and be done with it, otherwise try to use the
36
- # gem version.
37
- system("git -C #{sq_git_dir} status > #{DEVNULL} 2>&1")
38
- $? == 0 ? "0.0.0.1.ENOTAG" : gem_version(use_local_git)
39
+ # Are we in a git repo with no tags? If so, try to use the gemspec
40
+ # and if that fails then abort
41
+ begin
42
+ return gem_version(use_local_git)
43
+ rescue VersionUnobtainable
44
+ return "0.0.0.1.ENOTAG"
45
+ end
39
46
  end
40
47
 
41
- def self.major_version(use_local_git=false)
42
- ver = version(use_local_git)
48
+ def self.major_version(use_local_git=false, include_lite_tags=false)
49
+ ver = version(use_local_git, include_lite_tags)
43
50
  v = ver.split('.')[0]
44
51
 
45
52
  unless v =~ /^[0-9]+$/
@@ -50,8 +57,8 @@ module GitVersionBump
50
57
  return v.to_i
51
58
  end
52
59
 
53
- def self.minor_version(use_local_git=false)
54
- ver = version(use_local_git)
60
+ def self.minor_version(use_local_git=false, include_lite_tags=false)
61
+ ver = version(use_local_git, include_lite_tags)
55
62
  v = ver.split('.')[1]
56
63
 
57
64
  unless v =~ /^[0-9]+$/
@@ -62,8 +69,8 @@ module GitVersionBump
62
69
  return v.to_i
63
70
  end
64
71
 
65
- def self.patch_version(use_local_git=false)
66
- ver = version(use_local_git)
72
+ def self.patch_version(use_local_git=false, include_lite_tags=false)
73
+ ver = version(use_local_git, include_lite_tags)
67
74
  v = ver.split('.')[2]
68
75
 
69
76
  unless v =~ /^[0-9]+$/
@@ -74,8 +81,8 @@ module GitVersionBump
74
81
  return v.to_i
75
82
  end
76
83
 
77
- def self.internal_revision(use_local_git=false)
78
- version(use_local_git).split('.', 4)[3].to_s
84
+ def self.internal_revision(use_local_git=false, include_lite_tags=false)
85
+ version(use_local_git, include_lite_tags).split('.', 4)[3].to_s
79
86
  end
80
87
 
81
88
  def self.date(use_local_git=false)
@@ -95,11 +102,11 @@ module GitVersionBump
95
102
  if $? == 0
96
103
  # Yes, we're in git.
97
104
 
98
- if dirty_tree?
105
+ if dirty_tree?(sq_git_dir)
99
106
  return Time.now.strftime("%F")
100
107
  else
101
108
  # Clean tree. Date of last commit is needed.
102
- return `git -C #{sq_git_dir} show --no-show-signature --format=format:%cd --date=short`.lines.first.strip
109
+ return `git -C #{sq_git_dir} show --no-show-signature --format=format:%cd --date=short`.lines.first&.strip
103
110
  end
104
111
  else
105
112
  if use_local_git
@@ -117,14 +124,16 @@ module GitVersionBump
117
124
  end
118
125
  end
119
126
 
120
- def self.tag_version(v, release_notes = false)
127
+ def self.tag_version(v, release_notes = false, include_lite_tags=false)
121
128
  if dirty_tree?
122
129
  puts "You have uncommitted files. Refusing to tag a dirty tree."
123
130
  else
124
131
  if release_notes
125
132
  # We need to find the tag before this one, so we can list all the commits
126
133
  # between the two. This is not a trivial operation.
127
- prev_tag = `git describe --always`.strip.gsub(/-\d+-g[0-9a-f]+$/, '')
134
+ git_cmd = "git describe --match='#{VERSION_TAG_GLOB}' --always"
135
+ git_cmd << ' --tags' if include_lite_tags
136
+ prev_tag = `#{git_cmd}`.strip.gsub(/-\d+-g[0-9a-f]+$/, '')
128
137
 
129
138
  log_file = Tempfile.new('gvb')
130
139
 
@@ -221,10 +230,13 @@ module GitVersionBump
221
230
  # git failed us; either we're not in a git repo or else it's a git
222
231
  # repo that's not got any commits.
223
232
 
224
- # Are we in a git repo with no tags? If so, dump out our
225
- # super-special version and be done with it.
226
- system("git -C #{sq_git_dir} status > #{DEVNULL} 2>&1")
227
- $? == 0 ? "0.0.0.1.ENOCOMMITS" : gem_version(use_local_git)
233
+ # Are we in a git repo with no commits? If so, try to use the gemspec
234
+ # and if that fails then abort
235
+ begin
236
+ return gem_version(use_local_git)
237
+ rescue VersionUnobtainable
238
+ return "0.0.0.1.ENOCOMMITS"
239
+ end
228
240
  end
229
241
 
230
242
  private
@@ -235,11 +247,9 @@ module GitVersionBump
235
247
  $? == 0
236
248
  end
237
249
 
238
- def self.dirty_tree?
250
+ def self.dirty_tree?(sq_git_dir='.')
239
251
  # Are we in a dirty, dirty tree?
240
- system("! git diff --no-ext-diff --quiet --exit-code 2> #{DEVNULL} || ! git diff-index --cached --quiet HEAD 2> #{DEVNULL}")
241
-
242
- $? == 0
252
+ !system("git -C #{sq_git_dir} diff --no-ext-diff --quiet --exit-code 2> #{DEVNULL}") || !("git -C #{sq_git_dir} diff-index --cached --quiet HEAD 2> #{DEVNULL}")
243
253
  end
244
254
 
245
255
  def self.caller_file
@@ -248,8 +258,8 @@ module GitVersionBump
248
258
  # instead we need to parse the caller stack ourselves to find which
249
259
  # gem we're trying to version all over.
250
260
  Pathname(
251
- caller.
252
- map { |l| l.split(':')[0] }.
261
+ caller_locations.
262
+ map(&:path).
253
263
  find { |l| l != __FILE__ }
254
264
  ).realpath.to_s rescue nil
255
265
  end
@@ -260,8 +270,16 @@ module GitVersionBump
260
270
  # Grovel through all the loaded gems to try and find the gem
261
271
  # that contains the caller's file.
262
272
  Gem.loaded_specs.values.each do |spec|
263
- search_dirs = spec.require_paths.map { |d| "#{spec.full_gem_path}/#{d}" } +
264
- [File.join(spec.full_gem_path, spec.bindir)]
273
+ # On Windows I have encountered gems that already have an absolute
274
+ # path, verify that the path is relative before appending to it
275
+ search_dirs = spec.require_paths.map do |path|
276
+ if Pathname(path).absolute?
277
+ path
278
+ else
279
+ File.join(spec.full_gem_path, path)
280
+ end
281
+ end
282
+ search_dirs << File.join(spec.full_gem_path, spec.bindir)
265
283
  search_dirs.map! do |d|
266
284
  begin
267
285
  Pathname(d).realpath.to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-version-bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-19 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-release
@@ -102,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubyforge_project:
106
- rubygems_version: 2.7.7
105
+ rubygems_version: 3.0.3
107
106
  signing_key:
108
107
  specification_version: 4
109
108
  summary: Manage your app version entirely via git tags