git 2.2.0 → 2.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfdec3b45e4e9b00ce87e37026c6b8fe81c306fdc7c127f01e1e682a8655986c
4
- data.tar.gz: 3273f3eb91ab29af0143f1c5e0e5548bbc4e4575bc0a2a8ad4c6faa7cca3252b
3
+ metadata.gz: 1e24e434e4639e6c31133234cee6d96708baf23d212c2f78cf4b94159810b090
4
+ data.tar.gz: 9fc37b011ac0cb0e87a0ee50b7993e751a7075a7496d6feb41431d2f3612e823
5
5
  SHA512:
6
- metadata.gz: 137c05e180c79fc9b3e2810c1fb67a7a9304c365bf7ea445788cbf392c4e0bfadc04d91871e5f1aaf93db8c457b08b55487043abeff0e6a986fc1f812712ffe4
7
- data.tar.gz: 8e7c483a7d5b8699cc48f523678e2d5b586b51fd900ca3a9f5ca3535d3fe9ce3275e449345783de6f5b2656f620dc81225595b17a7881946319c867b089f6d22
6
+ metadata.gz: 232624614200233e3f2ed308a4e73580345fef5be0a98e64f35992ecb222fa96c4163399b2f08afbfcdf69cd3b2f8f6c57c309fe9122f18a56e9bc31f827b301
7
+ data.tar.gz: 4ae699244e5ff9f679795279b8dbfeebe35ce8c9bfb7e5d9a18552b77b3d86b630f50bd9fedb4eec4f697269cfec6c90f72adfa2edeada25258ab457f3b5dad8
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v2.3.0 (2024-09-01)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.2.0..v2.3.0)
11
+
12
+ Changes since v2.2.0:
13
+
14
+ * f8bc987 Fix windows CI build error
15
+ * 471f5a8 Sanatize object ref sent to cat-file command
16
+ * 604a9a2 Make Git::Base#branch work when HEAD is detached
17
+
8
18
  ## v2.2.0 (2024-08-26)
9
19
 
10
20
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.1.1..v2.2.0)
data/lib/git/base.rb CHANGED
@@ -650,10 +650,17 @@ module Git
650
650
  end
651
651
 
652
652
  def cat_file(objectish)
653
- self.lib.object_contents(objectish)
653
+ self.lib.cat_file(objectish)
654
654
  end
655
655
 
656
- # returns the name of the branch the working directory is currently on
656
+ # The name of the branch HEAD refers to or 'HEAD' if detached
657
+ #
658
+ # Returns one of the following:
659
+ # * The branch name that HEAD refers to (even if it is an unborn branch)
660
+ # * 'HEAD' if in a detached HEAD state
661
+ #
662
+ # @return [String] the name of the branch HEAD refers to or 'HEAD' if detached
663
+ #
657
664
  def current_branch
658
665
  self.lib.branch_current
659
666
  end
data/lib/git/lib.rb CHANGED
@@ -353,21 +353,105 @@ module Git
353
353
 
354
354
  alias :namerev :name_rev
355
355
 
356
- def object_type(sha)
357
- command('cat-file', '-t', sha)
356
+ # Output the contents or other properties of one or more objects.
357
+ #
358
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file
359
+ #
360
+ # @example Get the contents of a file without a block
361
+ # lib.cat_file_contents('README.md') # => "This is a README file\n"
362
+ #
363
+ # @example Get the contents of a file with a block
364
+ # lib.cat_file_contents('README.md') { |f| f.read } # => "This is a README file\n"
365
+ #
366
+ # @param object [String] the object whose contents to return
367
+ #
368
+ # @return [String] the object contents
369
+ #
370
+ # @raise [ArgumentError] if object is a string starting with a hyphen
371
+ #
372
+ def cat_file_contents(object, &block)
373
+ assert_args_are_not_options('object', object)
374
+
375
+ if block_given?
376
+ Tempfile.create do |file|
377
+ # If a block is given, write the output from the process to a temporary
378
+ # file and then yield the file to the block
379
+ #
380
+ command('cat-file', "-p", object, out: file, err: file)
381
+ file.rewind
382
+ yield file
383
+ end
384
+ else
385
+ # If a block is not given, return the file contents as a string
386
+ command('cat-file', '-p', object)
387
+ end
388
+ end
389
+
390
+ alias :object_contents :cat_file_contents
391
+
392
+ # Get the type for the given object
393
+ #
394
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file
395
+ #
396
+ # @param object [String] the object to get the type
397
+ #
398
+ # @return [String] the object type
399
+ #
400
+ # @raise [ArgumentError] if object is a string starting with a hyphen
401
+ #
402
+ def cat_file_type(object)
403
+ assert_args_are_not_options('object', object)
404
+
405
+ command('cat-file', '-t', object)
358
406
  end
359
407
 
360
- def object_size(sha)
361
- command('cat-file', '-s', sha).to_i
408
+ alias :object_type :cat_file_type
409
+
410
+ # Get the size for the given object
411
+ #
412
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file
413
+ #
414
+ # @param object [String] the object to get the type
415
+ #
416
+ # @return [String] the object type
417
+ #
418
+ # @raise [ArgumentError] if object is a string starting with a hyphen
419
+ #
420
+ def cat_file_size(object)
421
+ assert_args_are_not_options('object', object)
422
+
423
+ command('cat-file', '-s', object).to_i
362
424
  end
363
425
 
364
- # returns useful array of raw commit object data
365
- def commit_data(sha)
366
- sha = sha.to_s
367
- cdata = command_lines('cat-file', 'commit', sha)
368
- process_commit_data(cdata, sha)
426
+ alias :object_size :cat_file_size
427
+
428
+ # Return a hash of commit data
429
+ #
430
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file
431
+ #
432
+ # @param object [String] the object to get the type
433
+ #
434
+ # @return [Hash] commit data
435
+ #
436
+ # The returned commit data has the following keys:
437
+ # * tree [String]
438
+ # * parent [Array<String>]
439
+ # * author [String] the author name, email, and commit timestamp
440
+ # * committer [String] the committer name, email, and merge timestamp
441
+ # * message [String] the commit message
442
+ # * gpgsig [String] the public signing key of the commit (if signed)
443
+ #
444
+ # @raise [ArgumentError] if object is a string starting with a hyphen
445
+ #
446
+ def cat_file_commit(object)
447
+ assert_args_are_not_options('object', object)
448
+
449
+ cdata = command_lines('cat-file', 'commit', object)
450
+ process_commit_data(cdata, object)
369
451
  end
370
452
 
453
+ alias :commit_data :cat_file_commit
454
+
371
455
  def process_commit_data(data, sha)
