git 2.1.0 → 2.1.1

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: cf601afe6ddef5cc504f0a350bd9595feb76cc95822bd65716d6b5cecf2d324d
4
- data.tar.gz: 5f334a391220774ab0fea9c789a87fe3a45d9de55e0745d87f59c0bc9a52e5a9
3
+ metadata.gz: b171ab737c87e925d5752b52f2f05bdd2361592624d88b8db8db380dde051019
4
+ data.tar.gz: d7b3b7cdaba4996288c4c0e8fffe7819da6c0933ade68ca810d9fb3519d5cda0
5
5
  SHA512:
6
- metadata.gz: 20133b00f0f50ccc00dc1bd4bb88107911ff5f438e127b804270752c43029e2447b15a5212c701a24a49a6f98d7b12359cb3326924ea3dadf631408b316e626e
7
- data.tar.gz: 11ca7ae94de18e0b3d4aad99d315c2b973a8e2521ee24a935e5236fdc91eace943074ad388889a09ef4d8e33e2a4b1355d2590fe16fe0a1eda05357e1a315290
6
+ metadata.gz: '08dd5a4ea7b07230642e2dd87fca85ea634890f4700b77a996b3ff4443fc62d3c11a230c082c4d5b2c45c6c7d6916d9b98ce7362676e72d1a4bdd6f0fe2043e6'
7
+ data.tar.gz: 568111f5579b6b1728974dbfa12dc4d742f3715e951645dbed9a54d91399492157b77659b2e956ee995c142c8dbb01f3ee07357fb4db2a9c2bd0e1870e83dc79
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v2.1.1 (2024-06-01)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.1.0..v2.1.1)
11
+
12
+ Changes since v2.1.0:
13
+
14
+ * 6ce3d4d Handle ignored files with quoted (non-ASCII) filenames
15
+ * dd8e8d4 Supply all of the _specific_ color options too
16
+ * 749a72d Memoize all of the significant calls in Git::Status
17
+ * 2bacccc When core.ignoreCase, check for untracked files case-insensitively
18
+ * 7758ee4 When core.ignoreCase, check for deleted files case-insensitively
19
+ * 993eb78 When core.ignoreCase, check for added files case-insensitively
20
+ * d943bf4 When core.ignoreCase, check for changed files case-insensitively
21
+
8
22
  ## v2.1.0 (2024-05-31)
9
23
 
10
24
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.0.1..v2.1.0)
data/lib/git/base.rb CHANGED
@@ -309,6 +309,13 @@ module Git
309
309
  self.object('HEAD').grep(string, path_limiter, opts)
310
310
  end
311
311
 
312
+ # List the files in the worktree that are ignored by git
313
+ # @return [Array<String>] the list of ignored files relative to teh root of the worktree
314
+ #
315
+ def ignored_files
316
+ self.lib.ignored_files
317
+ end
318
+
312
319
  # removes file(s) from the git repository
313
320
  def rm(path = '.', opts = {})
314
321
  self.lib.rm(path, opts)
@@ -3,7 +3,7 @@
3
3
  module Git
4
4
  # Represents an escaped Git path string
5
5
  #
6
- # Git commands that output paths (e.g. ls-files, diff), will escape usual
6
+ # Git commands that output paths (e.g. ls-files, diff), will escape unusual
7
7
  # characters in the path with backslashes in the same way C escapes control
8
8
  # characters (e.g. \t for TAB, \n for LF, \\ for backslash) or bytes with values
9
9
  # larger than 0x80 (e.g. octal \302\265 for "micro" in UTF-8).
data/lib/git/lib.rb CHANGED
@@ -574,18 +574,52 @@ module Git
574
574
  diff_as_hash('diff-index', treeish)
575
575
  end
576
576
 
