git-version-bump 0.18.0.8.g580160f → 0.18.0.13.gc1af65c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/lib/git-version-bump.rb +38 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63fc7b28285b00549b449412a047a9abfddcde7f3306c8fd17285b97616c51d3
4
- data.tar.gz: 8bc1c9a5e33b285602f28f49d24e16ab747b9e9556bc239c364f5236fbb733c2
3
+ metadata.gz: 401c8af39ee5870527618010dfaf9d40942dadf75be49d8aff1052068f26e05b
4
+ data.tar.gz: '050811bc1eecc11587c369fe2d1ad48d8f51291127cfd989d23202dca5758e67'
5
5
  SHA512:
6
- metadata.gz: b986ba7470d40aee830db38aceb0581e23ee53e122371101b5625a90053d2df73c7d466329c5eb8070f07fc959b4dc966d013a72572fc9434d6d6afa0c482529
7
- data.tar.gz: 981aac0343a8c43810dbc1725c68f192eef26706bab0f6e59cda1383fa17167e9e0c26e78d57c9efd738501a795fa5b36914ba5fc1e01b35ded8a8b8116c377c
6
+ metadata.gz: 388a339b6f4c4b12bab2294e7fd8c912c5385d50fcb26a504b1dd1266151eb7a34a9ebdccdca4c26cd2a508e898265d5a5389f46b0d56674761349214abfc933
7
+ data.tar.gz: 227415d087e67252ab3a89c655b2b1ffdb23b384f010b9355fa69f3a6f6b18e865764348cbed7a64ad4e949afa6b54ccc14a69b05d1dd82fa3dc25a5e16be890
data/README.md CHANGED
@@ -141,6 +141,19 @@ commits to be detected then use the following configuration:
141
141
  end
142
142
 
143
143
 
144
+ ## Overriding the version
145
+
146
+ In very rare circumstances, while running in a git repo, you may wish to explicitly set the version or date returned by `GVB.version` or `GVB.date`, respectively.
147
+ This can be done by setting the repo's `versionBump.versionOverride` or `versionBump.dateOverride` config values, like so:
148
+
149
+ ```bash
150
+ git config versionBump.versionOverride 1.2.3
151
+ git config versionBump.dateOverride 1970-01-01
152
+ ```
153
+
154
+ Note that whatever you set those values to is used without validity checking; if you set it to something weird, you'll get weird results.
155
+
156
+
144
157
  # Contributing
145
158
 
146
159
  Send your pull requests to the [Github
@@ -25,7 +25,7 @@ module GitVersionBump
25
25
  repo_version(true, include_lite_tags)
26
26
  else
27
27
  gem_version || repo_version(false, include_lite_tags)
28
- end
28
+ end.tap { |v| p :GVB_VERSION, v if debug? }
29
29
  end
30
30
 
31
31
  def self.major_version(use_local_dir=false, include_lite_tags=false)
@@ -106,7 +106,7 @@ module GitVersionBump
106
106
  log_file.close
107
107
 
108
108
  pre_hash = Digest::SHA1.hexdigest(File.read(log_file.path))
109
- run_command(["git", "config", "-e", "-f", log_file.path], "editing release notes")
109
+ run_command(["git", "config", "-e", "-f", log_file.path], "editing release notes", false)
110
110
  if Digest::SHA1.hexdigest(File.read(log_file.path)) == pre_hash
111
111
  puts "Release notes not edited; not making release"
112
112
  log_file.unlink
@@ -198,10 +198,10 @@ module GitVersionBump
198
198
 
199
199
  # Execute a command, specified as an array.
200
200
  #
201
- # On success, the full output of the command (stdout+stderr, interleaved) is returned.
201
+ # On success, the full output of the command (stdout+stderr, interleaved) is returned unless capture_output is not true.
202
202
  # On error, a `CommandFailure` exception is raised.
203
203
  #
204
- def self.run_command(cmd, desc)
204
+ def self.run_command(cmd, desc, capture_output = true)
205
205
  unless cmd.is_a?(Array)
206
206
  raise ArgumentError, "Must pass command line arguments in an array"
207
207
  end
@@ -214,7 +214,13 @@ module GitVersionBump
214
214
  p :GVB_CMD, desc, cmd
215
215
  end
216
216
 
217
- out, status = Open3.capture2e({"LC_MESSAGES" => "C"}, *cmd)
217
+ if capture_output == true
218
+ out, status = Open3.capture2e({"LC_MESSAGES" => "C"}, *cmd)
219
+ else
220
+ out = '(output not captured)'
221
+ pid = spawn(*cmd)
222
+ (retpid, status) = Process.wait2 pid
223
+ end
218
224
 
219
225
  if status.exitstatus != 0
220
226
  raise CommandFailure.new("Failed while #{desc}", out, status.exitstatus)
@@ -236,6 +242,11 @@ module GitVersionBump
236
242
  end
237
243
  private_class_method :try_command
238
244
 
245
+ def self.run_git(git_args, desc, use_local_dir)
246
+ run_command(["git", "-C", git_dir(use_local_dir).to_s] + git_args, desc)
247
+ end
248
+ private_class_method :run_git
249
+
239
250
  def self.caller_file
240
251
  # Who called us? Because this method gets called from other methods
241
252
  # within this file, we can't just look at Gem.location_of_caller, but
@@ -298,6 +309,16 @@ module GitVersionBump
298
309
  private_class_method :gem_version
299
310
 
300
311
  def self.repo_version(use_local_dir, include_lite_tags)
312
+ begin
313
+ run_git(["config", "versionBump.versionOverride"], "getting versionOverride", use_local_dir).chomp
314
+ rescue CommandFailure => ex
315
+ p :NO_OVERRIDE_VERSION, [ex.class, ex.message] if debug?
316
+ repo_version_from_tag(use_local_dir, include_lite_tags)
317
+ end
318
+ end
319
+ private_class_method :repo_version
320
+
321
+ def self.repo_version_from_tag(use_local_dir, include_lite_tags)
301
322
  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
323
  git_cmd << "--tags" if include_lite_tags
303
324
 
@@ -316,9 +337,19 @@ module GitVersionBump
316
337
  end
317
338
  end
318
339
  end
319
- private_class_method :repo_version
340
+ private_class_method :repo_version_from_tag
320
341
 
321
342
  def self.repo_date(use_local_dir, include_lite_tags)
343
+ begin
344
+ run_git(["config", "versionBump.dateOverride"], "getting dateOverride", use_local_dir).chomp
345
+ rescue CommandFailure => ex
346
+ p :NO_OVERRIDE_DATE, [ex.class, ex.message] if debug?
347
+ repo_date_from_commit(use_local_dir, include_lite_tags)
348
+ end
349
+ end
350
+ private_class_method :repo_date
351
+
352
+ def self.repo_date_from_commit(use_local_dir, include_lite_tags)
322
353
  if dirty_tree?(git_dir(use_local_dir))
323
354
  Time.now.strftime("%F")
324
355
  else
@@ -328,7 +359,7 @@ module GitVersionBump
328
359
  rescue CommandFailure
329
360
  raise VersionUnobtainable, "Could not get commit date from git repository at #{git_dir(use_local_dir)}"
330
361
  end
331
- private_class_method :repo_date
362
+ private_class_method :repo_date_from_commit
332
363
 
333
364
  def self.git_dir(use_local_dir = false)
334
365
  if use_local_dir
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.18.0.8.g580160f
4
+ version: 0.18.0.13.gc1af65c
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-20 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-release