372
456
  hsh = {
373
457
  'sha' => sha,
@@ -402,12 +486,50 @@ module Git
402
486
  end
403
487
  end
404
488
 
405
- def tag_data(name)
406
- sha = sha.to_s
407
- tdata = command_lines('cat-file', 'tag', name)
408
- process_tag_data(tdata, name)
489
+ # Return a hash of annotated tag data
490
+ #
491
+ # Does not work with lightweight tags. List all annotated tags in your repository with the following command:
492
+ #
493
+ # ```sh
494
+ # git for-each-ref --format='%(refname:strip=2)' refs/tags | while read tag; do git cat-file tag $tag >/dev/null 2>&1 && echo $tag; done
495
+ # ```
496
+ #
497
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file
498
+ #
499
+ # @param object [String] the tag to retrieve
500
+ #
501
+ # @return [Hash] tag data
502
+ #
503
+ # Example tag data returned:
504
+ # ```ruby
505
+ # {
506
+ # "name" => "annotated_tag",
507
+ # "object" => "46abbf07e3c564c723c7c039a43ab3a39e5d02dd",
508
+ # "type" => "commit",
509
+ # "tag" => "annotated_tag",
510
+ # "tagger" => "Scott Chacon <schacon@gmail.com> 1724799270 -0700",
511
+ # "message" => "Creating an annotated tag\n"
512
+ # }
513
+ # ```
514
+ #
515
+ # The returned commit data has the following keys:
516
+ # * object [String] the sha of the tag object
517
+ # * type [String]
518
+ # * tag [String] tag name
519
+ # * tagger [String] the name and email of the user who created the tag and the timestamp of when the tag was created
520
+ # * message [String] the tag message
521
+ #
522
+ # @raise [ArgumentError] if object is a string starting with a hyphen
523
+ #
524
+ def cat_file_tag(object)
525
+ assert_args_are_not_options('object', object)
526
+
527
+ tdata = command_lines('cat-file', 'tag', object)
528
+ process_tag_data(tdata, object)
409
529
  end
410
530
 
531
+ alias :tag_data :cat_file_tag
532
+
411
533
  def process_tag_data(data, name)
412
534
  hsh = { 'name' => name }
413
535
 
@@ -461,22 +583,6 @@ module Git
461
583
  return hsh_array
462
584
  end
463
585
 
464
- def object_contents(sha, &block)
465
- if block_given?
466
- Tempfile.create do |file|
467
- # If a block is given, write the output from the process to a temporary
468
- # file and then yield the file to the block
469
- #
470
- command('cat-file', "-p", sha, out: file, err: file)
471
- file.rewind
472
- yield file
473
- end
474
- else
475
- # If a block is not given, return stdout
476
- command('cat-file', '-p', sha)
477
- end
478
- end
479
-
480
586
  def ls_tree(sha, opts = {})
481
587
  data = { 'blob' => {}, 'tree' => {}, 'commit' => {} }
482
588
 
@@ -591,8 +697,54 @@ module Git
591
697
  files
592
698
  end
593
699
 
700
+ # The state and name of branch pointed to by `HEAD`
701
+ #
702
+ # HEAD can be in the following states:
703
+ #
704
+ # **:active**: `HEAD` points to a branch reference which in turn points to a
705
+ # commit representing the tip of that branch. This is the typical state when
706
+ # working on a branch.
707
+ #
708
+ # **:unborn**: `HEAD` points to a branch reference that does not yet exist
709
+ # because no commits have been made on that branch. This state occurs in two
710
+ # scenarios:
711
+ #
712
+ # * When a repository is newly initialized, and no commits have been made on the
713
+ # initial branch.
714
+ # * When a new branch is created using `git checkout --orphan <branch>`, starting
715
+ # a new branch with no history.
716
+ #
717
+ # **:detached**: `HEAD` points directly to a specific commit (identified by its
718
+ # SHA) rather than a branch reference. This state occurs when you check out a
719
+ # commit, a tag, or any state that is not directly associated with a branch. The
720
+ # branch name in this case is `HEAD`.
721
+ #
722
+ HeadState = Struct.new(:state, :name)
723
+
724
+ # The current branch state which is the state of `HEAD`
725
+ #
726
+ # @return [HeadState] the state and name of the current branch
727
+ #
728
+ def current_branch_state
729
+ branch_name = command('branch', '--show-current')
730
+ return HeadState.new(:detached, 'HEAD') if branch_name.empty?
731
+
732
+ state =
733
+ begin
734
+ command('rev-parse', '--verify', '--quiet', branch_name)
735
+ :active
736
+ rescue Git::FailedError => e
737
+ raise unless e.result.status.exitstatus == 1 && e.result.stderr.empty?
738
+
739
+ :unborn
740
+ end
741
+
742
+ return HeadState.new(state, branch_name)
743
+ end
744
+
594
745
  def branch_current
595
- branches_all.select { |b| b[1] }.first[0] rescue nil
746
+ branch_name = command('branch', '--show-current')
747
+ branch_name.empty? ? 'HEAD' : branch_name
596
748
  end
597
749
 
598
750
  def branch_contains(commit, branch_name="")
data/lib/git/object.rb CHANGED
@@ -27,7 +27,7 @@ module Git
27
27
  end
28
28
 
29
29
  def size
30
- @size ||= @base.lib.object_size(@objectish)
30
+ @size ||= @base.lib.cat_file_size(@objectish)
31
31
  end
32
32
 
33
33
  # Get the object's contents.
@@ -38,9 +38,9 @@ module Git
38
38
  # Use this for large files so that they are not held in memory.
39
39
  def contents(&block)
40
40
  if block_given?
41
- @base.lib.object_contents(@objectish, &block)
41
+ @base.lib.cat_file_contents(@objectish, &block)
42
42
  else
43
- @contents ||= @base.lib.object_contents(@objectish)
43
+ @contents ||= @base.lib.cat_file_contents(@objectish)
44
44
  end
45
45
  end
46
46
 
@@ -237,7 +237,7 @@ module Git
237
237
  def check_commit
238
238
  return if @tree
239
239
 
240
- data = @base.lib.commit_data(@objectish)
240
+ data = @base.lib.cat_file_commit(@objectish)
241
241
  set_commit(data)
242
242
  end
243
243
 
@@ -254,7 +254,7 @@ module Git
254
254
  end
255
255
 
256
256
  def annotated?
257
- @annotated ||= (@base.lib.object_type(self.name) == 'tag')
257
+ @annotated ||= (@base.lib.cat_file_type(self.name) == 'tag')
258
258
  end
259
259
 
260
260
  def message
@@ -279,7 +279,7 @@ module Git
279
279
  if !self.annotated?
280
280
  @message = @tagger = nil
281
281
  else
282
- tdata = @base.lib.tag_data(@name)
282
+ tdata = @base.lib.cat_file_tag(@name)
283
283
  @message = tdata['message'].chomp
284
284
  @tagger = Git::Author.new(tdata['tagger'])
285
285
  end
@@ -300,7 +300,7 @@ module Git
300
300
  return Git::Object::Tag.new(base, sha, objectish)
301
301
  end
302
302
 
303
- type ||= base.lib.object_type(objectish)
303
+ type ||= base.lib.cat_file_type(objectish)
304
304
  klass =
305
305
  case type
306
306
  when /blob/ then Blob
data/lib/git/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  # The current gem version
3
3
  # @return [String] the current gem version.
4
- VERSION='2.2.0'
4
+ VERSION='2.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon and others
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2024-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -243,8 +243,8 @@ licenses:
243
243
  metadata:
244
244
  homepage_uri: http://github.com/ruby-git/ruby-git
245
245
  source_code_uri: http://github.com/ruby-git/ruby-git
246
- changelog_uri: https://rubydoc.info/gems/git/2.2.0/file/CHANGELOG.md
247
- documentation_uri: https://rubydoc.info/gems/git/2.2.0
246
+ changelog_uri: https://rubydoc.info/gems/git/2.3.0/file/CHANGELOG.md
247
+ documentation_uri: https://rubydoc.info/gems/git/2.3.0
248
248
  post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths: