git 5.0.0.beta.2 → 5.0.0.beta.4

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.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +27 -0
  3. data/.github/copilot-instructions.md +3 -8
  4. data/.github/hooks/bin-setup-on-worktree.json +11 -0
  5. data/.github/hooks/run-bin-setup-once.sh +14 -0
  6. data/.github/skills/breaking-change-analysis/SKILL.md +6 -9
  7. data/.github/skills/ci-cd-troubleshooting/SKILL.md +2 -2
  8. data/.github/skills/command-implementation/REFERENCE.md +34 -33
  9. data/.github/skills/command-implementation/SKILL.md +5 -4
  10. data/.github/skills/command-test-conventions/SKILL.md +13 -9
  11. data/.github/skills/command-yard-documentation/SKILL.md +14 -6
  12. data/.github/skills/development-workflow/SKILL.md +20 -14
  13. data/.github/skills/facade-implementation/REFERENCE.md +19 -22
  14. data/.github/skills/facade-implementation/SKILL.md +0 -5
  15. data/.github/skills/facade-test-conventions/SKILL.md +4 -7
  16. data/.github/skills/facade-yard-documentation/SKILL.md +8 -2
  17. data/.github/skills/make-skill-template/SKILL.md +53 -3
  18. data/.github/skills/pr-readiness-review/SKILL.md +22 -2
  19. data/.github/skills/project-context/SKILL.md +16 -23
  20. data/.github/skills/pull-request-review/SKILL.md +2 -2
  21. data/.github/skills/rebase/SKILL.md +148 -0
  22. data/.github/skills/refactor-command-to-commandlineresult/SKILL.md +1 -1
  23. data/.github/skills/resolve-feedback/SKILL.md +288 -0
  24. data/.github/skills/review-arguments-dsl/CHECKLIST.md +3 -3
  25. data/.github/skills/reviewing-skills/SKILL.md +28 -3
  26. data/.github/skills/test-debugging/SKILL.md +20 -19
  27. data/.github/skills/yard-documentation/SKILL.md +671 -483
  28. data/.github/skills/yard-documentation/element-rules.md +162 -0
  29. data/.github/skills-deprecated/README.md +21 -0
  30. data/.github/{skills → skills-deprecated}/extract-command-from-lib/SKILL.md +9 -9
  31. data/.github/{skills → skills-deprecated}/extract-facade-from-base-lib/SKILL.md +12 -12
  32. data/.github/workflows/continuous_integration.yml +3 -2
  33. data/.rubocop.yml +7 -39
  34. data/.yard-lint.yml +75 -0
  35. data/CONTRIBUTING.md +186 -174
  36. data/Gemfile +17 -0
  37. data/README.md +86 -23
  38. data/Rakefile +3 -21
  39. data/UPGRADING.md +219 -70
  40. data/docker/test/Dockerfile +32 -0
  41. data/docker/test/docker-compose.yml +0 -0
  42. data/git.gemspec +3 -4
  43. data/lib/git/author.rb +20 -1
  44. data/lib/git/branch.rb +26 -6
  45. data/lib/git/branch_delete_failure.rb +3 -0
  46. data/lib/git/branch_delete_result.rb +6 -3
  47. data/lib/git/branch_info.rb +6 -6
  48. data/lib/git/command_line/base.rb +6 -13
  49. data/lib/git/command_line/capturing.rb +67 -10
  50. data/lib/git/command_line/result.rb +0 -8
  51. data/lib/git/command_line/streaming.rb +45 -5
  52. data/lib/git/command_line.rb +4 -3
  53. data/lib/git/commands/add.rb +61 -53
  54. data/lib/git/commands/am/abort.rb +2 -2
  55. data/lib/git/commands/am/apply.rb +109 -98
  56. data/lib/git/commands/am/continue.rb +2 -2
  57. data/lib/git/commands/am/quit.rb +2 -2
  58. data/lib/git/commands/am/retry.rb +4 -2
  59. data/lib/git/commands/am/show_current_patch.rb +1 -1
  60. data/lib/git/commands/am/skip.rb +2 -2
  61. data/lib/git/commands/am.rb +2 -2
  62. data/lib/git/commands/apply.rb +7 -2
  63. data/lib/git/commands/archive/list_formats.rb +3 -3
  64. data/lib/git/commands/archive.rb +7 -2
  65. data/lib/git/commands/arguments.rb +1370 -359
  66. data/lib/git/commands/base.rb +111 -13
  67. data/lib/git/commands/branch/copy.rb +29 -21
  68. data/lib/git/commands/branch/create.rb +72 -68
  69. data/lib/git/commands/branch/delete.rb +25 -17
  70. data/lib/git/commands/branch/list.rb +76 -60
  71. data/lib/git/commands/branch/move.rb +29 -21
  72. data/lib/git/commands/branch/set_upstream.rb +8 -8
  73. data/lib/git/commands/branch/show_current.rb +3 -3
  74. data/lib/git/commands/branch/unset_upstream.rb +4 -8
  75. data/lib/git/commands/branch.rb +2 -2
  76. data/lib/git/commands/cat_file/batch.rb +36 -20
  77. data/lib/git/commands/cat_file/filtered.rb +12 -12
  78. data/lib/git/commands/cat_file/raw.rb +13 -13
  79. data/lib/git/commands/cat_file.rb +4 -4
  80. data/lib/git/commands/checkout/branch.rb +7 -5
  81. data/lib/git/commands/checkout/files.rb +5 -4
  82. data/lib/git/commands/checkout.rb +4 -4
  83. data/lib/git/commands/checkout_index.rb +5 -4
  84. data/lib/git/commands/clean.rb +6 -4
  85. data/lib/git/commands/clone.rb +5 -4
  86. data/lib/git/commands/commit.rb +5 -4
  87. data/lib/git/commands/commit_tree.rb +5 -4
  88. data/lib/git/commands/config_option_syntax/add.rb +7 -4
  89. data/lib/git/commands/config_option_syntax/get.rb +9 -5
  90. data/lib/git/commands/config_option_syntax/get_all.rb +7 -4
  91. data/lib/git/commands/config_option_syntax/get_color.rb +8 -4
  92. data/lib/git/commands/config_option_syntax/get_color_bool.rb +7 -4
  93. data/lib/git/commands/config_option_syntax/get_regexp.rb +8 -4
  94. data/lib/git/commands/config_option_syntax/get_urlmatch.rb +8 -4
  95. data/lib/git/commands/config_option_syntax/list.rb +8 -4
  96. data/lib/git/commands/config_option_syntax/remove_section.rb +7 -2
  97. data/lib/git/commands/config_option_syntax/rename_section.rb +7 -2
  98. data/lib/git/commands/config_option_syntax/replace_all.rb +7 -2
  99. data/lib/git/commands/config_option_syntax/set.rb +7 -2
  100. data/lib/git/commands/config_option_syntax/unset.rb +7 -4
  101. data/lib/git/commands/config_option_syntax/unset_all.rb +7 -2
  102. data/lib/git/commands/describe.rb +5 -4
  103. data/lib/git/commands/diff.rb +13 -12
  104. data/lib/git/commands/diff_files.rb +7 -6
  105. data/lib/git/commands/diff_index.rb +10 -7
  106. data/lib/git/commands/fetch.rb +6 -4
  107. data/lib/git/commands/fsck.rb +6 -4
  108. data/lib/git/commands/gc.rb +6 -4
  109. data/lib/git/commands/grep.rb +6 -5
  110. data/lib/git/commands/init.rb +6 -4
  111. data/lib/git/commands/log.rb +287 -285
  112. data/lib/git/commands/ls_files.rb +69 -65
  113. data/lib/git/commands/ls_remote.rb +62 -56
  114. data/lib/git/commands/ls_tree.rb +50 -46
  115. data/lib/git/commands/maintenance/register.rb +25 -23
  116. data/lib/git/commands/maintenance/run.rb +7 -2
  117. data/lib/git/commands/maintenance/start.rb +7 -2
  118. data/lib/git/commands/maintenance/stop.rb +7 -2
  119. data/lib/git/commands/maintenance/unregister.rb +7 -2
  120. data/lib/git/commands/merge/abort.rb +2 -2
  121. data/lib/git/commands/merge/continue.rb +2 -2
  122. data/lib/git/commands/merge/quit.rb +2 -2
  123. data/lib/git/commands/merge/start.rb +7 -2
  124. data/lib/git/commands/merge.rb +2 -2
  125. data/lib/git/commands/merge_base.rb +7 -2
  126. data/lib/git/commands/mv.rb +7 -2
  127. data/lib/git/commands/name_rev.rb +7 -2
  128. data/lib/git/commands/pull.rb +7 -2
  129. data/lib/git/commands/push.rb +7 -2
  130. data/lib/git/commands/read_tree.rb +7 -2
  131. data/lib/git/commands/remote/add.rb +7 -2
  132. data/lib/git/commands/remote/get_url.rb +4 -2
  133. data/lib/git/commands/remote/list.rb +4 -2
  134. data/lib/git/commands/remote/prune.rb +4 -2
  135. data/lib/git/commands/remote/remove.rb +4 -2
  136. data/lib/git/commands/remote/rename.rb +4 -2
  137. data/lib/git/commands/remote/set_branches.rb +9 -2
  138. data/lib/git/commands/remote/set_head.rb +12 -5
  139. data/lib/git/commands/remote/set_url.rb +9 -2
  140. data/lib/git/commands/remote/set_url_add.rb +11 -2
  141. data/lib/git/commands/remote/set_url_delete.rb +9 -2
  142. data/lib/git/commands/remote/show.rb +18 -12
  143. data/lib/git/commands/remote/update.rb +19 -12
  144. data/lib/git/commands/remote.rb +2 -2
  145. data/lib/git/commands/repack.rb +67 -63
  146. data/lib/git/commands/reset.rb +51 -44
  147. data/lib/git/commands/rev_parse.rb +135 -128
  148. data/lib/git/commands/revert/abort.rb +2 -2
  149. data/lib/git/commands/revert/continue.rb +7 -2
  150. data/lib/git/commands/revert/quit.rb +2 -2
  151. data/lib/git/commands/revert/skip.rb +2 -2
  152. data/lib/git/commands/revert/start.rb +7 -2
  153. data/lib/git/commands/revert.rb +2 -2
  154. data/lib/git/commands/rm.rb +35 -36
  155. data/lib/git/commands/show.rb +1 -1
  156. data/lib/git/commands/show_ref/exclude_existing.rb +3 -4
  157. data/lib/git/commands/show_ref/exists.rb +15 -13
  158. data/lib/git/commands/show_ref/list.rb +39 -35
  159. data/lib/git/commands/show_ref/verify.rb +29 -27
  160. data/lib/git/commands/show_ref.rb +4 -4
  161. data/lib/git/commands/stash/apply.rb +31 -25
  162. data/lib/git/commands/stash/branch.rb +10 -8
  163. data/lib/git/commands/stash/clear.rb +7 -5
  164. data/lib/git/commands/stash/create.rb +10 -8
  165. data/lib/git/commands/stash/drop.rb +15 -9
  166. data/lib/git/commands/stash/list.rb +9 -5
  167. data/lib/git/commands/stash/pop.rb +21 -12
  168. data/lib/git/commands/stash/push.rb +20 -11
  169. data/lib/git/commands/stash/show.rb +21 -12
  170. data/lib/git/commands/stash/store.rb +19 -10
  171. data/lib/git/commands/stash.rb +2 -2
  172. data/lib/git/commands/status.rb +7 -2
  173. data/lib/git/commands/symbolic_ref/delete.rb +18 -14
  174. data/lib/git/commands/symbolic_ref/read.rb +24 -20
  175. data/lib/git/commands/symbolic_ref/update.rb +20 -17
  176. data/lib/git/commands/symbolic_ref.rb +4 -4
  177. data/lib/git/commands/tag/create.rb +45 -42
  178. data/lib/git/commands/tag/delete.rb +5 -3
  179. data/lib/git/commands/tag/list.rb +47 -44
  180. data/lib/git/commands/tag/verify.rb +12 -12
  181. data/lib/git/commands/tag.rb +2 -2
  182. data/lib/git/commands/update_ref/batch.rb +6 -1
  183. data/lib/git/commands/update_ref/delete.rb +19 -21
  184. data/lib/git/commands/update_ref/update.rb +22 -25
  185. data/lib/git/commands/update_ref.rb +4 -4
  186. data/lib/git/commands/version.rb +14 -11
  187. data/lib/git/commands/worktree/add.rb +50 -51
  188. data/lib/git/commands/worktree/list.rb +17 -17
  189. data/lib/git/commands/worktree/lock.rb +12 -12
  190. data/lib/git/commands/worktree/move.rb +16 -16
  191. data/lib/git/commands/worktree/prune.rb +2 -2
  192. data/lib/git/commands/worktree/remove.rb +2 -2
  193. data/lib/git/commands/worktree/repair.rb +2 -2
  194. data/lib/git/commands/worktree/unlock.rb +2 -2
  195. data/lib/git/commands/write_tree.rb +2 -2
  196. data/lib/git/commands.rb +4 -3
  197. data/lib/git/config.rb +47 -1
  198. data/lib/git/configuring.rb +89 -15
  199. data/lib/git/detached_head_info.rb +4 -1
  200. data/lib/git/diff.rb +2 -5
  201. data/lib/git/diff_file_numstat_info.rb +3 -1
  202. data/lib/git/diff_file_patch_info.rb +3 -1
  203. data/lib/git/diff_file_raw_info.rb +3 -1
  204. data/lib/git/diff_info.rb +8 -15
  205. data/lib/git/diff_path_status.rb +16 -3
  206. data/lib/git/diff_result.rb +3 -1
  207. data/lib/git/diff_stats.rb +15 -0
  208. data/lib/git/dirstat_info.rb +24 -8
  209. data/lib/git/encoding_utils.rb +32 -1
  210. data/lib/git/errors.rb +19 -9
  211. data/lib/git/escaped_path.rb +55 -3
  212. data/lib/git/execution_context/repository.rb +15 -0
  213. data/lib/git/execution_context.rb +76 -74
  214. data/lib/git/file_ref.rb +6 -3
  215. data/lib/git/fsck_object.rb +8 -0
  216. data/lib/git/fsck_result.rb +26 -15
  217. data/lib/git/log.rb +152 -5
  218. data/lib/git/object.rb +284 -8
  219. data/lib/git/parsers/branch.rb +18 -0
  220. data/lib/git/parsers/cat_file.rb +2 -2
  221. data/lib/git/parsers/diff.rb +213 -5
  222. data/lib/git/parsers/fsck.rb +11 -0
  223. data/lib/git/parsers/ls_remote.rb +1 -1
  224. data/lib/git/parsers/stash.rb +51 -0
  225. data/lib/git/parsers/tag.rb +38 -0
  226. data/lib/git/remote.rb +34 -2
  227. data/lib/git/repository/branching.rb +23 -21
  228. data/lib/git/repository/committing.rb +46 -6
  229. data/lib/git/repository/context_helpers.rb +45 -16
  230. data/lib/git/repository/diffing.rb +32 -23
  231. data/lib/git/repository/factories.rb +153 -28
  232. data/lib/git/repository/inspecting.rb +1 -1
  233. data/lib/git/repository/logging.rb +169 -30
  234. data/lib/git/repository/maintenance.rb +1 -1
  235. data/lib/git/repository/merging.rb +3 -3
  236. data/lib/git/repository/object_operations.rb +108 -14
  237. data/lib/git/repository/remote_operations.rb +150 -171
  238. data/lib/git/repository/shared_private.rb +7 -5
  239. data/lib/git/repository/staging.rb +36 -12
  240. data/lib/git/repository/stashing.rb +16 -16
  241. data/lib/git/repository/status_operations.rb +1 -1
  242. data/lib/git/repository/worktree_operations.rb +1 -1
  243. data/lib/git/repository.rb +287 -6
  244. data/lib/git/stash.rb +16 -21
  245. data/lib/git/stash_info.rb +4 -4
  246. data/lib/git/stashes.rb +20 -26
  247. data/lib/git/status.rb +25 -13
  248. data/lib/git/tag_delete_failure.rb +3 -0
  249. data/lib/git/tag_delete_result.rb +6 -3
  250. data/lib/git/tag_info.rb +1 -0
  251. data/lib/git/url.rb +12 -5
  252. data/lib/git/version.rb +6 -4
  253. data/lib/git/version_constraint.rb +4 -0
  254. data/lib/git.rb +400 -314
  255. data/redesign/3_architecture_implementation.md +81 -30
  256. data/redesign/Phase 4 - Step A.md +6 -0
  257. data/redesign/Phase 4 - Step B.md +921 -0
  258. data/redesign/Phase 4 - Step C.md +833 -0
  259. data/redesign/c1a-public-api-scope.tsv +256 -0
  260. data/redesign/phase-4-step-b-test-audit.tsv +485 -0
  261. data/tasks/yard.rake +24 -17
  262. metadata +24 -58
  263. data/commitlint.test +0 -4
  264. data/lib/git/args_builder.rb +0 -103
  265. data/lib/git/command_line_result.rb +0 -8
  266. data/lib/git/deprecation.rb +0 -9
  267. data/lib/git/repository/configuring.rb +0 -351
  268. data/tasks/test.rake +0 -25
  269. /data/.github/{skills → skills-deprecated}/extract-facade-from-base-lib/KEYWORD_ARG_REMEDIATION.md +0 -0
  270. /data/.github/{skills → skills-deprecated}/review-backward-compatibility/SKILL.md +0 -0
