git 3.1.1 → 4.0.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.
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Git
4
+ # The files and their status (e.g., added, modified, deleted) between two commits
5
+ class DiffPathStatus
6
+ include Enumerable
7
+
8
+ # @private
9
+ def initialize(base, from, to, path_limiter = nil)
10
+ # Eagerly check for invalid arguments
11
+ [from, to].compact.each do |arg|
12
+ raise ArgumentError, "Invalid argument: '#{arg}'" if arg.start_with?('-')
13
+ end
14
+
15
+ @base = base
16
+ @from = from
17
+ @to = to
18
+ @path_limiter = path_limiter
19
+ @path_status = nil
20
+ end
21
+
22
+ # Iterates over each file's status.
23
+ #
24
+ # @yield [path, status]
25
+ def each(&)
26
+ fetch_path_status.each(&)
27
+ end
28
+
29
+ # Returns the name-status report as a Hash.
30
+ #
31
+ # @return [Hash<String, String>] A hash where keys are file paths
32
+ # and values are their status codes.
33
+ def to_h
34
+ fetch_path_status
35
+ end
36
+
37
+ private
38
+
39
+ # Lazily fetches and caches the path status from the git lib.
40
+ def fetch_path_status
41
+ @fetch_path_status ||= @base.lib.diff_path_status(
42
+ @from, @to, { path: @path_limiter }
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Git
4
+ # Provides access to the statistics of a diff between two commits,
5
+ # including insertions, deletions, and file-level details.
6
+ class DiffStats
7
+ # @private
8
+ def initialize(base, from, to, path_limiter = nil)
9
+ # Eagerly check for invalid arguments
10
+ [from, to].compact.each do |arg|
11
+ raise ArgumentError, "Invalid argument: '#{arg}'" if arg.start_with?('-')
12
+ end
13
+
14
+ @base = base
15
+ @from = from
16
+ @to = to
17
+ @path_limiter = path_limiter
18
+ @stats = nil
19
+ end
20
+
21
+ # Returns the total number of lines deleted.
22
+ def deletions
23
+ fetch_stats[:total][:deletions]
24
+ end
25
+
26
+ # Returns the total number of lines inserted.
27
+ def insertions
28
+ fetch_stats[:total][:insertions]
29
+ end
30
+
31
+ # Returns the total number of lines changed (insertions + deletions).
32
+ def lines
33
+ fetch_stats[:total][:lines]
34
+ end
35
+
36
+ # Returns a hash of statistics for each file in the diff.
37
+ #
38
+ # @return [Hash<String, {insertions: Integer, deletions: Integer}>]
39
+ def files
40
+ fetch_stats[:files]
41
+ end
42
+
43
+ # Returns a hash of the total statistics for the diff.
44
+ #
45
+ # @return [{insertions: Integer, deletions: Integer, lines: Integer, files: Integer}]
46
+ def total
47
+ fetch_stats[:total]
48
+ end
49
+
50
+ private
51
+
52
+ # Lazily fetches and caches the stats from the git lib.
53
+ def fetch_stats
54
+ @fetch_stats ||= @base.lib.diff_stats(
55
+ @from, @to, { path_limiter: @path_limiter }
56
+ )
57
+ end
58
+ end
59
+ end
data/lib/git/errors.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Git
4
+ # rubocop:disable Layout/LineLength
5
+
4
6
  # Base class for all custom git module errors
5
7
  #
6
8
  # The git gem will only raise an `ArgumentError` or an error that is a subclass of
@@ -60,6 +62,8 @@ module Git
60
62
  #
61
63
  class Error < StandardError; end
62
64
 
65
+ # rubocop:enable Layout/LineLength
66
+
63
67
  # An alias for Git::Error
64
68
  #
65
69
  # Git::GitExecuteError error class is an alias for Git::Error for backwards
@@ -155,7 +159,8 @@ module Git
155
159
  # status = ProcessExecuter.spawn(*command, timeout: timeout_duration)
156
160
  # result = Git::CommandLineResult.new(command, status, 'stdout', 'err output')
157
161
  # error = Git::TimeoutError.new(result, timeout_duration)
158
- # error.error_message #=> '["sleep", "10"], status: pid 70144 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
162
+ # error.error_message
163
+ # #=> '["sleep", "10"], status: pid 70144 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
159
164
  #
160
165
  # @param result [Git::CommandLineResult] the result of the git command including
161
166
  # the git command, status, stdout, and stderr
@@ -171,7 +176,8 @@ module Git
171
176
  # The human readable representation of this error
172
177
  #
173
178
  # @example
174
- # error.error_message #=> '["sleep", "10"], status: pid 88811 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
179
+ # error.error_message
180
+ # #=> '["sleep", "10"], status: pid 88811 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
175
181
  #
176
182
  # @return [String]
177
183
  #
@@ -42,7 +42,7 @@ module Git
42
42
  private
43
43
 
44
44
  def extract_octal(path, index)
45
- [path[index + 1..index + 3].to_i(8), 4]
45
+ [path[(index + 1)..(index + 3)].to_i(8), 4]
46
46
  end
47
47
 
48
48
  def extract_escape(path, index)