git 1.19.1 → 5.5.0

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 (265) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -1
  3. data/AI_POLICY.md +24 -0
  4. data/CHANGELOG.md +689 -0
  5. data/CODE_OF_CONDUCT.md +25 -0
  6. data/CONTRIBUTING.md +1175 -97
  7. data/GOVERNANCE.md +106 -0
  8. data/LICENSE +1 -1
  9. data/MAINTAINERS.md +17 -4
  10. data/README.md +476 -320
  11. data/UPGRADING.md +1138 -0
  12. data/git.gemspec +124 -36
  13. data/lib/git/author.rb +39 -7
  14. data/lib/git/author_info.rb +66 -0
  15. data/lib/git/branch.rb +615 -65
  16. data/lib/git/branch_delete_failure.rb +34 -0
  17. data/lib/git/branch_delete_result.rb +66 -0
  18. data/lib/git/branch_info.rb +237 -0
  19. data/lib/git/branches.rb +167 -44
  20. data/lib/git/command_line/base.rb +247 -0
  21. data/lib/git/command_line/capturing.rb +308 -0
  22. data/lib/git/command_line/result.rb +88 -0
  23. data/lib/git/command_line/streaming.rb +236 -0
  24. data/lib/git/command_line.rb +52 -0
  25. data/lib/git/commands/add.rb +139 -0
  26. data/lib/git/commands/am/abort.rb +43 -0
  27. data/lib/git/commands/am/apply.rb +263 -0
  28. data/lib/git/commands/am/continue.rb +43 -0
  29. data/lib/git/commands/am/quit.rb +43 -0
  30. data/lib/git/commands/am/retry.rb +49 -0
  31. data/lib/git/commands/am/show_current_patch.rb +64 -0
  32. data/lib/git/commands/am/skip.rb +42 -0
  33. data/lib/git/commands/am.rb +33 -0
  34. data/lib/git/commands/apply.rb +242 -0
  35. data/lib/git/commands/archive/list_formats.rb +46 -0
  36. data/lib/git/commands/archive.rb +145 -0
  37. data/lib/git/commands/arguments.rb +4521 -0
  38. data/lib/git/commands/base.rb +502 -0
  39. data/lib/git/commands/branch/copy.rb +102 -0
  40. data/lib/git/commands/branch/create.rb +177 -0
  41. data/lib/git/commands/branch/delete.rb +88 -0
  42. data/lib/git/commands/branch/list.rb +178 -0
  43. data/lib/git/commands/branch/move.rb +102 -0
  44. data/lib/git/commands/branch/set_upstream.rb +86 -0
  45. data/lib/git/commands/branch/show_current.rb +49 -0
  46. data/lib/git/commands/branch/unset_upstream.rb +53 -0
  47. data/lib/git/commands/branch.rb +34 -0
  48. data/lib/git/commands/cat_file/batch.rb +385 -0
  49. data/lib/git/commands/cat_file/filtered.rb +105 -0
  50. data/lib/git/commands/cat_file/raw.rb +271 -0
  51. data/lib/git/commands/cat_file.rb +49 -0
  52. data/lib/git/commands/checkout/branch.rb +153 -0
  53. data/lib/git/commands/checkout/files.rb +116 -0
  54. data/lib/git/commands/checkout.rb +38 -0
  55. data/lib/git/commands/checkout_index.rb +106 -0
  56. data/lib/git/commands/clean.rb +102 -0
  57. data/lib/git/commands/clone.rb +241 -0
  58. data/lib/git/commands/commit.rb +273 -0
  59. data/lib/git/commands/commit_tree.rb +101 -0
  60. data/lib/git/commands/config_option_syntax/add.rb +86 -0
  61. data/lib/git/commands/config_option_syntax/get.rb +121 -0
  62. data/lib/git/commands/config_option_syntax/get_all.rb +118 -0
  63. data/lib/git/commands/config_option_syntax/get_color.rb +95 -0
  64. data/lib/git/commands/config_option_syntax/get_color_bool.rb +96 -0
  65. data/lib/git/commands/config_option_syntax/get_regexp.rb +119 -0
  66. data/lib/git/commands/config_option_syntax/get_urlmatch.rb +111 -0
  67. data/lib/git/commands/config_option_syntax/list.rb +111 -0
  68. data/lib/git/commands/config_option_syntax/remove_section.rb +79 -0
  69. data/lib/git/commands/config_option_syntax/rename_section.rb +83 -0
  70. data/lib/git/commands/config_option_syntax/replace_all.rb +109 -0
  71. data/lib/git/commands/config_option_syntax/set.rb +119 -0
  72. data/lib/git/commands/config_option_syntax/unset.rb +92 -0
  73. data/lib/git/commands/config_option_syntax/unset_all.rb +94 -0
  74. data/lib/git/commands/config_option_syntax.rb +56 -0
  75. data/lib/git/commands/describe.rb +156 -0
  76. data/lib/git/commands/diff.rb +657 -0
  77. data/lib/git/commands/diff_files.rb +519 -0
  78. data/lib/git/commands/diff_index.rb +499 -0
  79. data/lib/git/commands/fetch.rb +354 -0
  80. data/lib/git/commands/fsck.rb +138 -0
  81. data/lib/git/commands/gc.rb +134 -0
  82. data/lib/git/commands/grep.rb +339 -0
  83. data/lib/git/commands/init.rb +101 -0
  84. data/lib/git/commands/log.rb +634 -0
  85. data/lib/git/commands/ls_files.rb +195 -0
  86. data/lib/git/commands/ls_remote.rb +161 -0
  87. data/lib/git/commands/ls_tree.rb +135 -0
  88. data/lib/git/commands/maintenance/register.rb +77 -0
  89. data/lib/git/commands/maintenance/run.rb +109 -0
  90. data/lib/git/commands/maintenance/start.rb +71 -0
  91. data/lib/git/commands/maintenance/stop.rb +60 -0
  92. data/lib/git/commands/maintenance/unregister.rb +84 -0
  93. data/lib/git/commands/maintenance.rb +31 -0
  94. data/lib/git/commands/merge/abort.rb +44 -0
  95. data/lib/git/commands/merge/continue.rb +44 -0
  96. data/lib/git/commands/merge/quit.rb +46 -0
  97. data/lib/git/commands/merge/start.rb +250 -0
  98. data/lib/git/commands/merge.rb +28 -0
  99. data/lib/git/commands/merge_base.rb +91 -0
  100. data/lib/git/commands/mv.rb +82 -0
  101. data/lib/git/commands/name_rev.rb +119 -0
  102. data/lib/git/commands/pull.rb +382 -0
  103. data/lib/git/commands/push.rb +251 -0
  104. data/lib/git/commands/read_tree.rb +154 -0
  105. data/lib/git/commands/remote/add.rb +96 -0
  106. data/lib/git/commands/remote/get_url.rb +68 -0
  107. data/lib/git/commands/remote/list.rb +56 -0
  108. data/lib/git/commands/remote/prune.rb +63 -0
  109. data/lib/git/commands/remote/remove.rb +52 -0
  110. data/lib/git/commands/remote/rename.rb +76 -0
  111. data/lib/git/commands/remote/set_branches.rb +70 -0
  112. data/lib/git/commands/remote/set_head.rb +89 -0
  113. data/lib/git/commands/remote/set_url.rb +78 -0
  114. data/lib/git/commands/remote/set_url_add.rb +70 -0
  115. data/lib/git/commands/remote/set_url_delete.rb +71 -0
  116. data/lib/git/commands/remote/show.rb +77 -0
  117. data/lib/git/commands/remote/update.rb +79 -0
  118. data/lib/git/commands/remote.rb +42 -0
  119. data/lib/git/commands/repack.rb +281 -0
  120. data/lib/git/commands/reset.rb +154 -0
  121. data/lib/git/commands/rev_parse.rb +304 -0
  122. data/lib/git/commands/revert/abort.rb +45 -0
  123. data/lib/git/commands/revert/continue.rb +62 -0
  124. data/lib/git/commands/revert/quit.rb +47 -0
  125. data/lib/git/commands/revert/skip.rb +44 -0
  126. data/lib/git/commands/revert/start.rb +158 -0
  127. data/lib/git/commands/revert.rb +29 -0
  128. data/lib/git/commands/rm.rb +113 -0
  129. data/lib/git/commands/show.rb +632 -0
  130. data/lib/git/commands/show_ref/exclude_existing.rb +119 -0
  131. data/lib/git/commands/show_ref/exists.rb +80 -0
  132. data/lib/git/commands/show_ref/list.rb +149 -0
  133. data/lib/git/commands/show_ref/verify.rb +122 -0
  134. data/lib/git/commands/show_ref.rb +42 -0
  135. data/lib/git/commands/stash/apply.rb +81 -0
  136. data/lib/git/commands/stash/branch.rb +67 -0
  137. data/lib/git/commands/stash/clear.rb +43 -0
  138. data/lib/git/commands/stash/create.rb +60 -0
  139. data/lib/git/commands/stash/drop.rb +73 -0
  140. data/lib/git/commands/stash/list.rb +43 -0
  141. data/lib/git/commands/stash/pop.rb +87 -0
  142. data/lib/git/commands/stash/push.rb +112 -0
  143. data/lib/git/commands/stash/show.rb +158 -0
  144. data/lib/git/commands/stash/store.rb +72 -0
  145. data/lib/git/commands/stash.rb +38 -0
  146. data/lib/git/commands/status.rb +174 -0
  147. data/lib/git/commands/symbolic_ref/delete.rb +72 -0
  148. data/lib/git/commands/symbolic_ref/read.rb +99 -0
  149. data/lib/git/commands/symbolic_ref/update.rb +79 -0
  150. data/lib/git/commands/symbolic_ref.rb +38 -0
  151. data/lib/git/commands/tag/create.rb +142 -0
  152. data/lib/git/commands/tag/delete.rb +57 -0
  153. data/lib/git/commands/tag/list.rb +146 -0
  154. data/lib/git/commands/tag/verify.rb +71 -0
  155. data/lib/git/commands/tag.rb +26 -0
  156. data/lib/git/commands/update_ref/batch.rb +145 -0
  157. data/lib/git/commands/update_ref/delete.rb +90 -0
  158. data/lib/git/commands/update_ref/update.rb +103 -0
  159. data/lib/git/commands/update_ref.rb +42 -0
  160. data/lib/git/commands/version.rb +60 -0
  161. data/lib/git/commands/worktree/add.rb +139 -0
  162. data/lib/git/commands/worktree/list.rb +64 -0
  163. data/lib/git/commands/worktree/lock.rb +58 -0
  164. data/lib/git/commands/worktree/management_base.rb +51 -0
  165. data/lib/git/commands/worktree/move.rb +66 -0
  166. data/lib/git/commands/worktree/prune.rb +67 -0
  167. data/lib/git/commands/worktree/remove.rb +63 -0
  168. data/lib/git/commands/worktree/repair.rb +76 -0
  169. data/lib/git/commands/worktree/unlock.rb +47 -0
  170. data/lib/git/commands/worktree.rb +43 -0
  171. data/lib/git/commands/write_tree.rb +68 -0
  172. data/lib/git/commands.rb +88 -0
  173. data/lib/git/config.rb +72 -5
  174. data/lib/git/config_entry_info.rb +106 -0
  175. data/lib/git/configuring.rb +795 -0
  176. data/lib/git/detached_head_info.rb +57 -0
  177. data/lib/git/diff.rb +437 -86
  178. data/lib/git/diff_file_numstat_info.rb +31 -0
  179. data/lib/git/diff_file_patch_info.rb +136 -0
  180. data/lib/git/diff_file_raw_info.rb +129 -0
  181. data/lib/git/diff_info.rb +162 -0
  182. data/lib/git/diff_path_status.rb +107 -0
  183. data/lib/git/diff_result.rb +34 -0
  184. data/lib/git/diff_stats.rb +111 -0
  185. data/lib/git/dirstat_info.rb +102 -0
  186. data/lib/git/encoding_utils.rb +32 -1
  187. data/lib/git/errors.rb +285 -0
  188. data/lib/git/escaped_path.rb +57 -5
  189. data/lib/git/execution_context/global.rb +31 -0
  190. data/lib/git/execution_context/repository.rb +151 -0
  191. data/lib/git/execution_context.rb +559 -0
  192. data/lib/git/factories.rb +813 -0
  193. data/lib/git/file_ref.rb +77 -0
  194. data/lib/git/fsck_object.rb +56 -0
  195. data/lib/git/fsck_result.rb +132 -0
  196. data/lib/git/log.rb +306 -90
  197. data/lib/git/object.rb +563 -141
  198. data/lib/git/parsers/branch.rb +240 -0
  199. data/lib/git/parsers/cat_file.rb +111 -0
  200. data/lib/git/parsers/config_entry.rb +110 -0
  201. data/lib/git/parsers/diff.rb +792 -0
  202. data/lib/git/parsers/fsck.rb +144 -0
  203. data/lib/git/parsers/grep.rb +42 -0
  204. data/lib/git/parsers/ls_remote.rb +79 -0
  205. data/lib/git/parsers/ls_tree.rb +58 -0
  206. data/lib/git/parsers/remote.rb +162 -0
  207. data/lib/git/parsers/stash.rb +292 -0
  208. data/lib/git/parsers/status.rb +251 -0
  209. data/lib/git/parsers/tag.rb +341 -0
  210. data/lib/git/parsers/worktree.rb +185 -0
  211. data/lib/git/path_resolver.rb +206 -0
  212. data/lib/git/remote.rb +165 -12
  213. data/lib/git/remote_info.rb +203 -0
  214. data/lib/git/repository/branching.rb +964 -0
  215. data/lib/git/repository/committing.rb +246 -0
  216. data/lib/git/repository/context_helpers.rb +293 -0
  217. data/lib/git/repository/diffing.rb +785 -0
  218. data/lib/git/repository/inspecting.rb +252 -0
  219. data/lib/git/repository/logging.rb +410 -0
  220. data/lib/git/repository/maintenance.rb +65 -0
  221. data/lib/git/repository/merging.rb +451 -0
  222. data/lib/git/repository/object_operations.rb +1551 -0
  223. data/lib/git/repository/remote_operations.rb +984 -0
  224. data/lib/git/repository/shared_private.rb +120 -0
  225. data/lib/git/repository/staging.rb +587 -0
  226. data/lib/git/repository/stashing.rb +623 -0
  227. data/lib/git/repository/status_operations.rb +249 -0
  228. data/lib/git/repository/worktree_operations.rb +339 -0
  229. data/lib/git/repository.rb +484 -2
  230. data/lib/git/stash.rb +109 -12
  231. data/lib/git/stash_info.rb +102 -0
  232. data/lib/git/stashes.rb +169 -26
  233. data/lib/git/status.rb +308 -122
  234. data/lib/git/status_file_info.rb +258 -0
  235. data/lib/git/status_info.rb +189 -0
  236. data/lib/git/tag_delete_failure.rb +34 -0
  237. data/lib/git/tag_delete_result.rb +66 -0
  238. data/lib/git/tag_info.rb +99 -0
  239. data/lib/git/url.rb +15 -8
  240. data/lib/git/version.rb +113 -2
  241. data/lib/git/version_constraint.rb +85 -0
  242. data/lib/git/worktree.rb +150 -8
  243. data/lib/git/worktree_info.rb +128 -0
  244. data/lib/git/worktrees.rb +118 -13
  245. data/lib/git.rb +632 -234
  246. metadata +369 -54
  247. data/.github/stale.yml +0 -25
  248. data/.github/workflows/continuous_integration.yml +0 -49
  249. data/.gitignore +0 -10
  250. data/Dockerfile.changelog-rs +0 -12
  251. data/Gemfile +0 -5
  252. data/ISSUE_TEMPLATE.md +0 -15
  253. data/PULL_REQUEST_TEMPLATE.md +0 -9
  254. data/RELEASING.md +0 -70
  255. data/Rakefile +0 -60
  256. data/lib/git/base/factory.rb +0 -99
  257. data/lib/git/base.rb +0 -711
  258. data/lib/git/command_line_result.rb +0 -86
  259. data/lib/git/failed_error.rb +0 -53
  260. data/lib/git/git_execute_error.rb +0 -7
  261. data/lib/git/index.rb +0 -5
  262. data/lib/git/lib.rb +0 -1328
  263. data/lib/git/path.rb +0 -31
  264. data/lib/git/signaled_error.rb +0 -50
  265. data/lib/git/working_directory.rb +0 -4