@@ -1,351 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'git/commands/config_option_syntax'
4
- require 'git/repository/shared_private'
5
-
6
- module Git
7
- class Repository
8
- # Legacy facade methods for reading and writing git configuration
9
- #
10
- # Provides the {#config} and {#global_config} dispatch methods for 4.x
11
- # compatibility. These methods return raw `String` / `Hash` values instead of
12
- # {Git::ConfigEntryInfo} objects and are retained so that internal callers such
13
- # as `Git::Status` continue to work unchanged.
14
- #
15
- # The structured `config_*` methods (e.g. `config_get`, `config_list`) are
16
- # provided by {Git::Configuring}, which is included directly into
17
- # {Git::Repository}.
18
- #
19
- # Included by {Git::Repository}.
20
- #
21
- # @api public
22
- #
23
- module Configuring
24
- # Option keys accepted by {#config} when writing a value
25
- CONFIG_SET_ALLOWED_OPTS = %i[file].freeze
26
- private_constant :CONFIG_SET_ALLOWED_OPTS
27
-
28
- # Option keys accepted by {#config} when reading a single value or listing
29
- CONFIG_READ_ALLOWED_OPTS = %i[file].freeze
30
- private_constant :CONFIG_READ_ALLOWED_OPTS
31
-
32
- # Read or write a git configuration entry
33
- #
34
- # Dispatches to one of three modes depending on the arguments supplied:
35
- #
36
- # * **List** — `config()` returns all visible config entries as a `Hash`.
37
- # * **Get** — `config(name)` returns the value for a single key as a `String`.
38
- # * **Set** — `config(name, value)` writes a value and returns the raw
39
- # command result.
40
- #
41
- # @overload config(options = {})
42
- #
43
- # @example List all config entries
44
- # repo.config #=> { "user.name" => "Alice", "core.bare" => "false" }
45
- #
46
- # @example List all entries from a custom config file
47
- # repo.config(file: '/path/to/.gitconfig')
48
- # #=> { "user.name" => "Alice", "core.bare" => "false" }
49
- #
50
- # @param options [Hash] options for the list operation
51
- #
52
- # @option options [String, nil] :file (nil) path to a custom config file
53
- # to read from instead of the default resolution chain
54
- #
55
- # @return [Hash{String => String}] all visible config entries, keyed by
56
- # their full dotted key names (e.g. `"user.name"`)
57
- #
58
- # @raise [ArgumentError] if unsupported options are provided
59
- #
60
- # @overload config(name, options = {})
61
- #
62
- # @example Read the committer name from config
63
- # repo.config('user.name') #=> "Alice"
64
- #
65
- # @example Read a value from a custom config file
66
- # repo.config('user.name', file: '/path/to/.gitconfig') #=> "Alice"
67
- #
68
- # @param name [String] the dotted config key to look up (e.g.
69
- # `"user.name"`)
70
- #
71
- # @param options [Hash] options for the get operation
72
- #
73
- # @option options [String, nil] :file (nil) path to a custom config file
74
- # to read from instead of the default resolution chain
75
- #
76
- # @return [String] the value of the config entry
77
- #
78
- # @raise [ArgumentError] if unsupported options are provided
79
- #
80
- # @overload config(name, value, options = {})
81
- #
82
- # @example Set the committer name in local config
83
- # repo.config('user.name', 'Alice')
84
- #
85
- # @example Write a value to a custom config file
86
- # repo.config('user.name', 'Alice', file: '/path/to/custom/config')
87
- #
88
- # @param name [String] the dotted config key to write (e.g.
89
- # `"user.name"`)
90
- #
91
- # @param value [#to_s] the value to assign; must not be `nil` (a `nil`
92
- # value is treated as "no value" and routes to the get overload).
93
- # Must not be a `Hash` (a Hash is treated as the `options` argument;
94
- # call `value.to_s` explicitly before passing if a stringified Hash
95
- # is genuinely needed). Any other non-nil object is converted to a
96
- # String via `#to_s` before being passed to git
97
- #
98
- # @param options [Hash] options for the set operation
99
- #
100
- # @option options [String, nil] :file (nil) path to a custom config file
101
- # to write to instead of the repository's default `.git/config`
102
- #
103
- # @return [Git::CommandLineResult] the raw result of
104
- # `git config <name> <value>`
105
- #
106
- # @raise [ArgumentError] if unsupported options are provided
107
- #
108
- # @raise [Git::FailedError] if git exits with a non-zero exit status
109
- #
110
- def config(name = nil, value = nil, options = {})
111
- name, value, options = Private.normalize_config_args(name, value, options)
112
-
113
- if !name.nil? && !value.nil?
114
- Private.config_set(@execution_context, name, value, **options)
115
- elsif name
116
- Private.config_get(@execution_context, name, **options)
117
- else
118
- Private.config_list(@execution_context, **options)
119
- end
120
- end
121
-
122
- # Read or write a global git configuration entry
123
- #
124
- # Dispatches to one of three modes depending on the arguments supplied,
125
- # targeting the git global config scope (`git config --global`):
126
- #
127
- # * **List** — `global_config()` returns all global config entries as a `Hash`.
128
- # * **Get** — `global_config(name)` returns the value for a single key as a `String`.
129
- # * **Set** — `global_config(name, value)` writes a value and returns the raw
130
- # command result.
131
- #
132
- # @overload global_config
133
- #
134
- # @example List all global config entries
135
- # repo.global_config #=> { "user.name" => "Alice", "core.autocrlf" => "false" }
136
- #
137
- # @return [Hash{String => String}] all global config entries, keyed by their
138
- # full dotted key names (e.g. `"user.name"`)
139
- #
140
- # @raise [Git::FailedError] if git exits with a non-zero exit status
141
- #
142
- # @overload global_config(name)
143
- #
144
- # @example Read the global committer name
145
- # repo.global_config('user.name') #=> "Alice"
146
- #
147
- # @param name [String] the dotted config key to look up (e.g. `"user.name"`)
148
- #
149
- # @return [String] the value of the global config entry
150
- #
151
- # @raise [Git::FailedError] if git exits with a non-zero exit status
152
- #
153
- # @overload global_config(name, value)
154
- #
155
- # @example Set the global committer name
156
- # repo.global_config('user.name', 'Alice')
157
- #
158
- # @param name [String] the dotted config key to write (e.g. `"user.name"`)
159
- #
160
- # @param value [#to_s] the value to assign; any object is accepted and
161
- # converted to a String via `#to_s` before being passed to git
162
- #
163
- # @return [Git::CommandLineResult] the raw result of
164
- # `git config --global <name> <value>`
165
- #
166
- # @raise [Git::FailedError] if git exits with a non-zero exit status
167
- #
168
- def global_config(name = nil, value = nil)
169
- if !name.nil? && !value.nil?
170
- Private.global_config_set(@execution_context, name, value)
171
- elsif !name.nil?
172
- Private.global_config_get(@execution_context, name)
173
- else
174
- Private.global_config_list(@execution_context)
175
- end
176
- end
177
-
178
- # Private helpers local to {Git::Repository::Configuring}
179
- #
180
- # @api private
181
- #
182
- module Private
183
- module_function
184
-
185
- # Normalize `config()` positional arguments
186
- #
187
- # In Ruby 3.x, calling `config(file: '/path')` passes the hash as the
188
- # first positional argument. This helper re-maps those patterns so that
189
- # `name`, `value`, and `options` are always in their canonical positions.
190
- #
191
- # Raises `ArgumentError` for call shapes that are ambiguous or clearly
192
- # wrong, such as passing extra positional arguments after an options Hash.
193
- #
194
- # @param name [String, Hash, nil] the raw first argument to {#config}
195
- #
196
- # @param value [Object, Hash, nil] the raw second argument to {#config}
197
- #
198
- # @param options [Hash] the raw third argument to {#config}
199
- #
200
- # @return [Array(String|nil, Object|nil, Hash)] normalized [name, value, options]
201
- #
202
- # @raise [ArgumentError] if extra positional arguments follow an options Hash
203
- #
204
- def normalize_config_args(name, value, options)
205
- if name.is_a?(Hash)
206
- raise ArgumentError, 'unexpected positional arguments after options hash' if !value.nil? || !options.empty?
207
-
208
- [nil, nil, name]
209
- elsif value.is_a?(Hash)
210
- raise ArgumentError, 'unexpected third argument when second argument is options hash' unless options.empty?
211
-
212
- [name, nil, value]
213
- else
214
- [name, value, options]
215
- end
216
- end
217
-
218
- # Set a config value by key name
219
- #
220
- # @overload config_set(execution_context, name, value, **options)
221
- #
222
- # @param execution_context [Git::ExecutionContext] the execution context
223
- #
224
- # @param name [String] the dotted config key to write (e.g. `"user.name"`)
225
- #
226
- # @param value [String] the value to assign
227
- #
228
- # @param options [Hash] keyword options forwarded to the command
229
- #
230
- # @option options [String, nil] :file (nil) path to a custom config file
231
- # to write to instead of the repository's default `.git/config`
232
- #
233
- # @return [Git::CommandLineResult] the raw result of
234
- # `git config <name> <value>`
235
- #
236
- # @raise [ArgumentError] if unsupported options are provided
237
- #
238
- # @raise [Git::FailedError] if git exits with a non-zero exit status
239
- #
240
- def config_set(execution_context, name, value, **)
241
- SharedPrivate.assert_valid_opts!(CONFIG_SET_ALLOWED_OPTS, **)
242
- Git::Commands::ConfigOptionSyntax::Set.new(execution_context).call(name, value, **)
243
- end
244
-
245
- # Retrieve a config value by key name
246
- #
247
- # @param execution_context [Git::ExecutionContext] the execution context
248
- #
249
- # @param name [String] the dotted config key to look up (e.g. `"user.name"`)
250
- #
251
- # @param options [Hash] keyword options
252
- #
253
- # @option options [String, nil] :file (nil) path to a custom config file to read from
254
- #
255
- # @return [String] the value of the config entry
256
- #
257
- # @raise [ArgumentError] if unsupported options are provided
258
- #
259
- # @raise [Git::FailedError] if git exits with a non-zero exit status
260
- #
261
- def config_get(execution_context, name, **options)
262
- SharedPrivate.assert_valid_opts!(CONFIG_READ_ALLOWED_OPTS, **options)
263
- opts = options[:file] ? { file: options[:file] } : {}
264
- result = Git::Commands::ConfigOptionSyntax::Get.new(execution_context).call(name, **opts)
265
- raise Git::FailedError, result if result.status.exitstatus != 0
266
-
267
- result.stdout
268
- end
269
-
270
- # Retrieve all config entries as a hash
271
- #
272
- # @param execution_context [Git::ExecutionContext] the execution context
273
- #
274
- # @param options [Hash] keyword options
275
- #
276
- # @option options [String, nil] :file (nil) path to a custom config file to read from
277
- #
278
- # @return [Hash{String => String}] all config entries, keyed by their full
279
- # dotted key names (e.g. `"user.name"`)
280
- #
281
- # @raise [ArgumentError] if unsupported options are provided
282
- #
283
- # @raise [Git::FailedError] if git exits with a non-zero exit status
284
- #
285
- def config_list(execution_context, **options)
286
- SharedPrivate.assert_valid_opts!(CONFIG_READ_ALLOWED_OPTS, **options)
287
- opts = options[:file] ? { file: options[:file] } : {}
288
- lines = Git::Commands::ConfigOptionSyntax::List.new(execution_context).call(**opts).stdout.split("\n")
289
- lines.each_with_object({}) do |line, hsh|
290
- key, value = line.split('=', 2)
291
- hsh[key] = value || ''
292
- end
293
- end
294
-
295
- # Retrieve a global config value by key name
296
- #
297
- # @param execution_context [Git::ExecutionContext] the execution context
298
- #
299
- # @param name [String] the dotted config key to look up (e.g. `"user.name"`)
300
- #
301
- # @return [String] the value of the global config entry
302
- #
303
- # @raise [Git::FailedError] if git exits with a non-zero exit status
304
- #
305
- def global_config_get(execution_context, name)
306
- result = Git::Commands::ConfigOptionSyntax::Get.new(execution_context).call(name, global: true)
307
- raise Git::FailedError, result if result.status.exitstatus != 0
308
-
309
- result.stdout
310
- end
311
-
312
- # Retrieve all global config entries as a hash
313
- #
314
- # @param execution_context [Git::ExecutionContext] the execution context
315
- #
316
- # @return [Hash{String => String}] all global config entries, keyed by their full
317
- # dotted key names (e.g. `"user.name"`)
318
- #
319
- # @raise [Git::FailedError] if git exits with a non-zero exit status
320
- #
321
- def global_config_list(execution_context)
322
- lines = Git::Commands::ConfigOptionSyntax::List.new(execution_context).call(global: true).stdout.split("\n")
323
- lines.each_with_object({}) do |line, hsh|
324
- key, value = line.split('=', 2)
325
- hsh[key] = value || ''
326
- end
327
- end
328
-
329
- # Set a global config value by key name
330
- #
331
- # @param execution_context [Git::ExecutionContext] the execution context
332
- #
333
- # @param name [String] the dotted config key to write (e.g. `"user.name"`)
334
- #
335
- # @param value [#to_s] the value to assign; any object is accepted and
336
- # converted to a String via `#to_s` before being passed to git
337
- #
338
- # @return [Git::CommandLineResult] the raw result of
339
- # `git config --global <name> <value>`
340
- #
341
- # @raise [Git::FailedError] if git exits with a non-zero exit status
342
- #
343
- def global_config_set(execution_context, name, value)
344
- Git::Commands::ConfigOptionSyntax::Set.new(execution_context).call(name, value, global: true)
345
- end
346
- end
347
-
348
- private_constant :Private
349
- end
350
- end
351
- end
data/tasks/test.rake DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- desc 'Run Unit Tests (TestUnit)'
4
- task :test do
5
- sh 'ruby bin/test'
6
-
7
- # You can run individual test files (or multiple files) from the command
8
- # line with:
9
- #
10
- # $ bin/test test_archive.rb
11
- #
12
- # $ bin/test test_archive.rb test_object.rb
13
- end
14
-
15
- desc 'Run Test::Unit tests in parallel'
16
- task 'test:parallel' do
17
- # Ensure git global config is set (normally done by bin/test for serial runs).
18
- # CI runners may not have a git identity configured.
19
- sh 'git config --global user.email "git@example.com"' if `git config --global user.email`.empty?
20
- sh 'git config --global user.name "GitExample"' if `git config --global user.name`.empty?
21
- sh 'git config --global init.defaultBranch main' if `git config --global init.defaultBranch`.empty?
22
-
23
- sh({ 'PARALLEL_TESTS_EXECUTABLE' => 'ruby -Itests' },
24
- "bundle exec parallel_test tests/units/ --suffix 'test_.+\\.rb$'")
25
- end