577
+ # List all files that are in the index
578
+ #
579
+ # @param location [String] the location to list the files from
580
+ #
581
+ # @return [Hash<String, Hash>] a hash of files in the index
582
+ # * key: file [String] the file path
583
+ # * value: file_info [Hash] the file information containing the following keys:
584
+ # * :path [String] the file path
585
+ # * :mode_index [String] the file mode
586
+ # * :sha_index [String] the file sha
587
+ # * :stage [String] the file stage
588
+ #
577
589
  def ls_files(location=nil)
578
590
  location ||= '.'
579
- hsh = {}
580
- command_lines('ls-files', '--stage', location).each do |line|
581
- (info, file) = line.split("\t")
582
- (mode, sha, stage) = info.split
583
- if file.start_with?('"') && file.end_with?('"')
584
- file = Git::EscapedPath.new(file[1..-2]).unescape
591
+ {}.tap do |files|
592
+ command_lines('ls-files', '--stage', location).each do |line|
593
+ (info, file) = line.split("\t")
594
+ (mode, sha, stage) = info.split
595
+ files[unescape_quoted_path(file)] = {
596
+ :path => file, :mode_index => mode, :sha_index => sha, :stage => stage
597
+ }
585
598
  end
586
- hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
587
599
  end
588
- hsh
600
+ end
601
+
602
+ # Unescape a path if it is quoted
603
+ #
604
+ # Git commands that output paths (e.g. ls-files, diff), will escape unusual
605
+ # characters.
606
+ #
607
+ # @example
608
+ # lib.unescape_if_quoted('"quoted_file_\\342\\230\\240"') # => 'quoted_file_☠'
609
+ # lib.unescape_if_quoted('unquoted_file') # => 'unquoted_file'
610
+ #
611
+ # @param path [String] the path to unescape if quoted
612
+ #
613
+ # @return [String] the unescaped path if quoted otherwise the original path
614
+ #
615
+ # @api private
616
+ #
617
+ def unescape_quoted_path(path)
618
+ if path.start_with?('"') && path.end_with?('"')
619
+ Git::EscapedPath.new(path[1..-2]).unescape
620
+ else
621
+ path
622
+ end
589
623
  end
590
624
 
591
625
  def ls_remote(location=nil, opts={})
@@ -606,7 +640,7 @@ module Git
606
640
  end
607
641
 
608
642
  def ignored_files
609
- command_lines('ls-files', '--others', '-i', '--exclude-standard')
643
+ command_lines('ls-files', '--others', '-i', '--exclude-standard').map { |f| unescape_quoted_path(f) }
610
644
  end
611
645
 
612
646
  def untracked_files
@@ -1223,6 +1257,14 @@ module Git
1223
1257
  global_opts << "--work-tree=#{@git_work_dir}" if !@git_work_dir.nil?
1224
1258
  global_opts << '-c' << 'core.quotePath=true'
1225
1259
  global_opts << '-c' << 'color.ui=false'
1260
+ global_opts << '-c' << 'color.advice=false'
1261
+ global_opts << '-c' << 'color.diff=false'
1262
+ global_opts << '-c' << 'color.grep=false'
1263
+ global_opts << '-c' << 'color.push=false'
1264
+ global_opts << '-c' << 'color.remote=false'
1265
+ global_opts << '-c' << 'color.showBranch=false'
1266
+ global_opts << '-c' << 'color.status=false'
1267
+ global_opts << '-c' << 'color.transport=false'
1226
1268
  end
1227
1269
  end
1228
1270
 
data/lib/git/status.rb CHANGED
@@ -22,7 +22,7 @@ module Git
22
22
  #
23
23
  # @return [Enumerable]
24
24
  def changed
25
- @files.select { |_k, f| f.type == 'M' }
25
+ @_changed ||= @files.select { |_k, f| f.type == 'M' }
26
26
  end
27
27
 
28
28
  #
@@ -34,7 +34,7 @@ module Git
34
34
  # changed?('lib/git.rb')
35
35
  # @return [Boolean]
36
36
  def changed?(file)
37
- changed.member?(file)
37
+ case_aware_include?(:changed, :lc_changed, file)
38
38
  end
39
39
 
40
40
  # Returns an Enumerable containing files that have been added.
@@ -42,7 +42,7 @@ module Git
42
42
  #
43
43
  # @return [Enumerable]
44
44
  def added
45
- @files.select { |_k, f| f.type == 'A' }
45
+ @_added ||= @files.select { |_k, f| f.type == 'A' }
46
46
  end
47
47
 
48
48
  # Determines whether the given file has been added to the repository
@@ -54,7 +54,7 @@ module Git
54
54
  # added?('lib/git.rb')
55
55
  # @return [Boolean]
56
56
  def added?(file)
57
- added.member?(file)
57
+ case_aware_include?(:added, :lc_added, file)
58
58
  end
59
59
 
60
60
  #
@@ -63,7 +63,7 @@ module Git
63
63
  #
64
64
  # @return [Enumerable]
65
65
  def deleted
66
- @files.select { |_k, f| f.type == 'D' }
66
+ @_deleted ||= @files.select { |_k, f| f.type == 'D' }
67
67
  end
68
68
 
69
69
  #
@@ -75,7 +75,7 @@ module Git
75
75
  # deleted?('lib/git.rb')
76
76
  # @return [Boolean]
77
77
  def deleted?(file)
78
- deleted.member?(file)
78
+ case_aware_include?(:deleted, :lc_deleted, file)
79
79
  end
80
80
 
81
81
  #
@@ -84,7 +84,7 @@ module Git
84
84
  #
85
85
  # @return [Enumerable]
86
86
  def untracked
87
- @files.select { |_k, f| f.untracked }
87
+ @_untracked ||= @files.select { |_k, f| f.untracked }
88
88
  end
89
89
 
90
90
  #
@@ -96,7 +96,7 @@ module Git
96
96
  # untracked?('lib/git.rb')
97
97
  # @return [Boolean]
98
98
  def untracked?(file)
99
- untracked.member?(file)
99
+ case_aware_include?(:untracked, :lc_untracked, file)
100
100
  end
101
101
 
102
102
  def pretty
@@ -264,5 +264,43 @@ module Git
264
264
  end
265
265
  end
266
266
  end
267
+
268
+ # It's worth noting that (like git itself) this gem will not behave well if
269
+ # ignoreCase is set inconsistently with the file-system itself. For details:
270
+ # https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase
271
+ def ignore_case?
272
+ return @_ignore_case if defined?(@_ignore_case)
273
+ @_ignore_case = @base.config('core.ignoreCase') == 'true'
274
+ rescue Git::FailedError
275
+ @_ignore_case = false
276
+ end
277
+
278
+ def downcase_keys(hash)
279
+ hash.map { |k, v| [k.downcase, v] }.to_h
280
+ end
281
+
282
+ def lc_changed
283
+ @_lc_changed ||= changed.transform_keys(&:downcase)
284
+ end
285
+
286
+ def lc_added
287
+ @_lc_added ||= added.transform_keys(&:downcase)
288
+ end
289
+
290
+ def lc_deleted
291
+ @_lc_deleted ||= deleted.transform_keys(&:downcase)
292
+ end
293
+
294
+ def lc_untracked
295
+ @_lc_untracked ||= untracked.transform_keys(&:downcase)
296
+ end
297
+
298
+ def case_aware_include?(cased_hash, downcased_hash, file)
299
+ if ignore_case?
300
+ send(downcased_hash).include?(file.downcase)
301
+ else
302
+ send(cased_hash).include?(file)
303
+ end
304
+ end
267
305
  end
268
306
  end
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.1.0'
4
+ VERSION='2.1.1'
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.1.0
4
+ version: 2.1.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: 2024-05-31 00:00:00.000000000 Z
11
+ date: 2024-06-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.1.0/file/CHANGELOG.md
247
- documentation_uri: https://rubydoc.info/gems/git/2.1.0
246
+ changelog_uri: https://rubydoc.info/gems/git/2.1.1/file/CHANGELOG.md
247
+ documentation_uri: https://rubydoc.info/gems/git/2.1.1
248
248
  post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths: