git 4.4.6 → 6.0.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 (275) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +348 -39
  4. data/CONTRIBUTING.md +1014 -144
  5. data/README.md +386 -504
  6. data/UPGRADING.md +1822 -0
  7. data/git.gemspec +102 -22
  8. data/lib/git/author_info.rb +65 -0
  9. data/lib/git/branch_delete_failure.rb +34 -0
  10. data/lib/git/branch_delete_result.rb +66 -0
  11. data/lib/git/branch_info.rb +237 -0
  12. data/lib/git/command_line/base.rb +247 -0
  13. data/lib/git/command_line/capturing.rb +308 -0
  14. data/lib/git/command_line/result.rb +88 -0
  15. data/lib/git/command_line/streaming.rb +236 -0
  16. data/lib/git/command_line.rb +45 -323
  17. data/lib/git/commands/add.rb +139 -0
  18. data/lib/git/commands/am/abort.rb +43 -0
  19. data/lib/git/commands/am/apply.rb +263 -0
  20. data/lib/git/commands/am/continue.rb +43 -0
  21. data/lib/git/commands/am/quit.rb +43 -0
  22. data/lib/git/commands/am/retry.rb +49 -0
  23. data/lib/git/commands/am/show_current_patch.rb +64 -0
  24. data/lib/git/commands/am/skip.rb +42 -0
  25. data/lib/git/commands/am.rb +33 -0
  26. data/lib/git/commands/apply.rb +242 -0
  27. data/lib/git/commands/archive/list_formats.rb +46 -0
  28. data/lib/git/commands/archive.rb +145 -0
  29. data/lib/git/commands/arguments.rb +4521 -0
  30. data/lib/git/commands/base.rb +522 -0
  31. data/lib/git/commands/branch/copy.rb +102 -0
  32. data/lib/git/commands/branch/create.rb +177 -0
  33. data/lib/git/commands/branch/delete.rb +88 -0
  34. data/lib/git/commands/branch/list.rb +178 -0
  35. data/lib/git/commands/branch/move.rb +102 -0
  36. data/lib/git/commands/branch/set_upstream.rb +86 -0
  37. data/lib/git/commands/branch/show_current.rb +49 -0
  38. data/lib/git/commands/branch/unset_upstream.rb +53 -0
  39. data/lib/git/commands/branch.rb +34 -0
  40. data/lib/git/commands/cat_file/batch.rb +385 -0
  41. data/lib/git/commands/cat_file/filtered.rb +105 -0
  42. data/lib/git/commands/cat_file/raw.rb +203 -0
  43. data/lib/git/commands/cat_file.rb +49 -0
  44. data/lib/git/commands/checkout/branch.rb +153 -0
  45. data/lib/git/commands/checkout/files.rb +116 -0
  46. data/lib/git/commands/checkout.rb +38 -0
  47. data/lib/git/commands/checkout_index.rb +106 -0
  48. data/lib/git/commands/clean.rb +102 -0
  49. data/lib/git/commands/clone.rb +241 -0
  50. data/lib/git/commands/commit.rb +273 -0
  51. data/lib/git/commands/commit_tree.rb +101 -0
  52. data/lib/git/commands/config_option_syntax/add.rb +86 -0
  53. data/lib/git/commands/config_option_syntax/get.rb +121 -0
  54. data/lib/git/commands/config_option_syntax/get_all.rb +118 -0
  55. data/lib/git/commands/config_option_syntax/get_color.rb +95 -0
  56. data/lib/git/commands/config_option_syntax/get_color_bool.rb +96 -0
  57. data/lib/git/commands/config_option_syntax/get_regexp.rb +119 -0
  58. data/lib/git/commands/config_option_syntax/get_urlmatch.rb +111 -0
  59. data/lib/git/commands/config_option_syntax/list.rb +111 -0
  60. data/lib/git/commands/config_option_syntax/remove_section.rb +79 -0
  61. data/lib/git/commands/config_option_syntax/rename_section.rb +83 -0
  62. data/lib/git/commands/config_option_syntax/replace_all.rb +109 -0
  63. data/lib/git/commands/config_option_syntax/set.rb +119 -0
  64. data/lib/git/commands/config_option_syntax/unset.rb +92 -0
  65. data/lib/git/commands/config_option_syntax/unset_all.rb +94 -0
  66. data/lib/git/commands/config_option_syntax.rb +56 -0
  67. data/lib/git/commands/describe.rb +156 -0
  68. data/lib/git/commands/diff.rb +657 -0
  69. data/lib/git/commands/diff_files.rb +519 -0
  70. data/lib/git/commands/diff_index.rb +499 -0
  71. data/lib/git/commands/fetch.rb +354 -0
  72. data/lib/git/commands/fsck.rb +138 -0
  73. data/lib/git/commands/gc.rb +134 -0
  74. data/lib/git/commands/grep.rb +339 -0
  75. data/lib/git/commands/init.rb +101 -0
  76. data/lib/git/commands/log.rb +634 -0
  77. data/lib/git/commands/ls_files.rb +195 -0
  78. data/lib/git/commands/ls_remote.rb +161 -0
  79. data/lib/git/commands/ls_tree.rb +135 -0
  80. data/lib/git/commands/maintenance/register.rb +73 -0
  81. data/lib/git/commands/maintenance/run.rb +105 -0
  82. data/lib/git/commands/maintenance/start.rb +67 -0
  83. data/lib/git/commands/maintenance/stop.rb +56 -0
  84. data/lib/git/commands/maintenance/unregister.rb +80 -0
  85. data/lib/git/commands/maintenance.rb +29 -0
  86. data/lib/git/commands/merge/abort.rb +44 -0
  87. data/lib/git/commands/merge/continue.rb +44 -0
  88. data/lib/git/commands/merge/quit.rb +46 -0
  89. data/lib/git/commands/merge/start.rb +250 -0
  90. data/lib/git/commands/merge.rb +28 -0
  91. data/lib/git/commands/merge_base.rb +91 -0
  92. data/lib/git/commands/mv.rb +82 -0
  93. data/lib/git/commands/name_rev.rb +119 -0
  94. data/lib/git/commands/pull.rb +382 -0
  95. data/lib/git/commands/push.rb +251 -0
  96. data/lib/git/commands/read_tree.rb +154 -0
  97. data/lib/git/commands/remote/add.rb +96 -0
  98. data/lib/git/commands/remote/get_url.rb +68 -0
  99. data/lib/git/commands/remote/list.rb +56 -0
  100. data/lib/git/commands/remote/prune.rb +63 -0
  101. data/lib/git/commands/remote/remove.rb +52 -0
  102. data/lib/git/commands/remote/rename.rb +76 -0
  103. data/lib/git/commands/remote/set_branches.rb +70 -0
  104. data/lib/git/commands/remote/set_head.rb +89 -0
  105. data/lib/git/commands/remote/set_url.rb +78 -0
  106. data/lib/git/commands/remote/set_url_add.rb +70 -0
  107. data/lib/git/commands/remote/set_url_delete.rb +71 -0
  108. data/lib/git/commands/remote/show.rb +77 -0
  109. data/lib/git/commands/remote/update.rb +79 -0
  110. data/lib/git/commands/remote.rb +42 -0
  111. data/lib/git/commands/repack.rb +281 -0
  112. data/lib/git/commands/reset.rb +154 -0
  113. data/lib/git/commands/rev_parse.rb +304 -0
  114. data/lib/git/commands/revert/abort.rb +45 -0
  115. data/lib/git/commands/revert/continue.rb +62 -0
  116. data/lib/git/commands/revert/quit.rb +47 -0
  117. data/lib/git/commands/revert/skip.rb +44 -0
  118. data/lib/git/commands/revert/start.rb +158 -0
  119. data/lib/git/commands/revert.rb +29 -0
  120. data/lib/git/commands/rm.rb +113 -0
  121. data/lib/git/commands/show.rb +632 -0
  122. data/lib/git/commands/show_ref/exclude_existing.rb +119 -0
  123. data/lib/git/commands/show_ref/exists.rb +75 -0
  124. data/lib/git/commands/show_ref/list.rb +149 -0
  125. data/lib/git/commands/show_ref/verify.rb +122 -0
  126. data/lib/git/commands/show_ref.rb +42 -0
  127. data/lib/git/commands/stash/apply.rb +81 -0
  128. data/lib/git/commands/stash/branch.rb +67 -0
  129. data/lib/git/commands/stash/clear.rb +43 -0
  130. data/lib/git/commands/stash/create.rb +60 -0
  131. data/lib/git/commands/stash/drop.rb +73 -0
  132. data/lib/git/commands/stash/list.rb +43 -0
  133. data/lib/git/commands/stash/pop.rb +87 -0
  134. data/lib/git/commands/stash/push.rb +112 -0
  135. data/lib/git/commands/stash/show.rb +158 -0
  136. data/lib/git/commands/stash/store.rb +72 -0
  137. data/lib/git/commands/stash.rb +38 -0
  138. data/lib/git/commands/status.rb +174 -0
  139. data/lib/git/commands/symbolic_ref/delete.rb +72 -0
  140. data/lib/git/commands/symbolic_ref/read.rb +99 -0
  141. data/lib/git/commands/symbolic_ref/update.rb +79 -0
  142. data/lib/git/commands/symbolic_ref.rb +38 -0
  143. data/lib/git/commands/tag/create.rb +142 -0
  144. data/lib/git/commands/tag/delete.rb +57 -0
  145. data/lib/git/commands/tag/list.rb +146 -0
  146. data/lib/git/commands/tag/verify.rb +71 -0
  147. data/lib/git/commands/tag.rb +26 -0
  148. data/lib/git/commands/update_ref/batch.rb +145 -0
  149. data/lib/git/commands/update_ref/delete.rb +90 -0
  150. data/lib/git/commands/update_ref/update.rb +103 -0
  151. data/lib/git/commands/update_ref.rb +42 -0
  152. data/lib/git/commands/version.rb +60 -0
  153. data/lib/git/commands/worktree/add.rb +139 -0
  154. data/lib/git/commands/worktree/list.rb +64 -0
  155. data/lib/git/commands/worktree/lock.rb +58 -0
  156. data/lib/git/commands/worktree/management_base.rb +51 -0
  157. data/lib/git/commands/worktree/move.rb +66 -0
  158. data/lib/git/commands/worktree/prune.rb +67 -0
  159. data/lib/git/commands/worktree/remove.rb +63 -0
  160. data/lib/git/commands/worktree/repair.rb +71 -0
  161. data/lib/git/commands/worktree/unlock.rb +47 -0
  162. data/lib/git/commands/worktree.rb +43 -0
  163. data/lib/git/commands/write_tree.rb +68 -0
  164. data/lib/git/commands.rb +88 -0
  165. data/lib/git/config.rb +64 -1
  166. data/lib/git/config_entry_info.rb +106 -0
  167. data/lib/git/configuring.rb +795 -0
  168. data/lib/git/detached_head_info.rb +57 -0
  169. data/lib/git/diff.rb +295 -12
  170. data/lib/git/diff_file_numstat_info.rb +31 -0
  171. data/lib/git/diff_file_patch_info.rb +136 -0
  172. data/lib/git/diff_file_raw_info.rb +129 -0
  173. data/lib/git/diff_info.rb +162 -0
  174. data/lib/git/diff_path_status.rb +80 -19
  175. data/lib/git/diff_result.rb +34 -0
  176. data/lib/git/diff_stats.rb +66 -14
  177. data/lib/git/dirstat_info.rb +102 -0
  178. data/lib/git/encoding_utils.rb +57 -1
  179. data/lib/git/errors.rb +107 -26
  180. data/lib/git/escaped_path.rb +55 -3
  181. data/lib/git/execution_context/global.rb +31 -0
  182. data/lib/git/execution_context/repository.rb +151 -0
  183. data/lib/git/execution_context.rb +559 -0
  184. data/lib/git/factories.rb +1049 -0
  185. data/lib/git/file_ref.rb +77 -0
  186. data/lib/git/fsck_object.rb +17 -9
  187. data/lib/git/fsck_result.rb +27 -16
  188. data/lib/git/log.rb +172 -65
  189. data/lib/git/object.rb +323 -108
  190. data/lib/git/parsers/branch.rb +240 -0
  191. data/lib/git/parsers/cat_file.rb +111 -0
  192. data/lib/git/parsers/config_entry.rb +110 -0
  193. data/lib/git/parsers/diff.rb +792 -0
  194. data/lib/git/parsers/fsck.rb +144 -0
  195. data/lib/git/parsers/grep.rb +42 -0
  196. data/lib/git/parsers/ls_remote.rb +79 -0
  197. data/lib/git/parsers/ls_tree.rb +58 -0
  198. data/lib/git/parsers/remote.rb +162 -0
  199. data/lib/git/parsers/stash.rb +292 -0
  200. data/lib/git/parsers/status.rb +251 -0
  201. data/lib/git/parsers/tag.rb +341 -0
  202. data/lib/git/parsers/worktree.rb +185 -0
  203. data/lib/git/path_resolver.rb +274 -0
  204. data/lib/git/remote_info.rb +203 -0
  205. data/lib/git/repository/branching.rb +796 -0
  206. data/lib/git/repository/committing.rb +221 -0
  207. data/lib/git/repository/context_helpers.rb +454 -0
  208. data/lib/git/repository/diffing.rb +743 -0
  209. data/lib/git/repository/inspecting.rb +252 -0
  210. data/lib/git/repository/logging.rb +410 -0
  211. data/lib/git/repository/maintenance.rb +65 -0
  212. data/lib/git/repository/merging.rb +429 -0
  213. data/lib/git/repository/object_operations.rb +1334 -0
  214. data/lib/git/repository/remote_operations.rb +772 -0
  215. data/lib/git/repository/shared_private.rb +120 -0
  216. data/lib/git/repository/staging.rb +409 -0
  217. data/lib/git/repository/stashing.rb +619 -0
  218. data/lib/git/repository/status_operations.rb +196 -0
  219. data/lib/git/repository/worktree_operations.rb +252 -0
  220. data/lib/git/repository.rb +204 -1
  221. data/lib/git/stash_info.rb +102 -0
  222. data/lib/git/status_file_info.rb +258 -0
  223. data/lib/git/status_info.rb +189 -0
  224. data/lib/git/system_call_guard.rb +95 -0
  225. data/lib/git/tag_delete_failure.rb +34 -0
  226. data/lib/git/tag_delete_result.rb +66 -0
  227. data/lib/git/tag_info.rb +99 -0
  228. data/lib/git/url.rb +12 -5
  229. data/lib/git/version.rb +111 -2
  230. data/lib/git/version_constraint.rb +85 -0
  231. data/lib/git/worktree_info.rb +128 -0
  232. data/lib/git.rb +319 -332
  233. metadata +318 -74
  234. data/.commitlintrc.yml +0 -38
  235. data/.github/copilot-instructions.md +0 -2733
  236. data/.github/issue_template.md +0 -15
  237. data/.github/pull_request_template.md +0 -17
  238. data/.github/workflows/continuous_integration.yml +0 -120
  239. data/.github/workflows/enforce_conventional_commits.yml +0 -29
  240. data/.github/workflows/experimental_continuous_integration.yml +0 -59
  241. data/.github/workflows/release.yml +0 -53
  242. data/.gitignore +0 -15
  243. data/.husky/commit-msg +0 -1
  244. data/.release-please-manifest.json +0 -3
  245. data/.rubocop.yml +0 -55
  246. data/.rubocop_todo.yml +0 -12
  247. data/Gemfile +0 -5
  248. data/Rakefile +0 -18
  249. data/lib/git/args_builder.rb +0 -111
  250. data/lib/git/author.rb +0 -16
  251. data/lib/git/base.rb +0 -1140
  252. data/lib/git/branch.rb +0 -423
  253. data/lib/git/branches.rb +0 -68
  254. data/lib/git/command_line_result.rb +0 -92
  255. data/lib/git/index.rb +0 -6
  256. data/lib/git/lib.rb +0 -2333
  257. data/lib/git/path.rb +0 -38
  258. data/lib/git/remote.rb +0 -39
  259. data/lib/git/stash.rb +0 -26
  260. data/lib/git/stashes.rb +0 -56
  261. data/lib/git/status.rb +0 -159
  262. data/lib/git/working_directory.rb +0 -6
  263. data/lib/git/worktree.rb +0 -39
  264. data/lib/git/worktrees.rb +0 -47
  265. data/package.json +0 -10
  266. data/redesign/1_architecture_existing.md +0 -66
  267. data/redesign/2_architecture_redesign.md +0 -130
  268. data/redesign/3_architecture_implementation.md +0 -138
  269. data/redesign/index.md +0 -34
  270. data/release-please-config.json +0 -36
  271. data/tasks/gem_tasks.rake +0 -10
  272. data/tasks/rubocop.rake +0 -12
  273. data/tasks/test.rake +0 -13
  274. data/tasks/test_gem.rake +0 -12
  275. data/tasks/yard.rake +0 -23
