git 1.16.0 → 1.17.1

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: 6c893cd566fdfc36e3f6ea4fc742d7665b5daf14c299ff1acd19c40de49e3eb2
4
+ data.tar.gz: cc08038a56beb1ba3195600e80a666d66a7d58dd1abb16d4e5282718cd067bcd
5
5
  SHA512:
6
- metadata.gz: 57db3b512e1d30130f1ab8bf9f77a701591c4c05c8c9fe35e9d047329cc7fe08b6e17c93d276bcfbfcb3e5c92a8dcb48cc571d513a7a981d69989eac7daea957
7
- data.tar.gz: ee2b51658bda3767a01729888c60b677d79d69b75fadb8659a6d56144e82f51e21da817f7f310b1af0be9baedda37923315adac10ad7a65be1624b6ecb0628fb
6
+ metadata.gz: 82e6441de9ff798080bddc79ca411386a7c20b5d4208d584fa12925777bb66de1ddc3532d512087eb815c083184d30cf445ef097a47cc8a8089027b1498820c1
7
+ data.tar.gz: f0657f1ee3f3142612fdd904bc8649207e6bc1a115cbb3a969105c99a0fff15c0d1851b755c527351f06b462e6ff22b98e85ed4139acdcdcf949c434417becb2
data/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v1.17.1 (2023-03-06)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.17.0..v1.17.1)
11
+
12
+ Changes since v1.17.0:
13
+
14
+ * 774e Revert introduction of ActiveSupport dependency (#649)
15
+
16
+ ## v1.17.0 (2023-03-05)
17
+
18
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.16.0..v1.17.0)
19
+
20
+ Changes since v1.16.0:
21
+
22
+ * 1311 Add deprecation mechanism (introduces runtime dependency on ActiveSupport) (#645)
23
+ * 50b8 Add the push_option option for Git::Lib#push (#644)
24
+ * a799 Make Git::Base#ls_tree handle commit objects (#643)
25
+ * 6db3 Implememt Git.default_branch (#571)
26
+
8
27
  ## v1.16.0 (2023-03-03)
9
28
 
10
29
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.15.0..v1.16.0)
data/README.md CHANGED
@@ -197,6 +197,8 @@ g.show('v2.8', 'README.md')
197
197
  Git.ls_remote('https://github.com/ruby-git/ruby-git.git') # returns a hash containing the available references of the repo.
198
198
  Git.ls_remote('/path/to/local/repo')
199
199
  Git.ls_remote() # same as Git.ls_remote('.')
200
+
201
+ Git.default_branch('https://github.com/ruby-git/ruby-git') #=> 'master'
200
202
  ```
201
203
 
202
204
  And here are the operations that will need to write to your git repository.
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.1'
5
5
  end
data/lib/git.rb CHANGED
@@ -175,6 +175,46 @@ module Git
175
175
  Base.clone(repository_url, directory, options)
176
176
  end
177
177
 
178
+ # Returns the name of the default branch of the given repository
179
+ #
180
+ # @example with a URI string
181
+ # Git.default_branch('https://github.com/ruby-git/ruby-git') # => 'master'
182
+ # Git.default_branch('https://github.com/rspec/rspec-core') # => 'main'
183
+ #
184
+ # @example with a URI object
185
+ # repository_uri = URI('https://github.com/ruby-git/ruby-git')
186
+ # Git.default_branch(repository_uri) # => 'master'
187
+ #
188
+ # @example with a local repository
189
+ # Git.default_branch('.') # => 'master'
190
+ #
191
+ # @example with a local repository Pathname
192
+ # repository_path = Pathname('.')
193
+ # Git.default_branch(repository_path) # => 'master'
194
+ #
195
+ # @example with the logging option
196
+ # logger = Logger.new(STDOUT, level: Logger::INFO)
197
+ # Git.default_branch('.', log: logger) # => 'master'
198
+ # I, [2022-04-13T16:01:33.221596 #18415] INFO -- : git '-c' 'core.quotePath=true' '-c' 'color.ui=false' ls-remote '--symref' '--' '.' 'HEAD' 2>&1
199
+ #
200
+ # @param repository [URI, Pathname, String] The (possibly remote) repository to get the default branch name for
201
+ #
202
+ # See [GIT URLS](https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a)
203
+ # for more information.
204
+ #
205
+ # @param [Hash] options The options for this command (see list of valid
206
+ # options below)
207
+ #
208
+ # @option options [Logger] :log A logger to use for Git operations. Git
209
+ # commands are logged at the `:info` level. Additional logging is done
210
+ # at the `:debug` level.
211
+ #
212
+ # @return [String] the name of the default branch
213
+ #
214
+ def self.default_branch(repository, options = {})
215
+ Base.repository_default_branch(repository, options)
216
+ end
217
+
178
218
  # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
179
219
  # is specified) into the +name+ directory, then remove all traces of git from the
180
220
  # directory.
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: 1.16.0
4
+ version: 1.17.1
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
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable