git-version-bump 0.17.2 → 0.18.0.7.g2e0c3c4

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: cb5d7286ef401dcda5941cfe558c6c76a01f3643d3b64fbf4c39ef0e26df9e43
4
- data.tar.gz: c52065c4822f48411b645da6c9d1e864f9439ced6fc25a2b94cec3d8d743628d
3
+ metadata.gz: 32795b930c87e8796ae34c50d42703165e8dc083d4fa4e6cd19763f49f71d78a
4
+ data.tar.gz: bdf0755443972b724acb3be0cf0b677cc5a698f52533ec9afe8c47dd35ec5553
5
5
  SHA512:
6
- metadata.gz: c128a2fac14105f6703f4344658831392668ffe391460d90b404893d0d9373edc43ce5b25b7572d750f04c7fdb4c50b724b539b02095fd7b8dbe055c1b4d9fc9
7
- data.tar.gz: cd902acf61793e97f98de3139d04dbea2e1e907fc8ead518e6e607283fc79ea984097e1e27b61c73facd49a2039db48091c5c56dfac276f21c8a956126c32220
6
+ metadata.gz: 3e97d8fd061b44c0f841c435f303930eacf1834acfb555c3b69f5ab7cfc918b678fa452e4f5ce1b8b0b780d5f01546226791a0fa45ad6985fc252d7c9cd63d5e
7
+ data.tar.gz: 82f01e33ed949be7ad11a544a24a44383e8f01896b67ff242c955287ea7ea51987e43c7afb9727afd026c63bce78bf0d06b3729016c8af5e4ca429d4ed832d53
@@ -0,0 +1,33 @@
1
+ name: "Release to RubyGems"
2
+ on:
3
+ push:
4
+ branch: [main]
5
+ release:
6
+ types: [created]
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ upload:
11
+ runs-on: ubuntu-latest
12
+ name: "Upload gem"
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ with:
17
+ fetch-depth: 0
18
+
19
+ - name: Install ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: '2.7'
23
+ bundler-cache: true
24
+
25
+ - name: Workaround for https://github.com/actions/checkout/issues/290
26
+ run: |
27
+ git fetch --force --tags
28
+
29
+ - name: Do The Needful
30
+ env:
31
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
32
+ run: |
33
+ bundle exec rake release:rubygem_push
data/bin/git-version-bump CHANGED
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'git-version-bump'
4
-
5
3
  if ARGV[0].nil? or
6
4
  ARGV[0].empty? or
7
5
  (ARGV.length == 1 && (ARGV[0] == "-d" || ARGV[0] == "--dry-run")) or
8
6
  ARGV[0] == '-h' or
9
7
  ARGV[0] == '--help'
10
8
  $stderr.puts <<-EOF.gsub(/^\t\t/, '')
11
- Usage: git version-bump [-n|--notes] [-d|--dry-run] <major|minor|patch|show>
9
+ Usage: git version-bump [-n|--notes] [-l|--lite-tags] [-d|--dry-run] <major|minor|patch|show>
12
10
 
13
11
  'major': x.y.z -> x+1.0.0
14
12
  'minor': x.y.z -> x.y+1.0
@@ -32,24 +30,40 @@ elsif ARGV[0] == '-h' or ARGV[0] == '--help'
32
30
  exit 0
33
31
  end
34
32
 
35
- result = case ARGV[0].downcase
36
- when /^maj?o?r?$/
37
- "#{GVB.major_version(true) + 1}.0.0"
38
- when /^min?o?r?$/
39
- "#{GVB.major_version(true)}.#{GVB.minor_version(true)+1}.0"
40
- when /^pa?t?c?h?$/
41
- "#{GVB.major_version(true)}.#{GVB.minor_version(true)}.#{GVB.patch_version(true)+1}"
42
- when /^sh?o?w?$/
43
- puts GVB.version(true)
44
- exit 0
45
- else
46
- $stderr.puts "Unknown argument: #{ARGV[0]}. Try --help."
47
- exit 1
48
- end
33
+ begin
34
+ require 'git-version-bump'
35
+
36
+ result = case ARGV[0].downcase
37
+ when /^maj?o?r?$/
38
+ "#{GVB.major_version(true) + 1}.0.0"
39
+ when /^min?o?r?$/
40
+ "#{GVB.major_version(true)}.#{GVB.minor_version(true)+1}.0"
41
+ when /^pa?t?c?h?$/
42
+ "#{GVB.major_version(true)}.#{GVB.minor_version(true)}.#{GVB.patch_version(true)+1}"
43
+ when /^sh?o?w?$/
44
+ puts GVB.version(true)
45
+ exit 0
46
+ else
47
+ $stderr.puts "Unknown argument: #{ARGV[0]}. Try --help."
48
+ exit 1
49
+ end
49
50
 