@@ -0,0 +1,203 @@
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
+ # Map committer/author identities through the mailmap before reporting size
53
+ # See https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---use-mailmap
54
+ flag_option :use_mailmap, negatable: true
55
+
56
+ # Stream stdout to this IO object instead of buffering in memory.
57
+ # When provided, {#call} dispatches to the streaming execution path.
58
+ execution_option :out
59
+
60
+ # Abort the command after this many seconds.
61
+ execution_option :timeout
62
+
63
+ end_of_options
64
+
65
+ # Expected object type — one of `commit`, `tree`, `blob`, or `tag`.
66
+ # Git also accepts a type that the object is trivially dereferenceable to
67
+ # (e.g. `tree` against a commit ref, `blob` against a tag that points to one).
68
+ operand :type
69
+
70
+ # Object name: SHA, ref, `HEAD`, treeish path reference, etc.
71
+ operand :object, required: true
72
+ end
73
+
74
+ # Execute `git cat-file` for a single object.
75
+ #
76
+ # Exactly one mode must be selected: pass one of `e: true`, `p: true`,
77
+ # `t: true`, `s: true`, or a positional `type` argument.
78
+ #
79
+ # @overload call(object, e: true, **options)
80
+ # Check whether an object exists
81
+ #
82
+ # @param object [String] object name (SHA, ref, `HEAD`, treeish path, etc.)
83
+ #
84
+ # @param e [Boolean] enable existence-check mode
85
+ #
86
+ # @param options [Hash] command options
87
+ #
88
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
89
+ #
90
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
91
+ #
92
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
93
+ #
94
+ # Exit status 0 means the object exists; exit status 1 means it does not
95
+ #
96
+ # @raise [ArgumentError] if unsupported options are provided
97
+ #
98
+ # @raise [Git::FailedError] if git exits with a status other than 0 or 1
99
+ #
100
+ # @overload call(object, t: true, **options)
101
+ # Print the object type
102
+ #
103
+ # @param object [String] object name
104
+ #
105
+ # @param t [Boolean] enable type-query mode
106
+ #
107
+ # @param options [Hash] command options
108
+ #
109
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
110
+ #
111
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
112
+ #
113
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
114
+ #
115
+ # Stdout contains the object type string
116
+ #
117
+ # @raise [ArgumentError] if unsupported options are provided
118
+ #
119
+ # @raise [Git::FailedError] if the object does not exist
120
+ #
121
+ # @overload call(object, s: true, **options)
122
+ # Print the object size in bytes
123
+ #
124
+ # @param object [String] object name
125
+ #
126
+ # @param s [Boolean] enable size-query mode
127
+ #
128
+ # @param options [Hash] command options
129
+ #
130
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
131
+ #
132
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
133
+ #
134
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
135
+ #
136
+ # Stdout contains the object size as a decimal string
137
+ #
138
+ # @raise [ArgumentError] if unsupported options are provided
139
+ #
140
+ # @raise [Git::FailedError] if the object does not exist
141
+ #
142
+ # @overload call(object, p: true, **options)
143
+ # Pretty-print the object content
144
+ #
145
+ # @param object [String] object name
146
+ #
147
+ # @param p [Boolean] enable pretty-print mode
148
+ #
149
+ # @param options [Hash] command options
150
+ #
151
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
152
+ #
153
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
154
+ #
155
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
156
+ #
157
+ # Stdout contains the formatted object content
158
+ #
159
+ # @raise [ArgumentError] if unsupported options are provided
160
+ #
161
+ # @raise [Git::FailedError] if the object does not exist
162
+ #
163
+ # @overload call(type, object, **options)
164
+ # Print the raw content, validating the object is of the given type
165
+ #
166
+ # @param type [String] expected object type — `commit`, `tree`, `blob`, or `tag`
167
+ #
168
+ # @param object [String] object name
169
+ #
170
+ # @param options [Hash] command options
171
+ #
172
+ # @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`)
173
+ #
174
+ # @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`)
175
+ #
176
+ # @return [Git::CommandLine::Result] the result of calling `git cat-file`
177
+ #
178
+ # Stdout contains the raw object content
179
+ #
180
+ # @raise [ArgumentError] if unsupported options are provided
181
+ #
182
+ # @raise [Git::FailedError] if the object does not exist or is not of the
183
+ # given type
184
+ #
185
+ # @option options [Numeric, nil] :timeout (nil) abort the command after this many seconds
186
+ #
187
+ def call(*, **)
188
+ bound = args_definition.bind(*, **)
189
+ validate_version!(bound.execution_options)
190
+ result = execute_command(bound)
191
+
192
+ # `-e` treats exit 1 as a meaningful result (object not found), but any other
193
+ # non-zero exit (e.g. 128 for a corrupt object database) is still a failure.
194
+ # All other modes treat every non-zero exit as a failure.
195
+ allowed = result.status.success? || (bound.e? && result.status.exitstatus == 1)
196
+ raise Git::FailedError, result unless allowed
197
+
198
+ result
199
+ end
200
+ end
201
+ end
202
+ end
203
+ 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
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ # Implements the `git checkout-index` command
8
+ #
9
+ # This command copies all files listed in the index to the working directory
10
+ # (not overwriting existing files). It is typically used to populate a new
11
+ # working directory from the current index, optionally scoped to a specific
12
+ # path or prefix.
13
+ #
14
+ # @example Typical usage
15
+ # checkout_index = Git::Commands::CheckoutIndex.new(execution_context)
16
+ # checkout_index.call(all: true)
17
+ # checkout_index.call(all: true, force: true)
18
+ # checkout_index.call('path/to/file.txt')
19
+ # checkout_index.call(all: true, prefix: 'output/')
20
+ #
21
+ # @note `arguments` block audited against https://git-scm.com/docs/git-checkout-index/2.53.0
22
+ #
23
+ # @see https://git-scm.com/docs/git-checkout-index git-checkout-index
24
+ #
25
+ # @see Git::Commands
26
+ #
27
+ # @api private
28
+ #
29
+ class CheckoutIndex < Git::Commands::Base
30
+ arguments do
31
+ literal 'checkout-index'
32
+ flag_option %i[index u]
33
+ flag_option %i[quiet q]
34
+ flag_option %i[all a]
35
+ flag_option %i[force f]
36
+ flag_option %i[no_create n]
37
+ value_option :prefix, inline: true
38
+ value_option :stage, inline: true
39
+ flag_option :temp
40
+ flag_option :ignore_skip_worktree_bits
41
+ end_of_options
42
+ operand :file, required: false, repeatable: true
43
+ end
44
+
45
+ # @overload call(*file, **options)
46
+ #
47
+ # Execute the `git checkout-index` command
48
+ #
49
+ # @param file [Array<String>] zero or more file paths to check out
50
+ #
51
+ # When empty, no files are checked out individually (use `:all` to check
52
+ # out everything).
53
+ #
54
+ # @param options [Hash] command options
55
+ #
56
+ # @option options [Boolean, nil] :index (nil) update stat information for the
57
+ # checked out entries in the index file
58
+ #
59
+ # Alias: `:u`
60
+ #
61
+ # @option options [Boolean, nil] :quiet (nil) suppress messages when files
62
+ # exist or are not in the index
63
+ #
64
+ # Alias: `:q`
65
+ #
66
+ # @option options [Boolean, nil] :all (nil) check out all files in the index
67
+ #
68
+ # Alias: `:a`
69
+ #
70
+ # @option options [Boolean, nil] :force (nil) force overwrite of existing files
71
+ #
72
+ # Alias: `:f`
73
+ #
74
+ # @option options [Boolean, nil] :no_create (nil) don't checkout new files,
75
+ # only refresh files already checked out
76
+ #
77
+ # Alias: `:n`
78
+ #
79
+ # @option options [String] :prefix (nil) write file content under the given
80
+ # directory prefix instead of the working directory root
81
+ #
82
+ # @option options [String] :stage (nil) check out from the named stage
83
+ #
84
+ # Pass `'1'`, `'2'`, or `'3'` for a specific stage number, or `'all'` to
85
+ # check out all stages (automatically implies `--temp`).
86
+ #
87
+ # @option options [Boolean, nil] :temp (nil) write file content to temporary
88
+ # files near the target location instead of checking them out
89
+ #
90
+ # @option options [Boolean, nil] :ignore_skip_worktree_bits (nil) check out
91
+ # all files, including those with the skip-worktree bit set
92
+ #
93
+ # @return [Git::CommandLine::Result] the result of calling `git checkout-index`
94
+ #
95
+ # @raise [ArgumentError] if unsupported options are provided
96
+ #
97
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
98
+ #
99
+ # @api public
100
+ #
101
+ def call(*, **)
102
+ super
103
+ end
104
+ end
105
+ end
106
+ end