git 1.18.0 → 1.19.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: b3c801f928c5b75999c02cecd054c0007a8e2f0460c27bc2b983741824d7b194
4
- data.tar.gz: 861bf03f14ed76dcf43acefcc8fe33787e202a9af52e7789d6d1660f84b4fc51
3
+ metadata.gz: 6f12803468275850ae680a4df2719890e8f84de95258f30dc898f817c7155d44
4
+ data.tar.gz: d24540a708538775d2ff1af495f04e7f42a297aaf790d0fe7b65ad71fe402550
5
5
  SHA512:
6
- metadata.gz: 4a4bf752eb3332572f968ea23a5cc4a4e4547279f60ce2341d6d6d815f5d9f4cbd17237b266c9cd2850c77c2c9a189ff98034af5385333632f557e765cb7b64a
7
- data.tar.gz: e678b9da94ccd8295347688d3dd3e400764da4af3f850ceaa0038e4ddb34804fd2cc3942119a9f66968b4c014fb07a040352c7b6494556298cebd826bc765fd8
6
+ metadata.gz: 15a09f75d84fb1ff7547403eb36c7342bee11fc1a23cf86e5eae224a2494da0e0bc60bf288c04924c87bdf6736f156f4d98f0468cf815d03b3291509ab234e8d
7
+ data.tar.gz: 7fe2633018ec2e38805b987271cc033d023b1a32b429cf2f75e88d1ac1c86c913689fc46806ea49c38fce66005215b05fc700ca3adc925afd0b3dcd3fefdc091
data/CHANGELOG.md CHANGED
@@ -5,6 +5,29 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v1.19.1 (2024-01-13)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.19.0..v1.19.1)
11
+
12
+ Changes since v1.19.0:
13
+
14
+ * f97c57c Announce the 2.0.0 pre-release (#682)
15
+
16
+ ## v1.19.0 (2023-12-28)
17
+
18
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.18.0..v1.19.0)
19
+
20
+ Changes since v1.18.0:
21
+
22
+ * 3bdb280 Add option to push all branches to a remote repo at one time (#678)
23
+ * b0d89ac Remove calls to Dir.chdir (#673)
24
+ * e64c2f6 Refactor tests for read_tree, write_tree, and commit_tree (#679)
25
+ * 0bb965d Explicitly name remote tracking branch in test (#676)
26
+ * 8481f8c Document how to delete a remote branch (#672)
27
+ * dce6816 show .log example with count in README, fixes #667 (#668)
28
+ * b1799f6 Update test of 'git worktree add' with no commits (#670)
29
+ * dd5a24d Add --filter to Git.clone for partial clones (#663)
30
+
8
31
  ## v1.18.0 (2023-03-19)
9
32
 
10
33
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.17.2..v1.18.0)
data/README.md CHANGED
@@ -5,11 +5,41 @@
5
5
 
6
6
  # The Git Gem
7
7
 
8
- The Git Gem provides an API that can be used to create, read, and manipulate
9
- Git repositories by wrapping system calls to the `git` binary. The API can be
10
- used for working with Git in complex interactions including branching and
11
- merging, object inspection and manipulation, history, patch generation and
12
- more.
8
+ [![Gem Version](https://badge.fury.io/rb/git.svg)](https://badge.fury.io/rb/git)
9
+ [![Documentation](https://img.shields.io/badge/Documentation-Latest-green)](https://rubydoc.info/gems/git/)
10
+ [![Change Log](https://img.shields.io/badge/CHANGELOG-Latest-green)](https://rubydoc.info/gems/git/file/CHANGELOG.md)
11
+ [![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)
12
+ [![Code Climate](https://codeclimate.com/github/ruby-git/ruby-git.png)](https://codeclimate.com/github/ruby-git/ruby-git)
13
+
14
+ The [git gem](https://rubygems.org/gems/git) provides an API that can be used to
15
+ create, read, and manipulate Git repositories by wrapping system calls to the `git`
16
+ command line. The API can be used for working with Git in complex interactions
17
+ including branching and merging, object inspection and manipulation, history, patch
18
+ generation and more.
19
+
20
+ ## v2.0.0 pre-release
21
+
22
+ git 2.0.0 is available as a pre-release version for testing! Please give it a try.
23
+
24
+ **JRuby on Windows is not yet supported by the 2.x release line. Users running JRuby
25
+ on Windows should continue to use the 1.x release line.**
26
+
27
+ The changes coming in this major release include:
28
+
29
+ * Create a policy of supported Ruby versions to support only non-EOL Ruby versions
30
+ * Create a policy of supported Git CLI versions (released 2020-12-25)
31
+ * Update the required Ruby version to at least 3.0 (released 2020-07-27)
32
+ * Update the required Git command line version to at least 2.28
33
+ * Update how CLI commands are called to use the [process_executer](https://github.com/main-branch/process_executer)
34
+ gem which is built on top of [Kernel.spawn](https://ruby-doc.org/3.3.0/Kernel.html#method-i-spawn).
35
+ See [PR #617](https://github.com/ruby-git/ruby-git/pull/617) for more details
36
+ on the motivation for this implementation.
37
+
38
+ The tentative plan is to release `2.0.0` near the end of March 2024 depending on
39
+ the feedback received during the pre-release period.
40
+
41
+ The `master` branch will be used for `2.x` development. If needed, fixes for `1.x`
42
+ version will be done on the `v1` branch.
13
43
 
14
44
  ## Homepage
15
45
 
@@ -41,9 +71,6 @@ sudo gem install git
41
71
 
42
72
  ## Code Status
43
73
 
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)
47
74
 
48
75
  ## Major Objects
49
76
 
@@ -113,6 +140,7 @@ g.repo
113
140
  g.dir
114
141
 
115
142
  g.log # returns a Git::Log object, which is an Enumerator of Git::Commit objects
143
+ g.log(200)
116
144
  g.log.since('2 weeks ago')
117
145
  g.log.between('v2.5', 'v2.6')
118
146
  g.log.each {|l| puts l.sha }
@@ -236,6 +264,9 @@ g.dir #=> /tmp/clone/ruby-git-clean
236
264
  g.config('user.name', 'Scott Chacon')
237
265
  g.config('user.email', 'email@email.com')
238
266
 
267
+ # Clone can take a filter to tell the serve to send a partial clone
268
+ g = Git.clone(git_url, name, :path => path, :filter => 'tree:0')
269
+
239
270
  # Clone can take an optional logger
240
271
  logger = Logger.new
241
272
  g = Git.clone(git_url, NAME, :log => logger)
@@ -282,6 +313,9 @@ g.branch('new_branch').delete
282
313
  g.branch('existing_branch').checkout
283
314
  g.branch('master').contains?('existing_branch')
284
315
 
316
+ # delete remote branch
317
+ g.push('origin', 'remote_branch_name', force: true, delete: true)
318
+
285
319
  g.checkout('new_branch')
286
320
  g.checkout('new_branch', new_branch: true, start_point: 'master')
287
321
  g.checkout(g.branch('new_branch'))
@@ -335,6 +369,12 @@ g.repack
335
369
  g.push
336
370
  g.push(g.remote('name'))
337
371
 
372
+ # delete remote branch
373
+ g.push('origin', 'remote_branch_name', force: true, delete: true)
374
+
375
+ # push all branches to remote at one time
376
+ g.push('origin', all: true)
377
+
338
378
  g.worktree('/tmp/new_worktree').add
339
379
  g.worktree('/tmp/new_worktree', 'branch1').add
340
380
  g.worktree('/tmp/new_worktree').remove
data/git.gemspec CHANGED
@@ -9,17 +9,19 @@ Gem::Specification.new do |s|
9
9
  s.name = 'git'
10
10
  s.summary = 'An API to create, read, and manipulate Git repositories'
11
11
  s.description = <<~DESCRIPTION
12
- The Git Gem provides an API that can be used to create, read, and manipulate
13
- Git repositories by wrapping system calls to the `git` binary. The API can be
14
- used for working with Git in complex interactions including branching and
15
- merging, object inspection and manipulation, history, patch generation and
16
- more.
12
+ The git gem provides an API that can be used to
13
+ create, read, and manipulate Git repositories by wrapping system calls to the git
14
+ command line. The API can be used for working with Git in complex interactions
15
+ including branching and merging, object inspection and manipulation, history, patch
16
+ generation and more.
17
17
  DESCRIPTION
18
18
  s.version = Git::VERSION
19
19
 
20
+
20
21
  s.metadata['homepage_uri'] = s.homepage
21
22
  s.metadata['source_code_uri'] = s.homepage
22
- s.metadata['changelog_uri'] = 'http://rubydoc.info/gems/git/file.CHANGELOG.html'
23
+ s.metadata['changelog_uri'] = "https://rubydoc.info/gems/#{s.name}/#{s.version}/file/CHANGELOG.md"
24
+ s.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{s.name}/#{s.version}"
23
25
 
24
26
  s.require_paths = ['lib']
25
27
  s.required_ruby_version = '>= 2.3'
@@ -32,6 +34,7 @@ Gem::Specification.new do |s|
32
34
  s.add_development_dependency 'bump', '~> 0.10'
33
35
  s.add_development_dependency 'create_github_release', '~> 0.2'
34
36
  s.add_development_dependency 'minitar', '~> 0.9'
37
+ s.add_development_dependency 'mocha', '~> 2.1'
35
38
  s.add_development_dependency 'rake', '~> 13.0'
36
39
  s.add_development_dependency 'test-unit', '~> 3.3'
37
40
 
data/lib/git/base.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'git/base/factory'
2
2
  require 'logger'
3
+ require 'open3'
3
4
 
4
5
  module Git
5
6
  # Git::Base is the main public interface for interacting with Git commands.
@@ -66,11 +67,11 @@ module Git
66
67
  def self.root_of_worktree(working_dir)
67
68
  result = working_dir
68
69
  status = nil
69
- Dir.chdir(working_dir) do
70
- git_cmd = "#{Git::Base.config.binary_path} -c core.quotePath=true -c color.ui=false rev-parse --show-toplevel 2>&1"
71
- result = `#{git_cmd}`.chomp
72
- status = $?
73
- end
70
+
71
+ git_cmd = "#{Git::Base.config.binary_path} -c core.quotePath=true -c color.ui=false rev-parse --show-toplevel 2>&1"
72
+ result, status = Open3.capture2(git_cmd, chdir: File.expand_path(working_dir))
73
+ result = result.chomp
74
+
74
75
  raise ArgumentError, "'#{working_dir}' is not in a git working tree" unless status.success?
75
76
  result
76
77
  end
data/lib/git/lib.rb CHANGED
@@ -2,6 +2,7 @@ require 'git/failed_error'
2
2
  require 'logger'
3
3
  require 'tempfile'
4
4
  require 'zlib'
5
+ require 'open3'
5
6
 
6
7
  module Git
7
8
  class Lib
@@ -84,6 +85,7 @@ module Git
84
85
  # :bare:: no working directory
85
86
  # :branch:: name of branch to track (rather than 'master')
86
87
  # :depth:: the number of commits back to pull
88
+ # :filter:: specify partial clone
87
89
  # :origin:: name of remote (same as remote)
88
90
  # :path:: directory where the repo will be cloned
89
91
  # :remote:: name of remote (rather than 'origin')
@@ -101,6 +103,7 @@ module Git
101
103
  arr_opts << '--bare' if opts[:bare]
102
104
  arr_opts << '--branch' << opts[:branch] if opts[:branch]
103
105
  arr_opts << '--depth' << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0
106
+ arr_opts << '--filter' << opts[:filter] if opts[:filter]
104
107
  Array(opts[:config]).each { |c| arr_opts << '--config' << c }
105
108
  arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin]
106
109
  arr_opts << '--recursive' if opts[:recursive]
@@ -439,7 +442,10 @@ module Git
439
442
  def list_files(ref_dir)
440
443
  dir = File.join(@git_dir, 'refs', ref_dir)
441
444
  files = []
442
- Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } } rescue nil
445
+ begin
446
+ files = Dir.glob('**/*', base: dir).select { |f| File.file?(File.join(dir, f)) }
447
+ rescue
448
+ end
443
449
  files
444
450
  end
445
451
 
@@ -577,15 +583,7 @@ module Git
577
583
  end
578
584
 
579
585
  def config_get(name)
580
- do_get = Proc.new do |path|
581
- command('config', '--get', name)
582
- end
583
-
584
- if @git_dir
585
- Dir.chdir(@git_dir, &do_get)
586
- else
587
- do_get.call
588
- end
586
+ command('config', '--get', name, chdir: @git_dir)
589
587
  end
590
588
 
591
589
  def global_config_get(name)
@@ -593,15 +591,7 @@ module Git
593
591
  end
594
592
 
595
593
  def config_list
596
- build_list = Proc.new do |path|
597
- parse_config_list command_lines('config', '--list')
598
- end
599
-
600
- if @git_dir
601
- Dir.chdir(@git_dir, &build_list)
602
- else
603
- build_list.call
604
- end
594
+ parse_config_list command_lines('config', '--list', chdir: @git_dir)
605
595
  end
606
596
 
607
597
  def global_config_list
@@ -982,7 +972,9 @@ module Git
982
972
  arr_opts = []
983
973
  arr_opts << '--mirror' if opts[:mirror]
984
974
  arr_opts << '--delete' if opts[:delete]
985
- arr_opts << '--force' if opts[:force] || opts[:f]
975
+ arr_opts << '--force' if opts[:force] || opts[:f]
976
+ arr_opts << '--all' if opts[:all] && remote
977
+
986
978
  Array(opts[:push_option]).each { |o| arr_opts << '--push-option' << o } if opts[:push_option]
987
979
  arr_opts << remote if remote
988
980
  arr_opts_with_branch = arr_opts.dup
@@ -1041,7 +1033,7 @@ module Git
1041
1033
  arr_opts = []
1042
1034
  arr_opts << tree
1043
1035
  arr_opts << '-p' << opts[:parent] if opts[:parent]
1044
- arr_opts += [opts[:parents]].map { |p| ['-p', p] }.flatten if opts[:parents]
1036
+ arr_opts += Array(opts[:parents]).map { |p| ['-p', p] }.flatten if opts[:parents]
1045
1037
  command('commit-tree', *arr_opts, redirect: "< #{escape t.path}")
1046
1038
  end
1047
1039
 
@@ -1106,6 +1098,22 @@ module Git
1106
1098
  version_parts.fill(0, version_parts.length...3)
1107
1099
  end
1108
1100
 
1101
+ # Returns current_command_version <=> other_version
1102
+ #
1103
+ # @example
1104
+ # lib.current_command_version #=> [2, 42, 0]
1105
+ #
1106
+ # lib.compare_version_to(2, 41, 0) #=> 1
1107
+ # lib.compare_version_to(2, 42, 0) #=> 0
1108
+ # lib.compare_version_to(2, 43, 0) #=> -1
1109
+ #
1110
+ # @param other_version [Array<Object>] the other version to compare to
1111
+ # @return [Integer] -1 if this version is less than other_version, 0 if equal, or 1 if greater than
1112
+ #
1113
+ def compare_version_to(*other_version)
1114
+ current_command_version <=> other_version
1115
+ end
1116
+
1109
1117
  def required_command_version
1110
1118
  [1, 6]
1111
1119
  end
@@ -1130,8 +1138,8 @@ module Git
1130
1138
  # @return [<String>] the names of the EVN variables involved in the git commands
1131
1139
  ENV_VARIABLE_NAMES = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_SSH']
1132
1140
 
1133
- def command_lines(cmd, *opts)
1134
- cmd_op = command(cmd, *opts)
1141
+ def command_lines(cmd, *opts, chdir: nil)
1142
+ cmd_op = command(cmd, *opts, chdir: chdir)
1135
1143
  if cmd_op.encoding.name != "UTF-8"
1136
1144
  op = cmd_op.encode("UTF-8", "binary", :invalid => :replace, :undef => :replace)
1137
1145
  else
@@ -1177,7 +1185,7 @@ module Git
1177
1185
  restore_git_system_env_variables()
1178
1186
  end
1179
1187
 
1180
- def command(*cmd, redirect: '', chomp: true, &block)
1188
+ def command(*cmd, redirect: '', chomp: true, chdir: nil, &block)
1181
1189
  Git::Lib.warn_if_old_command(self)
1182
1190
 
1183
1191
  raise 'cmd can not include a nested array' if cmd.any? { |o| o.is_a? Array }
@@ -1202,8 +1210,7 @@ module Git
1202
1210
 
1203
1211
  with_custom_env_variables do
1204
1212
  command_thread = Thread.new do
1205
- output = run_command(git_cmd, &block)
1206
- status = $?
1213
+ output, status = run_command(git_cmd, chdir, &block)
1207
1214
  end
1208
1215
  command_thread.join
1209
1216
  end
@@ -1285,10 +1292,17 @@ module Git
1285
1292
  arr_opts
1286
1293
  end
1287
1294
 
1288
- def run_command(git_cmd, &block)
1289
- return IO.popen(git_cmd, &block) if block_given?
1295
+ def run_command(git_cmd, chdir=nil, &block)
1296
+ block ||= Proc.new do |io|
1297
+ io.readlines.map { |l| Git::EncodingUtils.normalize_encoding(l) }.join
1298
+ end
1299
+
1300
+ opts = {}
1301
+ opts[:chdir] = File.expand_path(chdir) if chdir
1290
1302
 
1291
- `#{git_cmd}`.lines.map { |l| Git::EncodingUtils.normalize_encoding(l) }.join
1303
+ Open3.popen2(git_cmd, opts) do |stdin, stdout, wait_thr|
1304
+ [block.call(stdout), wait_thr.value]
1305
+ end
1292
1306
  end
1293
1307
 
1294
1308
  def escape(s)
data/lib/git/status.rb CHANGED
@@ -172,13 +172,12 @@ module Git
172
172
  def fetch_untracked
173
173
  ignore = @base.lib.ignored_files
174
174
 
175
- Dir.chdir(@base.dir.path) do
176
- Dir.glob('**/*', File::FNM_DOTMATCH) do |file|
177
- next if @files[file] || File.directory?(file) ||
178
- ignore.include?(file) || file =~ %r{^.git\/.+}
175
+ root_dir = @base.dir.path
176
+ Dir.glob('**/*', File::FNM_DOTMATCH, base: root_dir) do |file|
177
+ next if @files[file] || File.directory?(File.join(root_dir, file)) ||
178
+ ignore.include?(file) || file =~ %r{^.git\/.+}
179
179
 
180
- @files[file] = { path: file, untracked: true }
181
- end
180
+ @files[file] = { path: file, untracked: true }
182
181
  end
183
182
  end
184
183
 
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.18.0'
4
+ VERSION='1.19.1'
5
5
  end
data/lib/git.rb CHANGED
@@ -139,6 +139,9 @@ module Git
139
139
  # @option options [Integer] :depth Create a shallow clone with a history
140
140
  # truncated to the specified number of commits.
141
141
  #
142
+ # @option options [String] :filter Request that the server send a partial
143
+ # clone according to the given filter
144
+ #
142
145
  # @option options [Logger] :log A logger to use for Git operations. Git
143
146
  # commands are logged at the `:info` level. Additional logging is done
144
147
  # at the `:debug` level.
@@ -241,7 +244,7 @@ module Git
241
244
  options.delete(:remote)
242
245
  repo = clone(repository, name, {:depth => 1}.merge(options))
243
246
  repo.checkout("origin/#{options[:branch]}") if options[:branch]
244
- Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
247
+ FileUtils.rm_r File.join(repo.dir.to_s, '.git')
245
248
  end
246
249
 
247
250
  # Same as g.config, but forces it to be at the global level
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.18.0
4
+ version: 1.19.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-19 00:00:00.000000000 Z
11
+ date: 2024-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -157,11 +171,11 @@ dependencies:
157
171
  - !ruby/object:Gem::Version
158
172
  version: '0.9'
159
173
  description: |
160
- The Git Gem provides an API that can be used to create, read, and manipulate
161
- Git repositories by wrapping system calls to the `git` binary. The API can be
162
- used for working with Git in complex interactions including branching and
163
- merging, object inspection and manipulation, history, patch generation and
164
- more.
174
+ The git gem provides an API that can be used to
175
+ create, read, and manipulate Git repositories by wrapping system calls to the git
176
+ command line. The API can be used for working with Git in complex interactions
177
+ including branching and merging, object inspection and manipulation, history, patch
178
+ generation and more.
165
179
  email: schacon@gmail.com
166
180
  executables: []
167
181
  extensions: []
@@ -218,7 +232,8 @@ licenses:
218
232
  metadata:
219
233
  homepage_uri: http://github.com/ruby-git/ruby-git
220
234
  source_code_uri: http://github.com/ruby-git/ruby-git
221
- changelog_uri: http://rubydoc.info/gems/git/file.CHANGELOG.html
235
+ changelog_uri: https://rubydoc.info/gems/git/1.19.1/file/CHANGELOG.md
236
+ documentation_uri: https://rubydoc.info/gems/git/1.19.1
222
237
  post_install_message:
223
238
  rdoc_options: []
224
239
  require_paths:
@@ -235,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
250
  version: '0'
236
251
  requirements:
237
252
  - git 1.6.0.0, or greater
238
- rubygems_version: 3.4.1
253
+ rubygems_version: 3.5.3
239
254
  signing_key:
240
255
  specification_version: 4
241
256
  summary: An API to create, read, and manipulate Git repositories