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,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module ShowRef
8
+ # Stdin filter mode for `git show-ref --exclude-existing`
9
+ #
10
+ # Reads ref names from the positional arguments, passes them to git's stdin,
11
+ # and outputs only those refs that do NOT already exist in the local repository.
12
+ # Useful for determining which remote refs would be new if fetched.
13
+ #
14
+ # Pass `exclude_existing: 'refs/heads/'` to limit filtering to refs matching
15
+ # the given prefix pattern. By default (no pattern), all refs are evaluated.
16
+ #
17
+ # For standard ref listing, use {Git::Commands::ShowRef::List}.
18
+ # For strict per-ref verification, use {Git::Commands::ShowRef::Verify}.
19
+ # For a boolean existence check (git >= 2.43), use {Git::Commands::ShowRef::Exists}.
20
+ #
21
+ # @example Filter refs that do not exist locally
22
+ # cmd = Git::Commands::ShowRef::ExcludeExisting.new(execution_context)
23
+ # result = cmd.call('refs/heads/main', 'refs/heads/feature')
24
+ # result.stdout # => "abc1234 refs/heads/feature\n"
25
+ #
26
+ # @example Limit filtering to a prefix pattern
27
+ # cmd = Git::Commands::ShowRef::ExcludeExisting.new(execution_context)
28
+ # result = cmd.call('refs/heads/main', exclude_existing: 'refs/heads/')
29
+ # # refs/heads/main already exists locally, so git echoes nothing
30
+ # result.stdout # => ""
31
+ #
32
+ # @note `arguments` block audited against https://git-scm.com/docs/git-show-ref/2.53.0
33
+ #
34
+ # @see Git::Commands::ShowRef
35
+ #
36
+ # @see https://git-scm.com/docs/git-show-ref git-show-ref documentation
37
+ #
38
+ # @api private
39
+ #
40
+ class ExcludeExisting < Git::Commands::Base
41
+ arguments do
42
+ literal 'show-ref'
43
+
44
+ # Mode selector: pass `true` (default) to test all refs, or a pattern
45
+ # string to restrict testing to refs whose names start with the pattern.
46
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---exclude-existingltpatterngt
47
+ flag_or_value_option :exclude_existing, inline: true
48
+
49
+ execution_option :timeout
50
+
51
+ # Ref names to pass to stdin, one per line. Never emitted in git argv.
52
+ operand :ref, repeatable: true, skip_cli: true
53
+ end
54
+
55
+ # @overload call(*ref, exclude_existing: true, **options)
56
+ #
57
+ # Execute `git show-ref --exclude-existing` to filter ref names against the
58
+ # local repository
59
+ #
60
+ # Each ref is passed to git's stdin. Git writes back only
61
+ # the refs that do not already exist locally.
62
+ #
63
+ # @param ref [Array<String>] ref names to test
64
+ #
65
+ # @param exclude_existing [true, String] filter mode selector
66
+ #
67
+ # Pass `true` (default) to test all refs, or a non-empty pattern string to
68
+ # restrict testing to refs whose names start with the pattern
69
+ # (e.g. `'refs/heads/'`). Passing `false` or `nil` raises `ArgumentError`.
70
+ #
71
+ # @param options [Hash] command options
72
+ #
73
+ # @option options [Numeric] :timeout (nil) abort the command after this many
74
+ # seconds
75
+ #
76
+ # @return [Git::CommandLine::Result] the result of calling
77
+ # `git show-ref --exclude-existing`
78
+ #
79
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
80
+ #
81
+ def call(*, exclude_existing: true, **)
82
+ unless exclude_existing == true || (exclude_existing.is_a?(String) && !exclude_existing.empty?)
83
+ raise ArgumentError,
84
+ ":exclude_existing must be true or a non-empty String, got #{exclude_existing.inspect}"
85
+ end
86
+
87
+ bound = args_definition.bind(*, exclude_existing: exclude_existing, **)
88
+ validate_version!(bound.execution_options)
89
+ stdin = Array(bound.ref).map { |r| "#{r}\n" }.join
90
+ with_stdin(stdin) { |reader| run_filter(bound, reader) }
91
+ end
92
+
93
+ private
94
+
95
+ # Run the bound show-ref command, supplying ref names to git via stdin
96
+ #
97
+ # @param bound [Git::Commands::Arguments::Bound] bound argument list
98
+ #
99
+ # @param reader [IO] readable IO connected to git's stdin
100
+ #
101
+ # @return [Git::CommandLine::Result] the result of calling
102
+ # `git show-ref --exclude-existing`
103
+ #
104
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
105
+ #
106
+ def run_filter(bound, reader)
107
+ result = @execution_context.command_capturing(
108
+ *bound,
109
+ in: reader,
110
+ **bound.execution_options,
111
+ raise_on_failure: false
112
+ )
113
+ validate_exit_status!(result)
114
+ result
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module ShowRef
8
+ # Checks whether a single ref exists via `git show-ref --exists`
9
+ #
10
+ # Returns without raising for three exit-status outcomes:
11
+ #
12
+ # - **exit 0** — the ref exists in the local repository
13
+ # - **exit 2** — the ref does not exist (a normal result for an existence check)
14
+ # - **exit 1** — a lookup error occurred (e.g. malformed ref name)
15
+ #
16
+ # Callers inspect `result.status.exitstatus` to distinguish the three states.
17
+ # Unlike {ShowRef::Verify}, this mode never prints any output.
18
+ #
19
+ # For standard ref listing, use {ShowRef::List}.
20
+ # For strict per-ref verification with output, use {ShowRef::Verify}.
21
+ # For stdin-based filtering, use {ShowRef::ExcludeExisting}.
22
+ #
23
+ # @example Check whether a branch exists
24
+ # cmd = Git::Commands::ShowRef::Exists.new(execution_context)
25
+ # result = cmd.call('refs/heads/main')
26
+ # result.status.exitstatus # => 0 (exists) or 2 (not found)
27
+ #
28
+ # @note Requires git 2.43 or later
29
+ #
30
+ # Earlier versions do not recognise the `--exists` flag and will exit
31
+ # non-zero with an "unknown option" error.
32
+ #
33
+ # @note `arguments` block audited against https://git-scm.com/docs/git-show-ref/2.53.0
34
+ #
35
+ # @see Git::Commands::ShowRef
36
+ #
37
+ # @see https://git-scm.com/docs/git-show-ref git-show-ref documentation
38
+ #
39
+ # @api private
40
+ #
41
+ class Exists < Git::Commands::Base
42
+ arguments do
43
+ literal 'show-ref'
44
+ literal '--exists'
45
+ execution_option :timeout
46
+ operand :ref, required: true
47
+ end
48
+
49
+ # Exit status 0 = ref found; 2 = ref not found (expected); 1 = lookup error.
50
+ # All three are valid results — callers check exitstatus to distinguish them.
51
+ allow_exit_status 0..2
52
+
53
+ # @overload call(ref, **options)
54
+ #
55
+ # Execute `git show-ref --exists` to check whether a ref exists
56
+ #
57
+ # @param ref [String] the fully-qualified ref name to check
58
+ # (e.g. `"refs/heads/main"`)
59
+ #
60
+ # @param options [Hash] command options
61
+ #
62
+ # @option options [Numeric] :timeout (nil) abort the command after this many
63
+ # seconds
64
+ #
65
+ # @return [Git::CommandLine::Result] the result of calling
66
+ # `git show-ref --exists`
67
+ #
68
+ # @raise [ArgumentError] if unsupported options are provided
69
+ #
70
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 2)
71
+ #
72
+ # @api public
73
+ #
74
+ def call(*, **)
75
+ super
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module ShowRef
8
+ # Standard ref listing command via `git show-ref`
9
+ #
10
+ # Lists refs stored in the local repository together with their associated
11
+ # commit IDs. When no filters are given, all refs are listed. Filters can
12
+ # narrow output to heads, tags, or refs matching a given pattern.
13
+ #
14
+ # An exit status of 1 is not an error — it indicates that no matching refs
15
+ # were found. Exit status 0 means at least one match was found.
16
+ #
17
+ # For strict per-ref verification, use {Git::Commands::ShowRef::Verify}.
18
+ # For stdin-based filtering, use {Git::Commands::ShowRef::ExcludeExisting}.
19
+ # For a simple boolean existence check (git >= 2.43), use {Git::Commands::ShowRef::Exists}.
20
+ #
21
+ # @example List all refs
22
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
23
+ # result = cmd.call
24
+ # result.stdout # => "abc1234 refs/heads/main\n..."
25
+ #
26
+ # @example List only tags
27
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
28
+ # result = cmd.call(tags: true)
29
+ #
30
+ # @example List with abbreviated SHA hashes
31
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
32
+ # result = cmd.call(hash: 7)
33
+ #
34
+ # @example Match a pattern
35
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
36
+ # result = cmd.call('v1.0', 'v2.0', tags: true)
37
+ #
38
+ # @note `arguments` block audited against https://git-scm.com/docs/git-show-ref/2.53.0
39
+ #
40
+ # @see Git::Commands::ShowRef
41
+ #
42
+ # @see https://git-scm.com/docs/git-show-ref
43
+ #
44
+ # @api private
45
+ #
46
+ class List < Git::Commands::Base
47
+ arguments do
48
+ literal 'show-ref'
49
+
50
+ # Include the HEAD ref even if it would normally be filtered out
51
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---head
52
+ flag_option :head
53
+
54
+ # Dereference annotated tags; outputs an additional line per tag with
55
+ # the de-referenced object SHA followed by `^{}`
56
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---dereference
57
+ flag_option %i[dereference d]
58
+
59
+ # Show only the SHA part of the ref, optionally abbreviated to <n> hex digits;
60
+ # pass `true` for full-length SHA, or an integer for the abbreviation length
61
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---hashn
62
+ flag_or_value_option %i[hash s], inline: true
63
+
64
+ # Abbreviate the object names to at least <n> hex digits; pass `true` to
65
+ # use the default abbreviation length, or an integer for an explicit length
66
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---abbrevlength
67
+ flag_or_value_option :abbrev, inline: true
68
+
69
+ # Limit to refs under refs/heads/ only (preferred over :heads on git >= 2.46)
70
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---branches
71
+ flag_option :branches
72
+
73
+ # Limit to refs under refs/heads/ only (deprecated synonym for :branches in git >= 2.46)
74
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---branches
75
+ flag_option :heads
76
+
77
+ # Limit to refs under refs/tags/ only
78
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---tags
79
+ flag_option :tags
80
+
81
+ execution_option :timeout
82
+
83
+ end_of_options
84
+
85
+ # Optional glob patterns; only refs whose names contain a match are shown.
86
+ # Patterns are matched against the full ref name (without the leading `refs/`
87
+ # prefix on older git versions; full path on newer ones).
88
+ operand :pattern, repeatable: true
89
+ end
90
+
91
+ # Exit status 1 means no refs matched; that is a normal (non-error) outcome
92
+ allow_exit_status 0..1
93
+
94
+ # @overload call(*pattern, **options)
95
+ #
96
+ # Execute `git show-ref` to list matching refs
97
+ #
98
+ # @param pattern [Array<String>] zero or more patterns to filter refs
99
+ #
100
+ # When empty, all refs are listed.
101
+ #
102
+ # @param options [Hash] command options
103
+ #
104
+ # @option options [Boolean, nil] :head (nil) show the HEAD ref even when filtered
105
+ #
106
+ # @option options [Boolean, nil] :dereference (nil) dereference annotated tags,
107
+ # emitting an extra line per tag whose SHA points to the tagged object
108
+ #
109
+ # Alias: `:d`
110
+ #
111
+ # @option options [Boolean, Integer, nil] :hash (nil) show only the SHA part of each ref
112
+ #
113
+ # Pass `true` for full-length SHAs or an integer for the abbreviation length
114
+ # (e.g. `hash: 7`).
115
+ #
116
+ # Alias: `:s`
117
+ #
118
+ # @option options [Boolean, Integer, nil] :abbrev (nil) abbreviate object names
119
+ #
120
+ # Pass `true` for the default length or an integer for a specific length.
121
+ #
122
+ # @option options [Boolean, nil] :branches (nil) limit output to local branches (refs/heads/)
123
+ #
124
+ # Prefer `:branches` over `:heads` on git >= 2.46; `:heads` emits the deprecated
125
+ # `--heads` flag.
126
+ #
127
+ # @option options [Boolean, nil] :heads (nil) limit output to refs under refs/heads/
128
+ #
129
+ # Deprecated at the git level in git 2.46. Use `:branches` instead.
130
+ #
131
+ # @option options [Boolean, nil] :tags (nil) limit output to refs under refs/tags/
132
+ #
133
+ # @option options [Numeric] :timeout (nil) abort the command after this many seconds
134
+ #
135
+ # @return [Git::CommandLine::Result] the result of calling `git show-ref`
136
+ #
137
+ # @raise [ArgumentError] if unsupported options are provided
138
+ #
139
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 1)
140
+ #
141
+ # @api public
142
+ #
143
+ def call(*, **)
144
+ super
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module ShowRef
8
+ # Strict per-ref verification command via `git show-ref --verify`
9
+ #
10
+ # Verifies that refs exist by their full canonical name (e.g.
11
+ # `refs/heads/main`, `refs/tags/v1.0`). Unlike {ShowRef::List}, partial
12
+ # name matching is not performed. Every named ref must start with `refs/`
13
+ # (or be `HEAD`); anything else will cause git to exit non-zero.
14
+ #
15
+ # When a ref cannot be resolved, git exits 1 and this class raises
16
+ # {Git::FailedError}. This strict behaviour makes the class suitable for
17
+ # validating that refs are fully qualified.
18
+ #
19
+ # For pattern-based listing, use {ShowRef::List}.
20
+ # For stdin-based filtering, use {ShowRef::ExcludeExisting}.
21
+ # For a silent boolean check (git >= 2.43), use {ShowRef::Exists}.
22
+ #
23
+ # @example Verify a single ref
24
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
25
+ # result = cmd.call('refs/heads/main')
26
+ # result.stdout # => "abc1234 refs/heads/main\n"
27
+ #
28
+ # @example Verify with hash-only output
29
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
30
+ # result = cmd.call('refs/heads/main', hash: true)
31
+ # result.stdout # => "abc1234\n"
32
+ #
33
+ # @example Silent existence check
34
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
35
+ # cmd.call('refs/heads/main', quiet: true) # raises FailedError if not found
36
+ #
37
+ # @note `arguments` block audited against https://git-scm.com/docs/git-show-ref/2.53.0
38
+ #
39
+ # @see Git::Commands::ShowRef
40
+ #
41
+ # @see https://git-scm.com/docs/git-show-ref git-show-ref documentation
42
+ #
43
+ # @api private
44
+ #
45
+ class Verify < Git::Commands::Base
46
+ arguments do
47
+ literal 'show-ref'
48
+ literal '--verify'
49
+
50
+ # Suppress output; useful when you only care whether the ref exists
51
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---quiet
52
+ flag_option %i[quiet q]
53
+
54
+ # Dereference annotated tags; emit an extra line per tag with SHA^{}
55
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---dereference
56
+ flag_option %i[dereference d]
57
+
58
+ # Show only the SHA; pass `true` for full-length or an integer for abbreviated length
59
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---hashn
60
+ flag_or_value_option %i[hash s], inline: true
61
+
62
+ # Abbreviate object names; pass `true` for default or integer for explicit length
63
+ # See https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---abbrevlength
64
+ flag_or_value_option :abbrev, inline: true
65
+
66
+ execution_option :timeout
67
+
68
+ end_of_options
69
+
70
+ # One or more fully-qualified ref names to verify (e.g. `refs/heads/main`)
71
+ operand :ref, repeatable: true, required: true
72
+ end
73
+
74
+ # @overload call(*ref, **options)
75
+ #
76
+ # Execute `git show-ref --verify` to verify refs by their full name
77
+ #
78
+ # @param ref [Array<String>] one or more fully-qualified ref names
79
+ #
80
+ # Each name must begin with `refs/` (or be `HEAD`). At least one is required.
81
+ #
82
+ # @param options [Hash] command options
83
+ #
84
+ # @option options [Boolean, nil] :quiet (nil) suppress all output
85
+ #
86
+ # Useful when you only care whether the ref exists.
87
+ #
88
+ # Alias: `:q`
89
+ #
90
+ # @option options [Boolean, nil] :dereference (nil) dereference annotated tags,
91
+ # emitting an extra `^{}` line per tag
92
+ #
93
+ # Alias: `:d`
94
+ #
95
+ # @option options [Boolean, Integer, nil] :hash (nil) show only the SHA part
96
+ #
97
+ # Pass `true` for full-length SHAs or an integer for abbreviation length.
98
+ #
99
+ # Alias: `:s`
100
+ #
101
+ # @option options [Boolean, Integer, nil] :abbrev (nil) abbreviate object names
102
+ #
103
+ # Pass `true` for the default length or an integer for a specific length.
104
+ #
105
+ # @option options [Numeric] :timeout (nil) abort the command after this many
106
+ # seconds
107
+ #
108
+ # @return [Git::CommandLine::Result] the result of calling `git show-ref --verify`
109
+ #
110
+ # @raise [ArgumentError] if unsupported options are provided
111
+ #
112
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
113
+ #
114
+ # @api public
115
+ #
116
+ def call(*, **)
117
+ super
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'show_ref/exclude_existing'
4
+ require_relative 'show_ref/exists'
5
+ require_relative 'show_ref/list'
6
+ require_relative 'show_ref/verify'
7
+
8
+ module Git
9
+ module Commands
10
+ # Commands for querying git refs via `git show-ref`
11
+ #
12
+ # This module contains command classes split by invocation mode:
13
+ #
14
+ # - {ShowRef::List} — standard ref listing with optional pattern filtering
15
+ # (`git show-ref [options] [<pattern>...]`)
16
+ # - {ShowRef::Verify} — strict per-ref verification by full refname
17
+ # (`git show-ref --verify [options] [<ref>...]`)
18
+ # - {ShowRef::ExcludeExisting} — stdin-based filter for ref names, excluding
19
+ # refs that already exist in the repository
20
+ # (`git show-ref --exclude-existing[=<pattern>]`)
21
+ # - {ShowRef::Exists} — boolean existence check without output (git >= 2.43)
22
+ # (`git show-ref --exists <ref>`)
23
+ #
24
+ # @example List all refs matching a pattern
25
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
26
+ # result = cmd.call('refs/tags/', tags: true)
27
+ # result.stdout
28
+ # # => "abc1234 refs/tags/v1.0\ndef5678 refs/tags/v2.0\n"
29
+ #
30
+ # @example Verify a specific ref
31
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
32
+ # result = cmd.call('refs/heads/main')
33
+ # result.stdout # => "abc1234 refs/heads/main\n"
34
+ #
35
+ # @see https://git-scm.com/docs/git-show-ref git-show-ref documentation
36
+ #
37
+ # @api private
38
+ #
39
+ module ShowRef
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module Stash
8
+ # Apply stashed changes to the working directory
9
+ #
10
+ # Applies the changes recorded in a stash to the working tree.
11
+ # Unlike {Pop}, this does not remove the stash from the stash list.
12
+ #
13
+ # @example Apply the latest stash
14
+ # Git::Commands::Stash::Apply.new(execution_context).call
15
+ #
16
+ # @example Apply a specific stash
17
+ # Git::Commands::Stash::Apply.new(execution_context).call('stash@\\{2}')
18
+ #
19
+ # @example Apply and restore index state
20
+ # Git::Commands::Stash::Apply.new(execution_context).call(index: true)
21
+ #
22
+ # @note `arguments` block audited against https://git-scm.com/docs/git-stash/2.53.0
23
+ #
24
+ # @see Git::Commands::Stash Git::Commands::Stash for usage examples
25
+ #
26
+ # @see https://git-scm.com/docs/git-stash git-stash documentation
27
+ #
28
+ # @api private
29
+ #
30
+ class Apply < Git::Commands::Base
31
+ arguments do
32
+ literal 'stash'
33
+ literal 'apply'
34
+ flag_option :index
35
+ flag_option %i[quiet q]
36
+ operand :stash
37
+ end
38
+
39
+ # @overload call(**options)
40
+ #
41
+ # Apply the latest stash
42
+ #
43
+ # @param options [Hash] command options
44
+ #
45
+ # @option options [Boolean, nil] :index (nil) restore the index state as well
46
+ #
47
+ # @option options [Boolean, nil] :quiet (nil) suppress informational messages
48
+ #
49
+ # Alias: :q
50
+ #
51
+ # @raise [ArgumentError] if unsupported options are provided
52
+ #
53
+ # @overload call(stash, **options)
54
+ #
55
+ # Apply a specific stash
56
+ #
57
+ # @param stash [String] stash reference (e.g., 'stash@\\{0}', '0')
58
+ #
59
+ # @param options [Hash] command options
60
+ #
61
+ # @option options [Boolean, nil] :index (nil) restore the index state as well
62
+ #
63
+ # @option options [Boolean, nil] :quiet (nil) suppress informational messages
64
+ #
65
+ # Alias: :q
66
+ #
67
+ # @raise [ArgumentError] if unsupported options are provided
68
+ #
69
+ # @return [Git::CommandLine::Result] the result of calling `git stash apply`
70
+ #
71
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
72
+ #
73
+ # @api public
74
+ #
75
+ def call(*, **)
76
+ super
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module Stash
8
+ # Create a branch from a stash entry
9
+ #
10
+ # Creates a new branch starting from the commit at which the stash was
11
+ # originally created, applies the stashed changes, and then drops the stash
12
+ # if the changes are applied successfully.
13
+ #
14
+ # This is useful if the branch on which you ran `git stash push` has changed
15
+ # enough that `git stash apply` fails due to conflicts. The new branch will
16
+ # be created at the commit that was HEAD when the stash was created, so
17
+ # applying the stash should succeed.
18
+ #
19
+ # @example Create branch from latest stash
20
+ # Git::Commands::Stash::Branch.new(execution_context).call('my-branch')
21
+ #
22
+ # @example Create branch from specific stash
23
+ # Git::Commands::Stash::Branch.new(execution_context).call('my-branch', 'stash@{2}')
24
+ #
25
+ # @note `arguments` block audited against https://git-scm.com/docs/git-stash/2.53.0
26
+ #
27
+ # @see Git::Commands::Stash Git::Commands::Stash for usage examples
28
+ #
29
+ # @see https://git-scm.com/docs/git-stash git-stash documentation
30
+ #
31
+ # @api private
32
+ #
33
+ class Branch < Git::Commands::Base
34
+ arguments do
35
+ literal 'stash'
36
+ literal 'branch'
37
+ operand :branchname, required: true
38
+ operand :stash
39
+ end
40
+
41
+ # @!method call(*)
42
+ #
43
+ # Create a branch from a stash entry
44
+ #
45
+ # @overload call(branchname)
46
+ #
47
+ # Create a branch from the latest stash
48
+ #
49
+ # @param branchname [String] the name of the branch to create (required)
50
+ #
51
+ # @overload call(branchname, stash)
52
+ #
53
+ # Create a branch from a specific stash
54
+ #
55
+ # @param branchname [String] the name of the branch to create (required)
56
+ #
57
+ # @param stash [String] stash reference (e.g., 'stash@\\{0}', '0')
58
+ #
59
+ # @return [Git::CommandLine::Result] the result of calling `git stash branch`
60
+ #
61
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
62
+ #
63
+ # @api public
64
+ end
65
+ end
66
+ end
67
+ end