git 1.16.0 → 1.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: 06d2809c51685e3171199f0eb8bce4c02a7970d61d12fabbde7bf2ab3850a86b
4
- data.tar.gz: 439eac61b04b8fcdafa739f7f6f27cfc89f00d557aac52aacd6f71762bc8281e
3
+ metadata.gz: dcca4b91f56e1bf6b99c471f918fbe4b1ed6d56b0058021e345514676e153223
4
+ data.tar.gz: 9f4386702fca4248c3a7a07400c6ff3e52fa7898f0e16bbcb3b90bf945fde1da
5
5
  SHA512:
6
- metadata.gz: 57db3b512e1d30130f1ab8bf9f77a701591c4c05c8c9fe35e9d047329cc7fe08b6e17c93d276bcfbfcb3e5c92a8dcb48cc571d513a7a981d69989eac7daea957
7
- data.tar.gz: ee2b51658bda3767a01729888c60b677d79d69b75fadb8659a6d56144e82f51e21da817f7f310b1af0be9baedda37923315adac10ad7a65be1624b6ecb0628fb
6
+ metadata.gz: 4d943759fc15a56baee49734b4628cf1b5651416c13842077a9bfe979df1bdc05afbe114af904b2161ef84be090207f9691a80a704efe2d8a3a14bb4c80df8f6
7
+ data.tar.gz: 8feccfa435ec2f3d95a52ec0fd3920b5a956b2dc3cbcddfbc63c48052ddf64686ba1ef849f0b96307e573134d0e818c6d5bfaae8f3dad877a6f74a516806754a
data/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v1.17.0 (2023-03-05)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.16.0..v1.17.0)
11
+
12
+ Changes since v1.16.0:
13
+
14
+ * 1311 Add deprecation mechanism (introduces runtime dependency on ActiveSupport) (#645)
15
+ * 50b8 Add the push_option option for Git::Lib#push (#644)
16
+ * a799 Make Git::Base#ls_tree handle commit objects (#643)
17
+ * 6db3 Implememt Git.default_branch (#571)
18
+
8
19
  ## v1.16.0 (2023-03-03)
9
20
 
10
21
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.15.0..v1.16.0)
data/README.md CHANGED
@@ -3,47 +3,73 @@
3
3
  # @title README
4
4
  -->
5
5
 
6
- # The Git Gem
6
+ # The `git` Gem
7
7
 
8
- The Git Gem provides an API that can be used to create, read, and manipulate
8
+ [![Gem Version](https://badge.fury.io/rb/git.svg)](https://badge.fury.io/rb/git)
9
+ [![Change Log](https://img.shields.io/badge/change%20log-Latest-green)](https://rubydoc.info/gems/git/file/CHANGELOG.md)
10
+ [![Build Status](https://github.com/ruby-git/ruby-git/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/ruby-git/ruby-git/actions/workflows/continuous_integration.yml)
11
+ [![Code Climate](https://codeclimate.com/github/ruby-git/ruby-git.png)](https://codeclimate.com/github/ruby-git/ruby-git)
12
+ [![Source Code](https://img.shields.io/badge/source-GitHub-green)](https://github.com/ruby-git/ruby-git)
13
+ [![Documentation](https://img.shields.io/badge/documentation-Latest-green)](https://rubydoc.info/gems/git)
14
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ruby-git/ruby-git/blob/master/LICENSE)
15
+
16
+ The git Gem provides an API that can be used to create, read, and manipulate
9
17
  Git repositories by wrapping system calls to the `git` binary. The API can be
10
18
  used for working with Git in complex interactions including branching and
11
19
  merging, object inspection and manipulation, history, patch generation and
12
20
  more.
13
21
 
14
- ## Homepage
22
+ ## Basic Usage
15
23
 
16
- The project source code is at:
24
+ Get started by obtaining a repository object by:
17
25
 
18
- http://github.com/ruby-git/ruby-git
26
+ * Opening an existing working copy with [Git.open](https://rubydoc.info/gems/git/Git#open-class_method)
27
+ * Initializing a new repository with [Git.init](https://rubydoc.info/gems/git/Git#init-class_method)
28
+ * Cloning a repository with [Git.clone](https://rubydoc.info/gems/git/Git#clone-class_method)
19
29
 
20
- ## Documentation
30
+ Methods that can be called on a repository object are documented in [Git::Base](https://rubydoc.info/gems/git/Git/Base)
21
31
 
22
- Detailed documentation can be found at:
32
+ ## Install
23
33
 
24
- https://rubydoc.info/gems/git/Git.html
34
+ You can install the `git` gem with the following command:
25
35
 
26
- Get started by obtaining a repository object by:
27
-
28
- * opening an existing working copy with [Git.open](https://rubydoc.info/gems/git/Git#open-class_method)
29
- * initializing a new repository with [Git.init](https://rubydoc.info/gems/git/Git#init-class_method)
30
- * cloning a repository with [Git.clone](https://rubydoc.info/gems/git/Git#clone-class_method)
36
+ ```shell
37
+ gem install git
38
+ ```
31
39
 
32
- Methods that can be called on a repository object are documented in [Git::Base](https://rubydoc.info/gems/git/Git/Base)
40
+ ## Deprecation Warnings
33
41
 
34
- ## Install
42
+ Deprecation warnings are managed with the `Git.deprecation` attribute.
35
43
 
36
- You can install Ruby/Git like this:
44
+ Use this object to define deprecations in the source code:
37
45
 
46
+ ```ruby
47
+ Git.deprecation.deprecate_methods(Git::Branch, stashes: 'use Git::Base#stash_list instead')
38
48
  ```
39
- sudo gem install git
49
+
50
+ The default action when using deprecated items (methods, classes, etc.) is to output
51
+ a **DEPRECATION WARNING** to `$stderr` like the following:
52
+
53
+ ```text
54
+ DEPRECATION WARNING: stashes is deprecated and will be removed from git 2.0.0 (use Git::Base.stash_list instead)
40
55
  ```
41
56
 
42
- ## Code Status
57
+ The action taken when a deprecated item is used is defined by setting the behavior
58
+ on the deprecation object:
59
+
60
+ ```ruby
61
+ # Log all deprecation warnings to $stderr (the default)
62
+ Git.deprecation = :stderr
43
63
 
44
- * [![Build Status](https://github.com/ruby-git/ruby-git/workflows/CI/badge.svg?branch=master)](https://github.com/ruby-git/ruby-git/actions?query=workflow%3ACI)
45
- * [![Code Climate](https://codeclimate.com/github/ruby-git/ruby-git.png)](https://codeclimate.com/github/ruby-git/ruby-git)
46
- * [![Gem Version](https://badge.fury.io/rb/git.svg)](https://badge.fury.io/rb/git)
64
+ # Raise an ActiveSupport::DeprecationException
65
+ Git.deprecation = :raise
66
+
67
+ # Do nothing
68
+ Git.deprecation = :silence
69
+ ```
70
+
71
+ See [ActiveSupport::Deprecation](https://api.rubyonrails.org/classes/ActiveSupport/Deprecation.html)
72
+ for more details on how to use deprecations.
47
73
 
48
74
  ## Major Objects
49
75
 
@@ -197,6 +223,8 @@ g.show('v2.8', 'README.md')
197
223
  Git.ls_remote('https://github.com/ruby-git/ruby-git.git') # returns a hash containing the available references of the repo.
198
224
  Git.ls_remote('/path/to/local/repo')
199
225
  Git.ls_remote() # same as Git.ls_remote('.')
226
+
227
+ Git.default_branch('https://github.com/ruby-git/ruby-git') #=> 'master'
200
228
  ```
201
229
 
202
230
  And here are the operations that will need to write to your git repository.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ task :test do
18
18
  end
19
19
  default_tasks << :test
20
20
 
21
- unless RUBY_PLATFORM == 'java'
21
+ unless RUBY_PLATFORM == 'java' || RUBY_ENGINE == 'truffleruby'
22
22
  #
23
23
  # YARD documentation for this project can NOT be built with JRuby.
24
24
  # This project uses the redcarpet gem which can not be installed on JRuby.
data/git.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
27
27
  s.requirements = ['git 1.6.0.0, or greater']
28
28
 
29
+ s.add_runtime_dependency 'activesupport', '>= 4.0.0'
29
30
  s.add_runtime_dependency 'addressable', '~> 2.8'
30
31
  s.add_runtime_dependency 'rchardet', '~> 1.8'
31
32
 
data/lib/git/base.rb CHANGED
@@ -24,6 +24,11 @@ module Git
24
24
  new(new_options)
25
25
  end
26
26
 
27
+ # (see Git.default_branch)
28
+ def self.repository_default_branch(repository, options = {})
29
+ Git::Lib.new(nil, options[:log]).repository_default_branch(repository)
30
+ end
31
+
27
32
  # Returns (and initialize if needed) a Git::Config instance
28
33
  #
29
34
  # @return [Git::Config] the current config instance.
@@ -369,10 +374,23 @@ module Git
369
374
  self.lib.fetch(remote, opts)
370
375
  end
371
376
 
372
- # pushes changes to a remote repository - easiest if this is a cloned repository,
373
- # otherwise you may have to run something like this first to setup the push parameters:
377
+ # Push changes to a remote repository
378
+ #
379
+ # @overload push(remote = nil, branch = nil, options = {})
380
+ # @param remote [String] the remote repository to push to
381
+ # @param branch [String] the branch to push
382
+ # @param options [Hash] options to pass to the push command
383
+ #
384
+ # @option opts [Boolean] :mirror (false) Push all refs under refs/heads/, refs/tags/ and refs/remotes/
385
+ # @option opts [Boolean] :delete (false) Delete refs that don't exist on the remote
386
+ # @option opts [Boolean] :force (false) Force updates
387
+ # @option opts [Boolean] :tags (false) Push all refs under refs/tags/
388
+ # @option opts [Array, String] :push_options (nil) Push options to transmit
389
+ #
390
+ # @return [Void]
374
391
  #
375
- # @git.config('remote.remote-name.push', 'refs/heads/master:refs/heads/master')
392
+ # @raise [Git::FailedError] if the push fails
393
+ # @raise [ArgumentError] if a branch is given without a remote
376
394
  #
377
395
  def push(*args, **options)
378
396
  self.lib.push(*args, **options)
data/lib/git/lib.rb CHANGED
@@ -124,6 +124,24 @@ module Git
124
124
  base_opts
125
125
  end
126
126
 
127
+ # Returns the name of the default branch of the given repository
128
+ #
129
+ # @param repository [URI, Pathname, String] The (possibly remote) repository to clone from
130
+ #
131
+ # @return [String] the name of the default branch
132
+ #
133
+ def repository_default_branch(repository)
134
+ output = command('ls-remote', '--symref', '--', repository, 'HEAD')
135
+
136
+ match_data = output.match(%r{^ref: refs/remotes/origin/(?<default_branch>[^\t]+)\trefs/remotes/origin/HEAD$})
137
+ return match_data[:default_branch] if match_data
138
+
139
+ match_data = output.match(%r{^ref: refs/heads/(?<default_branch>[^\t]+)\tHEAD$})
140
+ return match_data[:default_branch] if match_data
141
+
142
+ raise 'Unable to determine the default branch'
143
+ end
144
+
127
145
  ## READ COMMANDS ##
128
146
 
129
147
  #
@@ -320,7 +338,7 @@ module Git
320
338
  end
321
339
 
322
340
  def ls_tree(sha)
323
- data = {'blob' => {}, 'tree' => {}}
341
+ data = { 'blob' => {}, 'tree' => {}, 'commit' => {} }
324
342
 
325
343
  command_lines('ls-tree', sha).each do |line|
326
344
  (info, filenm) = line.split("\t")
@@ -964,6 +982,7 @@ module Git
964
982
  arr_opts << '--mirror' if opts[:mirror]
965
983
  arr_opts << '--delete' if opts[:delete]
966
984
  arr_opts << '--force' if opts[:force] || opts[:f]
985
+ Array(opts[:push_option]).each { |o| arr_opts << '--push-option' << o } if opts[:push_option]
967
986
  arr_opts << remote if remote
968
987
  arr_opts_with_branch = arr_opts.dup
969
988
  arr_opts_with_branch << branch if branch
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='1.16.0'
4
+ VERSION='1.17.0'
5
5
  end
data/lib/git.rb CHANGED
@@ -1,7 +1,32 @@
1
- # Add the directory containing this file to the start of the load path if it
2
- # isn't there already.
3
- $:.unshift(File.dirname(__FILE__)) unless
4
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ require 'active_support/deprecation'
2
+
3
+ module Git
4
+ # An object used to manage deprecations
5
+ #
6
+ # A ActiveSupport::Deprecation object used to manage the deprecations scheduled
7
+ # to be removed in the next major release of the `git`` gem.
8
+ #
9
+ # @example Deprecate a method
10
+ # Git.deprecation.deprecate_methods(Git::Branch, stashes: 'use Git::Base#stash_list instead')
11
+ #
12
+ # @example Set the deprecation behavior
13
+ # # Log all deprecation warnings to $stderr (the default)
14
+ # Git.deprecation.behavior = :stderr
15
+ #
16
+ # # Raise an ActiveSupport::DeprecationException
17
+ # Git.deprecation.behavior = :raise
18
+ #
19
+ # # Do nothing
20
+ # Git.deprecation.behavior = :raise
21
+ #
22
+ # @see https://api.rubyonrails.org/classes/ActiveSupport/Deprecation.html ActiveSupport::Deprecation
23
+ #
24
+ # @return [ActiveSupport::Deprecation]
25
+ #
26
+ def self.deprecation
27
+ @deprecation ||= ActiveSupport::Deprecation.new('2.0.0', 'git')
28
+ end
29
+ end
5
30
 
6
31
  require 'git/author'
7
32
  require 'git/base'
@@ -175,6 +200,46 @@ module Git
175
200
  Base.clone(repository_url, directory, options)
176
201
  end
177
202
 
203
+ # Returns the name of the default branch of the given repository
204
+ #
205
+ # @example with a URI string
206
+ # Git.default_branch('https://github.com/ruby-git/ruby-git') # => 'master'
207
+ # Git.default_branch('https://github.com/rspec/rspec-core') # => 'main'
208
+ #
209
+ # @example with a URI object
210
+ # repository_uri = URI('https://github.com/ruby-git/ruby-git')
211
+ # Git.default_branch(repository_uri) # => 'master'
212
+ #
213
+ # @example with a local repository
214
+ # Git.default_branch('.') # => 'master'
215
+ #
216
+ # @example with a local repository Pathname
217
+ # repository_path = Pathname('.')
218
+ # Git.default_branch(repository_path) # => 'master'
219
+ #
220
+ # @example with the logging option
221
+ # logger = Logger.new(STDOUT, level: Logger::INFO)
222
+ # Git.default_branch('.', log: logger) # => 'master'
223
+ # I, [2022-04-13T16:01:33.221596 #18415] INFO -- : git '-c' 'core.quotePath=true' '-c' 'color.ui=false' ls-remote '--symref' '--' '.' 'HEAD' 2>&1
224
+ #
225
+ # @param repository [URI, Pathname, String] The (possibly remote) repository to get the default branch name for
226
+ #
227
+ # See [GIT URLS](https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a)
228
+ # for more information.
229
+ #
230
+ # @param [Hash] options The options for this command (see list of valid
231
+ # options below)
232
+ #
233
+ # @option options [Logger] :log A logger to use for Git operations. Git
234
+ # commands are logged at the `:info` level. Additional logging is done
235
+ # at the `:debug` level.
236
+ #
237
+ # @return [String] the name of the default branch
238
+ #
239
+ def self.default_branch(repository, options = {})
240
+ Base.repository_default_branch(repository, options)
241
+ end
242
+
178
243
  # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
179
244
  # is specified) into the +name+ directory, then remove all traces of git from the
180
245
  # directory.
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.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: 2023-03-04 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: addressable
15
29
  requirement: !ruby/object:Gem::Requirement