git-lite-version-bump 0.17.1 → 0.17.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/git-version-bump.rb +24 -24
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 245fa58c69c2530bf29a431acafb3d1c2072dd685322efe95f2e0a486f57a050
4
- data.tar.gz: 9a2b6c6cab12d189fdf6e85ff769bffaa64a1ca0d301f5712e2cd124fb5e9528
3
+ metadata.gz: 11b1d0035cce0dcc1c4713db85c0b695c945200a625d281b24c50fd2e5fbddb9
4
+ data.tar.gz: 9826f50499d603317b53640bd772bba95486b1180b1fa8d12bfe64cf053c3fb8
5
5
  SHA512:
6
- metadata.gz: 55b0499ada73ff1ee43db28d8388235dde7c2ebe2e36aed80630d61ac1c59a12e942a8ba9461103e02759e093b54dfe10141b664cd52351a70c743c16bae9b6c
7
- data.tar.gz: 5c939fe28ce4faba2fda3016b827b407fbeeb7c021dae79a41316825fae1e256ff0364a35c43dc00e9d6c232d9e2f52f49ef8580c5611d3f8196e0b11e711a85
6
+ metadata.gz: 5a7978746a84b9e614bb1904be4ccbe1790b2f1f0a1f1b6947578418d2341217691bac76af8aeb02dcd9f490110e039fcadc39c5e95ea894eb5abc9b2fadd482
7
+ data.tar.gz: 53ecbb6f8ea367f4273e6a0e78ddd181189fe4ebf4b8a41d48ca92992279380bffcb41273f0a6a32fc33cea0d603c806f97e65c0c992ccd87c50234242d66f27
@@ -5,6 +5,8 @@ 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
12
  def self.version(use_local_git=false, include_lite_tags=false)
@@ -19,7 +21,7 @@ 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_cmd = "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]'"
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}'"
23
25
  git_cmd << " --tags" if include_lite_tags
24
26
 
25
27
  git_ver = `#{git_cmd} 2> #{DEVNULL}`.
@@ -34,11 +36,13 @@ module GitVersionBump
34
36
  # git failed us; we're either not in a git repo or else we've never
35
37
  # tagged anything before.
36
38
 
37
- # Are we in a git repo with no tags? If so, dump out our
38
- # super-special version and be done with it, otherwise try to use the
39
- # gem version.
40
- system("git -C #{sq_git_dir} status > #{DEVNULL} 2>&1")
41
- $? == 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
42
46
  end
43
47
 
44
48
  def self.major_version(use_local_git=false, include_lite_tags=false)
@@ -98,11 +102,11 @@ module GitVersionBump
98
102
  if $? == 0
99
103
  # Yes, we're in git.
100
104
 
101
- if dirty_tree?
105
+ if dirty_tree?(sq_git_dir)
102
106
  return Time.now.strftime("%F")
103
107
  else
104
108
  # Clean tree. Date of last commit is needed.
105
- 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
106
110
  end
107
111
  else
108
112
  if use_local_git
@@ -127,7 +131,7 @@ module GitVersionBump
127
131
  if release_notes
128
132
  # We need to find the tag before this one, so we can list all the commits
129
133
  # between the two. This is not a trivial operation.
130
- git_cmd = 'git describe --always'
134
+ git_cmd = "git describe --match '#{VERSION_TAG_GLOB}' --always"
131
135
  git_cmd << ' --tags' if include_lite_tags
132
136
  prev_tag = `#{git_cmd}`.strip.gsub(/-\d+-g[0-9a-f]+$/, '')
133
137
 
@@ -226,10 +230,13 @@ module GitVersionBump
226
230
  # git failed us; either we're not in a git repo or else it's a git
227
231
  # repo that's not got any commits.
228
232
 
229
- # Are we in a git repo with no tags? If so, dump out our
230
- # super-special version and be done with it.
231
- system("git -C #{sq_git_dir} status > #{DEVNULL} 2>&1")
232
- $? == 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
233
240
  end
234
241
 
235
242
  private
@@ -240,11 +247,9 @@ module GitVersionBump
240
247
  $? == 0
241
248
  end
242
249
 
243
- def self.dirty_tree?
250
+ def self.dirty_tree?(sq_git_dir='.')
244
251
  # Are we in a dirty, dirty tree?
245
- system("! git diff --no-ext-diff --quiet --exit-code 2> #{DEVNULL} || ! git diff-index --cached --quiet HEAD 2> #{DEVNULL}")
246
-
247
- $? == 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}")
248
253
  end
249
254
 
250
255
  def self.caller_file
@@ -252,14 +257,9 @@ module GitVersionBump
252
257
  # within this file, we can't just look at Gem.location_of_caller, but
253
258
  # instead we need to parse the caller stack ourselves to find which
254
259
  # gem we're trying to version all over.
255
- #
256
- # Caller returns paths of the form `/path/to/file:100:in method...` on *nix
257
- # and `C:\path\to\file:in method...` on Windows. Splitting on colon isn't
258
- # reliable since the Windows path has a colon at the beginning, split on :num:
259
- # instead since that will always be there no matter the platform.
260
260
  Pathname(
261
- caller.
262
- map { |l| l.split(/:\d+:/)[0] }.
261
+ caller_locations.
262
+ map(&:path).
263
263
  find { |l| l != __FILE__ }
264
264
  ).realpath.to_s rescue nil
265
265
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-lite-version-bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-06 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-release