@@ -0,0 +1,271 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module CatFile
8
+ # Queries a single git object by name passed as a CLI argument
9
+ #
10
+ # Runs `git cat-file` in non-batch mode. Exactly one mode flag or a `<type>`
11
+ # operand must be supplied:
12
+ #
13
+ # - **`-e`** — exit 0 if the object exists and is valid, exit 1 otherwise;
14
+ # no output is written to stdout
15
+ # - **`-t`** — print the object type (`blob`, `tree`, `commit`, or `tag`)
16
+ # - **`-s`** — print the object size in bytes
17
+ # - **`-p`** — pretty-print the object content (format varies by type)
18
+ # - **`<type>`** — print the raw content after validating the object is of
19
+ # the given type (or trivially dereferenceable to it)
20
+ #
21
+ # For queries across multiple objects, use {CatFile::Batch}.
22
+ # For filter-processed content, use {CatFile::Filtered}.
23
+ #
24
+ # @note `arguments` block audited against https://git-scm.com/docs/git-cat-file/2.53.0
25
+ #
26
+ # @see Git::Commands::CatFile
27
+ #
28
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file documentation
29
+ #
30
+ # @api private
31
+ #
32
+ class Raw < Base
33
+ arguments do
34
+ literal 'cat-file'
35
+
36
+ # Exit 0 if object exists and is valid; exit 1 otherwise (no output)
37
+ # See https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt--e
38
+ flag_option :e
39
+
40
+ # Pretty-print the object content based on its type
41
+ # See https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt--p
42
+ flag_option :p
43
+
44
+ # Print the object type (`blob`, `tree`, `commit`, or `tag`)
45
+ # See https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt--t
46
+ flag_option :t
47
+
48
+ # Print the object size in bytes
49
+ # See https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt--s
50
+ flag_option :s
51
+
52
+ # Allow -t and -s to query broken or corrupt objects of unknown type.
53
+ # Deprecated and removed in v6.0.0 (see issue 1709); passing it emits a
54
+ # deprecation warning. Git 2.28-2.49 honors it with -t and -s and rejects
55
+ # it in other modes; git 2.50+ accepts and ignores it everywhere (the
56
+ # unknown-type feature was removed).
57
+ # See https://git-scm.com/docs/git-cat-file/2.49.0#Documentation/git-cat-file.txt---allow-unknown-type
58
+ flag_option :allow_unknown_type
59
+
60
+ # Map committer/author identities through the mailmap before reporting size
61
+ # See https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---use-mailmap
62
+ flag_option :use_mailmap, negatable: true
63
+
64
+ # Stream stdout to this IO object instead of buffering in memory.
65
+ # When provided, {#call} dispatches to the streaming execution path.
66
+ execution_option :out
67
+
68
+ # Abort the command after this many seconds.
69
+ execution_option :timeout
70
+
71
+ end_of_options
72
+
73
+ # Expected object type — one of `commit`, `tree`, `blob`, or `tag`.
74
+ # Git also accepts a type that the object is trivially dereferenceable to
75
+ # (e.g. `tree` against a commit ref, `blob` against a tag that points to one).
76
+ operand :type
77
+
78
+ # Object name: SHA, ref, `HEAD`, treeish path reference, etc.
79
+ operand :object, required: true
80
+ end
81
+
82
+ # Execute `git cat-file` for a single object.
83
+ #
84
+ # Exactly one mode must be selected: pass one of `e: true`, `p: true`,
85
+ # `t: true`, `s: true`, or a positional `type` argument.
86
+ #
87
+ # @overload call(object, e: true, **options)
88
+ # Check whether an object exists
89
+ #
90
+ # @param object [String] object name (SHA, ref, `HEAD`, treeish path, etc.)
91
+ #
92
+ # @param e [Boolean] enable existence-check mode
93
+ #
94
+ # @param options [Hash] command options
95
+ #
96
+ # @option options [Boolean, nil] :allow_unknown_type (nil) pass `--allow-unknown-type` through to git,
97
+ # which rejects it in this mode on git 2.28-2.49 and accepts it as a no-op
98
+ # on git 2.50 and later
99
+ #
100
+ # Deprecated and removed in v6.0.0; passing it emits a deprecation
101
+ # warning.
102
+ #
103
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
104
+ #
105
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
106
+ #
107
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
108
+ #
109
+ # Exit status 0 means the object exists; exit status 1 means it does not
110
+ #
111
+ # @raise [ArgumentError] if unsupported options are provided
112
+ #
113
+ # @raise [Git::FailedError] if git exits with a status other than 0 or 1
114
+ #
115
+ # @overload call(object, t: true, **options)
116
+ # Print the object type
117
+ #
118
+ # @param object [String] object name
119
+ #
120
+ # @param t [Boolean] enable type-query mode
121
+ #
122
+ # @param options [Hash] command options
123
+ #
124
+ # @option options [Boolean, nil] :allow_unknown_type (nil) allow querying broken or corrupt objects of
125
+ # unknown type on git 2.28-2.49
126
+ #
127
+ # Deprecated and removed in v6.0.0; passing it emits a deprecation
128
+ # warning. Git 2.50 removed the unknown-type feature and accepts this
129
+ # flag as a no-op.
130
+ #
131
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
132
+ #
133
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
134
+ #
135
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
136
+ #
137
+ # Stdout contains the object type string
138
+ #
139
+ # @raise [ArgumentError] if unsupported options are provided
140
+ #
141
+ # @raise [Git::FailedError] if the object does not exist
142
+ #
143
+ # @overload call(object, s: true, **options)
144
+ # Print the object size in bytes
145
+ #
146
+ # @param object [String] object name
147
+ #
148
+ # @param s [Boolean] enable size-query mode
149
+ #
150
+ # @param options [Hash] command options
151
+ #
152
+ # @option options [Boolean, nil] :allow_unknown_type (nil) allow querying broken or corrupt objects of
153
+ # unknown type on git 2.28-2.49
154
+ #
155
+ # Deprecated and removed in v6.0.0; passing it emits a deprecation
156
+ # warning. Git 2.50 removed the unknown-type feature and accepts this
157
+ # flag as a no-op.
158
+ #
159
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
160
+ #
161
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
162
+ #
163
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
164
+ #
165
+ # Stdout contains the object size as a decimal string
166
+ #
167
+ # @raise [ArgumentError] if unsupported options are provided
168
+ #
169
+ # @raise [Git::FailedError] if the object does not exist
170
+ #
171
+ # @overload call(object, p: true, **options)
172
+ # Pretty-print the object content
173
+ #
174
+ # @param object [String] object name
175
+ #
176
+ # @param p [Boolean] enable pretty-print mode
177
+ #
178
+ # @param options [Hash] command options
179
+ #
180
+ # @option options [Boolean, nil] :allow_unknown_type (nil) pass `--allow-unknown-type` through to git,
181
+ # which rejects it in this mode on git 2.28-2.49 and accepts it as a no-op
182
+ # on git 2.50 and later
183
+ #
184
+ # Deprecated and removed in v6.0.0; passing it emits a deprecation
185
+ # warning.
186
+ #
187
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
188
+ #
189
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
190
+ #
191
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
192
+ #
193
+ # Stdout contains the formatted object content
194
+ #
195
+ # @raise [ArgumentError] if unsupported options are provided
196
+ #
197
+ # @raise [Git::FailedError] if the object does not exist
198
+ #
199
+ # @overload call(type, object, **options)
200
+ # Print the raw content, validating the object is of the given type
201
+ #
202
+ # @param type [String] expected object type — `commit`, `tree`, `blob`, or `tag`
203
+ #
204
+ # @param object [String] object name
205
+ #
206
+ # @param options [Hash] command options
207
+ #
208
+ # @option options [Boolean, nil] :allow_unknown_type (nil) pass `--allow-unknown-type` through to git,
209
+ # which rejects it in this mode on git 2.28-2.49 and accepts it as a no-op
210
+ # on git 2.50 and later
211
+ #
212
+ # Deprecated and removed in v6.0.0; passing it emits a deprecation
213
+ # warning.
214
+ #
215
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
216
+ #
217
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
218
+ #
219
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
220
+ #
221
+ # Stdout contains the raw object content
222
+ #
223
+ # @raise [ArgumentError] if unsupported options are provided
224
+ #
225
+ # @raise [Git::FailedError] if the object does not exist or is not of the
226
+ # given type
227
+ #
228
+ # @option options [Numeric, nil] :timeout (nil) abort the command after this many seconds
229
+ #
230
+ def call(*, **)
231
+ warn_allow_unknown_type_deprecated(**)
232
+ bound = args_definition.bind(*, **)
233
+ validate_version!(bound.execution_options)
234
+ result = execute_command(bound)
235
+
236
+ # `-e` treats exit 1 as a meaningful result (object not found), but any other
237
+ # non-zero exit (e.g. 128 for a corrupt object database) is still a failure.
238
+ # All other modes treat every non-zero exit as a failure.
239
+ allowed = result.status.success? || (bound.e? && result.status.exitstatus == 1)
240
+ raise Git::FailedError, result unless allowed
241
+
242
+ result
243
+ end
244
+
245
+ private
246
+
247
+ # Emit the deprecation warning when the `allow_unknown_type` keyword is passed
248
+ #
249
+ # Keys on the keyword being present, whatever its value: `false` and `nil`
250
+ # suppress the flag but still name a deprecated option.
251
+ #
252
+ # @param options [Hash] the keyword arguments passed to {#call}
253
+ #
254
+ # @option options [Boolean, nil] :allow_unknown_type the deprecated option;
255
+ # any value, including `false` and `nil`, triggers the warning
256
+ #
257
+ # @return [void]
258
+ #
259
+ def warn_allow_unknown_type_deprecated(**options)
260
+ return unless options.key?(:allow_unknown_type)
261
+
262
+ Git::Deprecation.warn(
263
+ 'The allow_unknown_type option of Git::Commands::CatFile::Raw is deprecated ' \
264
+ 'and will be removed in v6.0.0. Git 2.50 removed the unknown-type feature ' \
265
+ 'and accepts --allow-unknown-type as a no-op.'
266
+ )
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cat_file/batch'
4
+ require_relative 'cat_file/filtered'
5
+ require_relative 'cat_file/raw'
6
+
7
+ module Git
8
+ module Commands
9
+ # Commands for reading git object store content via `git cat-file`
10
+ #
11
+ # This module contains command classes split by invocation protocol:
12
+ #
13
+ # - {CatFile::Raw} — single object as a CLI argument; raw content, type, size, or
14
+ # existence check (`-e`, `-t`, `-s`, `-p`, `<type>`)
15
+ # - {CatFile::Filtered} — single object as a CLI argument; content after
16
+ # `.gitattributes` filter processing (`--textconv`, `--filters`)
17
+ # - {CatFile::Batch} — objects fed via stdin; all batch streaming modes
18
+ # (`--batch`, `--batch-check`, `--batch-command`)
19
+ #
20
+ # @example Check whether an object exists
21
+ # cmd = Git::Commands::CatFile::Raw.new(lib)
22
+ # result = cmd.call('HEAD', e: true)
23
+ # result.status.exitstatus # => 0 (exists) or 1 (not found)
24
+ #
25
+ # @example Pretty-print a single object
26
+ # cmd = Git::Commands::CatFile::Raw.new(lib)
27
+ # result = cmd.call('HEAD', p: true)
28
+ # result.stdout
29
+ # # => "tree abc1234...\nauthor ...\n\nCommit message\n"
30
+ #
31
+ # @example Fetch content after working-tree filters
32
+ # cmd = Git::Commands::CatFile::Filtered.new(lib)
33
+ # result = cmd.call('HEAD:README.md', filters: true)
34
+ # result.stdout
35
+ #
36
+ # @example Fetch metadata for several objects via batch
37
+ # cmd = Git::Commands::CatFile::Batch.new(lib)
38
+ # result = cmd.call('HEAD', 'v1.0', batch_check: true)
39
+ # result.stdout
40
+ # # => "abc1234... commit 250\nabc5678... tag 143\n"
41
+ #
42
+ # @see https://git-scm.com/docs/git-cat-file git-cat-file documentation
43
+ #
44
+ # @api private
45
+ #
46
+ module CatFile
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module Checkout
8
+ # Implements the `git checkout` command for switching branches
9
+ #
10
+ # This command switches branches by updating the index and working tree
11
+ # to match the specified branch, and updating HEAD to point to that branch.
12
+ # It can also create new branches with the `-b` or `-B` options.
13
+ #
14
+ # @example Typical usage
15
+ # checkout = Git::Commands::Checkout::Branch.new(execution_context)
16
+ # checkout.call('main')
17
+ # checkout.call(b: 'feature-branch')
18
+ # checkout.call('origin/main', b: 'feature-branch', track: true)
19
+ # checkout.call('abc123', detach: true)
20
+ # checkout.call('main', force: true)
21
+ #
22
+ # @note `arguments` block audited against https://git-scm.com/docs/git-checkout/2.53.0
23
+ #
24
+ # @see Git::Commands::Checkout
25
+ #
26
+ # @see https://git-scm.com/docs/git-checkout git-checkout
27
+ #
28
+ # @api private
29
+ #
30
+ class Branch < Git::Commands::Base
31
+ arguments do
32
+ literal 'checkout'
33
+ flag_option %i[quiet q]
34
+ flag_option :progress, negatable: true
35
+ flag_option %i[force f]
36
+ value_option :b
37
+ value_option :B
38
+ flag_or_value_option %i[track t], negatable: true, inline: true
39
+ flag_option :guess, negatable: true
40
+ flag_option :l
41
+ flag_option %i[detach d]
42
+ value_option :orphan
43
+ flag_option %i[merge m]
44
+ flag_option :ignore_other_worktrees
45
+ flag_option :overwrite_ignore, negatable: true
46
+
47
+ # --recurse-submodules is technically available but has no effect on branch
48
+ # switching in older git versions. Included for completeness per the man page.
49
+ flag_option :recurse_submodules, negatable: true
50
+
51
+ execution_option :chdir
52
+
53
+ operand :branch
54
+ end
55
+
56
+ # @overload call(branch = nil, **options)
57
+ #
58
+ # Execute the git checkout command for branch switching
59
+ #
60
+ # @param branch [String, nil] the branch name, commit SHA, or ref to check
61
+ # out; when used with branch creation options (`:b`, `:B`, `:orphan`)
62
+ # this becomes the start point
63
+ #
64
+ # @param options [Hash] command options
65
+ #
66
+ # @option options [Boolean, nil] :quiet (nil) suppress feedback messages
67
+ #
68
+ # Alias: `:q`
69
+ #
70
+ # @option options [Boolean, nil] :progress (nil) force progress reporting even
71
+ # when not attached to a terminal (`--progress`)
72
+ #
73
+ # @option options [Boolean, nil] :no_progress (nil) disable progress reporting
74
+ # even when attached to a terminal (`--no-progress`)
75
+ #
76
+ # @option options [Boolean, nil] :force (nil) proceed even if the index or
77
+ # working tree differs from HEAD; discards local changes and untracked
78
+ # files that are in the way
79
+ #
80
+ # Alias: `:f`
81
+ #
82
+ # @option options [String] :b (nil) create a new branch with this name and
83
+ # switch to it; the positional `branch` argument becomes the start point
84
+ #
85
+ # @option options [String] :B (nil) like `:b`, but reset the branch to the
86
+ # start point if it already exists
87
+ #
88
+ # @option options [Boolean, String, nil] :track (nil) set up upstream tracking
89
+ # configuration; `true` emits `--track`, `'direct'` emits
90
+ # `--track=direct`, `'inherit'` emits `--track=inherit` (`--track`)
91
+ #
92
+ # Alias: `:t`
93
+ #
94
+ # @option options [Boolean, nil] :no_track (nil) do not set up branch tracking
95
+ # even if `branch.autoSetupMerge` is configured (`--no-track`)
96
+ #
97
+ # @option options [Boolean, nil] :guess (nil) automatically create and check out
98
+ # a local branch from a uniquely matching remote-tracking branch
99
+ # (`--guess`)
100
+ #
101
+ # @option options [Boolean, nil] :no_guess (nil) disable automatic remote branch
102
+ # matching (`--no-guess`)
103
+ #
104
+ # @option options [Boolean, nil] :l (nil) create the new branch's reflog
105
+ #
106
+ # @option options [Boolean, nil] :detach (nil) detach HEAD at the specified
107
+ # commit rather than pointing a branch at it
108
+ #
109
+ # Alias: `:d`
110
+ #
111
+ # @option options [String] :orphan (nil) create a new unborn branch with no
112
+ # history; the positional `branch` argument becomes the start point
113
+ #
114
+ # @option options [Boolean, nil] :merge (nil) perform a three-way merge when
115
+ # local modifications conflict with the target branch
116
+ #
117
+ # Alias: `:m`
118
+ #
119
+ # @option options [Boolean, nil] :ignore_other_worktrees (nil) check out the
120
+ # branch even if it is already in use by another worktree
121
+ #
122
+ # @option options [Boolean, nil] :overwrite_ignore (nil) silently overwrite
123
+ # ignored files when switching branches (`--overwrite-ignore`)
124
+ #
125
+ # @option options [Boolean, nil] :no_overwrite_ignore (nil) abort the checkout
126
+ # if ignored files would be overwritten (`--no-overwrite-ignore`)
127
+ #
128
+ # @option options [Boolean, nil] :recurse_submodules (nil) update all active
129
+ # submodule working trees to match the new branch
130
+ # (`--recurse-submodules`)
131
+ #
132
+ # @option options [Boolean, nil] :no_recurse_submodules (nil) do not update
133
+ # submodule working trees when switching branches
134
+ # (`--no-recurse-submodules`)
135
+ #
136
+ # @option options [String] :chdir (nil) change to this directory before
137
+ # running git; not passed to the git CLI
138
+ #
139
+ # @return [Git::CommandLine::Result] the result of calling `git checkout`
140
+ #
141
+ # @raise [ArgumentError] if unsupported options are provided
142
+ #
143
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
144
+ #
145
+ # @api public
146
+ #
147
+ def call(*, **)
148
+ super
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module Checkout
8
+ # Implements the `git checkout` command for restoring working tree files
9
+ #
10
+ # This command replaces files in the working tree with versions from
11
+ # the index (when tree_ish is nil) or a specified tree-ish (commit,
12
+ # branch, tag, etc.).
13
+ #
14
+ # @example Restore working tree files
15
+ # files = Git::Commands::Checkout::Files.new(execution_context)
16
+ # files.call(pathspec: ['lib/foo.rb']) # from the index
17
+ # files.call('HEAD~1', pathspec: ['lib/foo.rb']) # from a specific commit
18
+ # files.call('main', pathspec: %w[lib/foo.rb lib/bar.rb]) # from a branch
19
+ # files.call(pathspec: ['conflicted.txt'], ours: true) # resolve conflict (ours)
20
+ # files.call('main', pathspec_from_file: 'paths.txt') # paths from a file
21
+ #
22
+ # @note `arguments` block audited against https://git-scm.com/docs/git-checkout/2.53.0
23
+ #
24
+ # @see Git::Commands::Checkout
25
+ #
26
+ # @see https://git-scm.com/docs/git-checkout git-checkout
27
+ #
28
+ # @api private
29
+ #
30
+ class Files < Git::Commands::Base
31
+ arguments do
32
+ literal 'checkout'
33
+ flag_option %i[force f]
34
+ flag_option :ours
35
+ flag_option :theirs
36
+ flag_option %i[merge m]
37
+ value_option :conflict, inline: true
38
+ flag_option :overlay, negatable: true
39
+ flag_option :ignore_skip_worktree_bits
40
+ value_option :pathspec_from_file, inline: true
41
+ flag_option :pathspec_file_nul
42
+
43
+ execution_option :chdir
44
+
45
+ operand :tree_ish
46
+ end_of_options
47
+ value_option :pathspec, as_operand: true, repeatable: true
48
+ end
49
+
50
+ # @overload call(tree_ish = nil, **options)
51
+ #
52
+ # Execute the git checkout command for restoring files
53
+ #
54
+ # @param tree_ish [String, nil] The commit, branch, or tree to restore
55
+ # files from
56
+ #
57
+ # When `nil`, files are restored from the index
58
+ #
59
+ # @param options [Hash] command options
60
+ #
61
+ # @option options [Boolean, nil] :force (nil) ignore unmerged entries
62
+ #
63
+ # Alias: `:f`
64
+ #
65
+ # @option options [Boolean, nil] :ours (nil) for unmerged paths, check out
66
+ # stage #2 (our version)
67
+ #
68
+ # @option options [Boolean, nil] :theirs (nil) for unmerged paths, check out
69
+ # stage #3 (their version)
70
+ #
71
+ # @option options [Boolean, nil] :merge (nil) recreate the conflicted merge in
72
+ # the specified paths; cannot be used when checking out from a tree-ish
73
+ #
74
+ # Alias: `:m`
75
+ #
76
+ # @option options [String] :conflict (nil) conflict marker style; valid
77
+ # values are `'merge'`, `'diff3'`, and `'zdiff3'`
78
+ #
79
+ # @option options [Boolean, nil] :overlay (nil) never remove files from the
80
+ # index or working tree that are not present in the tree-ish (`--overlay`)
81
+ #
82
+ # @option options [Boolean, nil] :no_overlay (nil) remove files not present
83
+ # in the tree-ish from the index and working tree (`--no-overlay`)
84
+ #
85
+ # @option options [Boolean, nil] :ignore_skip_worktree_bits (nil) in sparse
86
+ # checkout mode, ignore sparse patterns and update all files matched by
87
+ # pathspec
88
+ #
89
+ # @option options [String] :pathspec_from_file (nil) read pathspec from
90
+ # this file; pass `'-'` to read from stdin
91
+ #
92
+ # @option options [Boolean, nil] :pathspec_file_nul (nil) with
93
+ # `:pathspec_from_file`, separate pathspec elements with NUL instead of
94
+ # newline
95
+ #
96
+ # @option options [Array<String>, String] :pathspec (nil) the files or
97
+ # directories to restore
98
+ #
99
+ # @option options [String] :chdir (nil) change to this directory before
100
+ # running git; not passed to the git CLI
101
+ #
102
+ # @return [Git::CommandLine::Result] the result of calling `git checkout`
103
+ #
104
+ # @raise [ArgumentError] if unsupported options are provided
105
+ #
106
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
107
+ #
108
+ # @api public
109
+ #
110
+ def call(*, **)
111
+ super
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'checkout/branch'
4
+ require_relative 'checkout/files'
5
+
6
+ module Git
7
+ module Commands
8
+ # Commands for switching branches and restoring files via `git checkout`
9
+ #
10
+ # This module contains command classes split by checkout mode:
11
+ #
12
+ # - {Checkout::Branch} — switch branches or create and switch to a new branch
13
+ # - {Checkout::Files} — restore working tree files from a given tree-ish
14
+ #
15
+ # @example Switch to an existing branch
16
+ # cmd = Git::Commands::Checkout::Branch.new(lib)
17
+ # cmd.call('main')
18
+ #
19
+ # @example Create and switch to a new branch
20
+ # cmd = Git::Commands::Checkout::Branch.new(lib)
21
+ # cmd.call('main', b: 'feature/new-feature')
22
+ #
23
+ # @example Restore a file from the index (discard uncommitted changes)
24
+ # cmd = Git::Commands::Checkout::Files.new(lib)
25
+ # cmd.call(pathspec: ['lib/my_file.rb'])
26
+ #
27
+ # @example Restore a file from a specific branch
28
+ # cmd = Git::Commands::Checkout::Files.new(lib)
29
+ # cmd.call('main', pathspec: ['lib/my_file.rb'])
30
+ #
31
+ # @see https://git-scm.com/docs/git-checkout git-checkout documentation
32
+ #
33
+ # @api private
34
+ #
35
+ module Checkout
36
+ end
37
+ end
38
+ end