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.
- checksums.yaml +4 -4
- data/.github/workflows/continuous_integration.yml +11 -3
- data/.github/workflows/experimental_continuous_integration.yml +9 -0
- data/.gitignore +1 -0
- data/.release-please-manifest.json +1 -1
- data/.rubocop.yml +51 -0
- data/.rubocop_todo.yml +12 -0
- data/CHANGELOG.md +63 -0
- data/README.md +19 -0
- data/Rakefile +13 -1
- data/git.gemspec +35 -30
- data/lib/git/args_builder.rb +103 -0
- data/lib/git/author.rb +6 -5
- data/lib/git/base.rb +274 -164
- data/lib/git/branch.rb +14 -15
- data/lib/git/branches.rb +9 -13
- data/lib/git/command_line.rb +95 -52
- data/lib/git/command_line_result.rb +9 -3
- data/lib/git/config.rb +4 -6
- data/lib/git/diff.rb +115 -80
- data/lib/git/diff_path_status.rb +46 -0
- data/lib/git/diff_stats.rb +59 -0
- data/lib/git/errors.rb +8 -2
- data/lib/git/escaped_path.rb +1 -1
- data/lib/git/lib.rb +869 -561
- data/lib/git/log.rb +90 -146
- data/lib/git/object.rb +85 -66
- data/lib/git/path.rb +18 -8
- data/lib/git/remote.rb +3 -4
- data/lib/git/repository.rb +0 -2
- data/lib/git/stash.rb +13 -6
- data/lib/git/stashes.rb +5 -5
- data/lib/git/status.rb +108 -247
- data/lib/git/url.rb +3 -3
- data/lib/git/version.rb +1 -1
- data/lib/git/worktree.rb +4 -5
- data/lib/git/worktrees.rb +4 -6
- data/lib/git.rb +17 -16
- metadata +40 -6
@@ -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
|
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
|
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
|
#
|