50
- if dry_run
51
- puts result
52
- else
53
- GVB.tag_version result, release_notes, lite_tags
54
- puts "Version is now #{GVB.version(true)}."
51
+ if dry_run
52
+ puts result
53
+ else
54
+ unless GVB.tag_version result, release_notes, lite_tags
55
+ exit 1
56
+ end
57
+ puts "Version is now #{GVB.version(true)}."
58
+ end
59
+ rescue GVB::VersionUnobtainable => ex
60
+ $stderr.puts "Could not obtain version information. #{ex.message} (git available: #{GVB.git_available?.inspect})"
61
+ exit 1
62
+ rescue GVB::CommandFailure => ex
63
+ $stderr.puts "#{ex.message} (exit status: #{ex.exitstatus})"
64
+ $stderr.puts "command output was:"
65
+ $stderr.puts "----8<----"
66
+ $stderr.puts ex.output
67
+ $stderr.puts "---->8----"
68
+ exit 1
55
69
  end
@@ -1,8 +1,33 @@
1
1
  module GitVersionBump
2
- VERSION = GVB.version
3
- MAJOR_VERSION = GVB.major_version
4
- MINOR_VERSION = GVB.minor_version
5
- PATCH_VERSION = GVB.patch_version
6
- INTERNAL_REVISION = GVB.internal_revision
7
- DATE = GVB.date
2
+ def self.VERSION
3
+ GVB.version
4
+ end
5
+
6
+ def self.MAJOR_VERSION
7
+ GVB.major_version
8
+ end
9
+
10
+ def self.MINOR_VERSION
11
+ GVB.minor_version
12
+ end
13
+
14
+ def self.PATCH_VERSION
15
+ GVB.patch_version
16
+ end
17
+
18
+ def self.INTERNAL_REVISION
19
+ GVB.internal_revision
20
+ end
21
+
22
+ def self.DATE
23
+ GVB.date
24
+ end
25
+
26
+ def self.const_missing(c)
27
+ if self.respond_to?(c) && c =~ /\A[A-Z_]+\z/
28
+ public_send c
29
+ else
30
+ super
31
+ end
32
+ end
8
33
  end
@@ -1,52 +1,35 @@
1
1
  require 'tempfile'
2
2
  require 'digest/sha1'
3
+ require 'open3'
3
4
  require 'pathname'
4
5
 
5
6
  module GitVersionBump
6
7
  class VersionUnobtainable < StandardError; end
8
+ class CommandFailure < StandardError
9
+ attr_accessor :output, :exitstatus
10
+
11
+ def initialize(m, output, exitstatus)
12
+ super(m)
13
+ @output, @exitstatus = output, exitstatus
14
+ end
15
+ end
7
16
 
8
17
  VERSION_TAG_GLOB = 'v[0-9]*.[0-9]*.*[0-9]'
18
+ private_constant :VERSION_TAG_GLOB
9
19
 
10
20
  DEVNULL = Gem.win_platform? ? "NUL" : "/dev/null"
21
+ private_constant :DEVNULL
11
22
 
12
- def self.version(use_local_git=false, include_lite_tags=false)
13
- if use_local_git
14
- unless git_available?
15
- raise RuntimeError,
16
- "GVB.version(use_local_git=true) called, but git isn't installed"
17
- end
18
-
19
- sq_git_dir = shell_quoted_string(Dir.pwd)
23
+ def self.version(use_local_dir=false, include_lite_tags=false)
24
+ if use_local_dir
25
+ repo_version(true, include_lite_tags)
20
26
  else
21
- sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
22
- end
23
-
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}`.
28
- strip.
29
- gsub(/^v/, '').
30
- gsub('-', '.')
31
-
32
- # If git returned success, then it gave us a described version.
33
- # Success!
34
- return git_ver if $? == 0
35
-
36
- # git failed us; we're either not in a git repo or else we've never
37
- # tagged anything before.
38
-
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"
27
+ gem_version || repo_version(false, include_lite_tags)
45
28
  end
46
29
  end
47
30
 
48
- def self.major_version(use_local_git=false, include_lite_tags=false)
49
- ver = version(use_local_git, include_lite_tags)
31
+ def self.major_version(use_local_dir=false, include_lite_tags=false)
32
+ ver = version(use_local_dir, include_lite_tags)
50
33
  v = ver.split('.')[0]
51
34
 
52
35
  unless v =~ /^[0-9]+$/
@@ -57,8 +40,8 @@ module GitVersionBump
57
40
  return v.to_i
58
41
  end
59
42
 
60
- def self.minor_version(use_local_git=false, include_lite_tags=false)
61
- ver = version(use_local_git, include_lite_tags)
43
+ def self.minor_version(use_local_dir=false, include_lite_tags=false)
44
+ ver = version(use_local_dir, include_lite_tags)
62
45
  v = ver.split('.')[1]
63
46
 
64
47
  unless v =~ /^[0-9]+$/
@@ -69,8 +52,8 @@ module GitVersionBump
69
52
  return v.to_i
70
53
  end
71
54
 
72
- def self.patch_version(use_local_git=false, include_lite_tags=false)
73
- ver = version(use_local_git, include_lite_tags)
55
+ def self.patch_version(use_local_dir=false, include_lite_tags=false)
56
+ ver = version(use_local_dir, include_lite_tags)
74
57
  v = ver.split('.')[2]
75
58
 
76
59
  unless v =~ /^[0-9]+$/
@@ -81,61 +64,33 @@ module GitVersionBump
81
64
  return v.to_i
82
65
  end
83
66
 
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
67
+ def self.internal_revision(use_local_dir=false, include_lite_tags=false)
68
+ version(use_local_dir, include_lite_tags).split('.', 4)[3].to_s
86
69
  end
87
70
 
88
- def self.date(use_local_git=false)
89
- if use_local_git
90
- unless git_available?
91
- raise RuntimeError,
92
- "GVB.date(use_local_git=true), but git is not installed"
93
- end
94
-
95
- sq_git_dir = shell_quoted_string(Dir.pwd)
71
+ def self.date(use_local_dir=false, include_lite_tags = false)
72
+ if use_local_dir
73
+ repo_date(true, include_lite_tags)
96
74
  else
97
- sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
98
- end
99
-
100
- # Are we in a git tree?
101
- system("git -C #{sq_git_dir} status > #{DEVNULL} 2>&1")
102
- if $? == 0
103
- # Yes, we're in git.
104
-
105
- if dirty_tree?(sq_git_dir)
106
- return Time.now.strftime("%F")
107
- else
108
- # Clean tree. Date of last commit is needed.
109
- return (`git -C #{sq_git_dir} show --no-show-signature --format=format:%cd --date=short`.lines.first || "").strip
110
- end
111
- else
112
- if use_local_git
113
- raise RuntimeError,
114
- "GVB.date(use_local_git=true) called from non-git location"
115
- end
116
-
117
- # Not in git; time to hit the gemspecs
118
- if spec = caller_gemspec
119
- return spec.date.strftime("%F")
120
- end
121
-
122
- raise RuntimeError,
123
- "GVB.date called from mysterious, non-gem location."
75
+ gem_date || repo_date(false, include_lite_tags)
124
76
  end
125
77
  end
126
78
 
127
79
  def self.tag_version(v, release_notes = false, include_lite_tags=false)
128
80
  if dirty_tree?
129
81
  puts "You have uncommitted files. Refusing to tag a dirty tree."
130
- else
131
- if release_notes
82
+ return false
83
+ end
84
+ if release_notes
85
+ log_file = Tempfile.new('gvb')
86
+
87
+ begin
132
88
  # We need to find the tag before this one, so we can list all the commits
133
89
  # between the two. This is not a trivial operation.
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]+$/, '')
90
+ git_cmd = ["git", "describe", "--match=#{VERSION_TAG_GLOB}", "--always"]
91
+ git_cmd << "--tags" if include_lite_tags
137
92
 
138
- log_file = Tempfile.new('gvb')
93
+ prev_tag = run_command(git_cmd, "getting previous release tag").strip.gsub(/-\d+-g[0-9a-f]+$/, '')
139
94
 
140
95
  log_file.puts <<-EOF.gsub(/^\t\t\t\t\t/, '')
141
96
 
@@ -146,29 +101,30 @@ module GitVersionBump
146
101
  # are listed below. This will become v#{v}
147
102
  #
148
103
  EOF
104
+ log_file.puts run_command(["git", "log", "--no-show-signature", "--format=# %h %s", "#{prev_tag}..HEAD"], "getting commit range of release")
149
105
 
150
106
  log_file.close
151
- system("git log --no-show-signature --format='# %h %s' #{prev_tag}..HEAD >>#{log_file.path}")
152
107
 
153
108
  pre_hash = Digest::SHA1.hexdigest(File.read(log_file.path))
154
- system("git config -e -f #{log_file.path}")
109
+ run_command(["git", "config", "-e", "-f", log_file.path], "editing release notes")
155
110
  if Digest::SHA1.hexdigest(File.read(log_file.path)) == pre_hash
156
- puts "Release notes not edited; aborting"
111
+ puts "Release notes not edited; not making release"
157
112
  log_file.unlink
158
113
  return
159
114
  end
160
115
 
161
116
  puts "Tagging version #{v}..."
162
- system("git tag -a -F #{log_file.path} v#{v}")
117
+ run_command(["git", "tag", "-a", "-F", log_file.path, "v#{v}"], "tagging release with annotations")
118
+ ensure
163
119
  log_file.unlink
164
- else
165
- # Crikey this is a lot simpler
166
- system("git tag -a -m 'Version v#{v}' v#{v}")
167
120
  end
168
-
169
- system("git push > #{DEVNULL} 2>&1")
170
- system("git push --tags > #{DEVNULL} 2>&1")
121
+ else
122
+ # Crikey this is a lot simpler
123
+ run_command(["git", "tag", "-a", "-m", "Version v#{v}", "v#{v}"], "tagging release")
171
124
  end
125
+
126
+ run_command(["git", "push"], "pushing commits to the default remote repository")
127
+ run_command(["git", "push", "--tags"], "pushing tags to the default remote repository")
172
128
  end
173
129
 
174
130
  # Calculate a version number based on the date of the most recent git commit.
@@ -198,59 +154,87 @@ module GitVersionBump
198
154
  # version. Since hashes are hex, we're boned. Sorry about that. Don't
199
155
  # make builds off a branch, basically.
200
156
  #
201
- def self.commit_date_version(use_local_git = false)
202
- if use_local_git
203
- unless git_available?
204
- raise RuntimeError,
205
- "GVB.commit_date_version(use_local_git=true) called, but git isn't installed"
206
- end
207
-
208
- sq_git_dir = shell_quoted_string(Dir.pwd)
157
+ def self.commit_date_version(use_local_dir = false)
158
+ if use_local_dir
159
+ commit_date_version_string(true)
209
160
  else
210
- sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
161
+ gem_version || commit_date_version_string(false)
211
162
  end
163
+ end
212
164
 
213
- commit_dates = `git -C #{sq_git_dir} log --no-show-signature --format=%at`.
165
+ def self.commit_date_version_string(use_local_dir = false)
166
+ commit_dates = run_command(["git", "-C", git_dir(use_local_dir).to_s, "log", "--no-show-signature", "--format=%at"], "getting dates of all commits").
214
167
  split("\n").
215
168
  map { |l| Time.at(Integer(l)).strftime("%Y%m%d") }
216
169
 
217
- if $? == 0
218
- # We got a log; calculate our version number and we're done.
219
- version_date = commit_dates.first
220
- commit_count = commit_dates.select { |d| d == version_date }.length - 1
221
- dirty_suffix = if dirty_tree?
222
- ".dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}"
223
- else
224
- ""
225
- end
226
-
227
- return "0.#{version_date}.#{commit_count}#{dirty_suffix}"
170
+ version_date = commit_dates.first
171
+ commit_count = commit_dates.select { |d| d == version_date }.length - 1
172
+ dirty_suffix = if dirty_tree?
173
+ ".dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}"
174
+ else
175
+ ""
228
176
  end
229
177
 
230
- # git failed us; either we're not in a git repo or else it's a git
231
- # repo that's not got any commits.
232
-
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
178
+ return "0.#{version_date}.#{commit_count}#{dirty_suffix}"
179
+ rescue CommandFailure => ex
180
+ p :GVB_CDVS_CMD_FAIL, ex.output if debug?
181
+ if ex.output =~ /fatal: your current branch .* does not have any commits yet/
238
182
  return "0.0.0.1.ENOCOMMITS"
183
+ else
184
+ raise VersionUnobtainable, "Could not get commit date-based version from git repository at #{git_dir(use_local_dir)}"
239
185
  end
240
186
  end
241
187
 
242
- private
243
-
244
188
  def self.git_available?
245
- system("git --version > #{DEVNULL} 2>&1")
246
-
247
- $? == 0
189
+ try_command(["git", "--version"])
248
190
  end
191
+ private_class_method :git_available?
249
192
 
250
- def self.dirty_tree?(sq_git_dir='.')
193
+ def self.dirty_tree?(dir='.')
251
194
  # Are we in a dirty, dirty tree?
252
- ! `git -C #{sq_git_dir} status --porcelain 2> #{DEVNULL}`.empty?
195
+ ! run_command(["git", "-C", dir.to_s, "status", "--porcelain"], "checking for tree cleanliness").empty?
196
+ end
197
+ private_class_method :dirty_tree?
198
+
199
+ # Execute a command, specified as an array.
200
+ #
201
+ # On success, the full output of the command (stdout+stderr, interleaved) is returned.
202
+ # On error, a `CommandFailure` exception is raised.
203
+ #
204
+ def self.run_command(cmd, desc)
205
+ unless cmd.is_a?(Array)
206
+ raise ArgumentError, "Must pass command line arguments in an array"
207
+ end
208
+
209
+ unless cmd.all? { |s| s.is_a?(String) }
210
+ raise ArgumentError, "Command line arguments must be strings"
211
+ end
212
+
213
+ if debug?
214
+ p :GVB_CMD, desc, cmd
215
+ end
216
+
217
+ out, status = Open3.capture2e({"LC_MESSAGES" => "C"}, *cmd)
218
+
219
+ if status.exitstatus != 0
220
+ raise CommandFailure.new("Failed while #{desc}", out, status.exitstatus)
221
+ else
222
+ out
223
+ end
253
224
  end
225
+ private_class_method :run_command
226
+
227
+ # Execute a command, and return whether it succeeded or failed.
228
+ #
229
+ def self.try_command(cmd)
230
+ begin
231
+ run_command(cmd, "try_command")
232
+ true
233
+ rescue CommandFailure
234
+ false
235
+ end
236
+ end
237
+ private_class_method :try_command
254
238
 
255
239
  def self.caller_file
256
240
  # Who called us? Because this method gets called from other methods
@@ -260,9 +244,11 @@ module GitVersionBump
260
244
  Pathname(
261
245
  caller_locations.
262
246
  map(&:path).
247
+ tap { |c| p :CALLER_LOCATIONS, c if debug? }.
263
248
  find { |l| l != __FILE__ }
264
- ).realpath.to_s rescue nil
249
+ ).realpath rescue nil
265
250
  end
251
+ private_class_method :caller_file
266
252
 
267
253
  def self.caller_gemspec
268
254
  cf = caller_file or return nil
@@ -288,48 +274,75 @@ module GitVersionBump
288
274
  end
289
275
  end.compact!
290
276
 
291
- if search_dirs.find { |d| cf.index(d) == 0 }
277
+ if search_dirs.find { |d| cf.to_s.index(d) == 0 }
292
278
  return spec
293
279
  end
294
280
  end
295
281
 
296
- raise VersionUnobtainable,
297
- "Unable to find gemspec for caller file #{cf}"
282
+ if debug?
283
+ p :GVB_NO_GEMSPEC, cf
284
+ end
285
+
286
+ nil
298
287
  end
288
+ private_class_method :caller_gemspec
299
289
 
300
- def self.gem_version(use_local_git = false)
301
- if use_local_git
302
- raise VersionUnobtainable,
303
- "Unable to determine version from local git repo. This should never happen."
304
- end
290
+ def self.gem_version
291
+ caller_gemspec&.version&.to_s
292
+ end
293
+ private_class_method :gem_version
305
294
 
306
- if spec = caller_gemspec
307
- return spec.version.to_s
308
- else
309
- # If we got here, something went *badly* wrong -- presumably, we
310
- # weren't called from within a loaded gem, and so we've got *no*
311
- # idea what's going on. Time to bail!
312
- if git_available?
313
- raise VersionUnobtainable,
314
- "GVB.version(#{use_local_git.inspect}) failed, and I really don't know why."
295
+ def self.gem_date
296
+ caller_gemspec&.date&.strftime("%F")
297
+ end
298
+ private_class_method :gem_version
299
+
300
+ def self.repo_version(use_local_dir, include_lite_tags)
301
+ git_cmd = ["git", "-C", git_dir(use_local_dir).to_s, "describe", "--dirty=.1.dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}", "--match=#{VERSION_TAG_GLOB}"]
302
+ git_cmd << "--tags" if include_lite_tags
303
+
304
+ begin
305
+ run_command(git_cmd, "getting current version descriptor").
306
+ strip.
307
+ gsub(/^v/, '').
308
+ gsub('-', '.')
309
+ rescue CommandFailure => ex
310
+ p :GVB_REPO_VERSION_FAILURE, ex.output if debug?
311
+ if ex.output =~ /fatal: No names found, cannot describe anything/
312
+ # aka "no tags, bro"
313
+ "0.0.0.1.ENOTAG"
315
314
  else
316
- raise VersionUnobtainable,
317
- "GVB.version(#{use_local_git.inspect}) failed; perhaps you need to install git?"
315
+ raise VersionUnobtainable, "Could not get version from gemspec or git repository at #{git_dir(use_local_dir)}"
318
316
  end
319
317
  end
320
318
  end
319
+ private_class_method :repo_version
321
320
 
322
- def self.shell_quoted_string(dir_string)
323
- if Gem.win_platform?
324
- return "\"#{dir_string}\""
321
+ def self.repo_date(use_local_dir, include_lite_tags)
322
+ if dirty_tree?(git_dir(use_local_dir))
323
+ Time.now.strftime("%F")
325
324
  else
326
- # Shell Quoted, for your convenience
327
- return "'#{dir_string.gsub("'", "'\\''")}'"
325
+ # Clean tree. Date of last commit is needed.
326
+ (run_command(["git", "-C", git_dir(use_local_dir).to_s, "show", "--no-show-signature", "--format=format:%cd", "--date=short"], "getting date of last commit").lines.first || "").strip
328
327
  end
328
+ rescue CommandFailure
329
+ raise VersionUnobtainable, "Could not get commit date from git repository at #{git_dir(use_local_dir)}"
329
330
  end
331
+ private_class_method :repo_date
330
332
 
331
- private_class_method :shell_quoted_string
333
+ def self.git_dir(use_local_dir = false)
334
+ if use_local_dir
335
+ Dir.pwd
336
+ else
337
+ caller_file&.dirname || Dir.pwd
338
+ end.tap { |d| p :GVB_GIT_DIR, use_local_dir, d if debug? }
339
+ end
340
+ private_class_method :git_dir
332
341
 
342
+ def self.debug?
343
+ ENV.key?("GVB_DEBUG")
344
+ end
345
+ private_class_method :debug?
333
346
  end
334
347
 
335
348
  GVB = GitVersionBump unless defined? GVB
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.17.2
4
+ version: 0.18.0.7.g2e0c3c4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2023-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-release
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files:
75
75
  - README.md
76
76
  files:
77
+ - ".github/workflows/release.yml"
77
78
  - ".gitignore"
78
79
  - Gemfile
79
80
  - LICENCE
@@ -98,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
99
  version: 2.1.0
99
100
  required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ">="
102
+ - - ">"
102
103
  - !ruby/object:Gem::Version
103
- version: '0'
104
+ version: 1.3.1
104
105
  requirements: []
105
106
  rubygems_version: 3.1.6
106
107
  signing_key: