git 4.3.2 → 5.0.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.github/copilot-instructions.md +67 -2705
  3. data/.github/pull_request_template.md +3 -1
  4. data/.github/skills/breaking-change-analysis/SKILL.md +102 -0
  5. data/.github/skills/ci-cd-troubleshooting/SKILL.md +264 -0
  6. data/.github/skills/command-implementation/REFERENCE.md +993 -0
  7. data/.github/skills/command-implementation/SKILL.md +229 -0
  8. data/.github/skills/command-test-conventions/SKILL.md +660 -0
  9. data/.github/skills/command-yard-documentation/SKILL.md +426 -0
  10. data/.github/skills/dependency-management/SKILL.md +72 -0
  11. data/.github/skills/development-workflow/SKILL.md +506 -0
  12. data/.github/skills/extract-command-from-lib/SKILL.md +487 -0
  13. data/.github/skills/extract-facade-from-base-lib/SKILL.md +586 -0
  14. data/.github/skills/facade-implementation/REFERENCE.md +840 -0
  15. data/.github/skills/facade-implementation/SKILL.md +260 -0
  16. data/.github/skills/facade-test-conventions/SKILL.md +380 -0
  17. data/.github/skills/facade-yard-documentation/SKILL.md +429 -0
  18. data/.github/skills/make-skill-template/SKILL.md +176 -0
  19. data/.github/skills/pr-readiness-review/SKILL.md +185 -0
  20. data/.github/skills/project-context/SKILL.md +313 -0
  21. data/.github/skills/pull-request-review/SKILL.md +168 -0
  22. data/.github/skills/refactor-command-to-commandlineresult/SKILL.md +131 -0
  23. data/.github/skills/release-management/SKILL.md +125 -0
  24. data/.github/skills/review-arguments-dsl/CHECKLIST.md +788 -0
  25. data/.github/skills/review-arguments-dsl/SKILL.md +214 -0
  26. data/.github/skills/review-backward-compatibility/SKILL.md +275 -0
  27. data/.github/skills/review-cross-command-consistency/SKILL.md +139 -0
  28. data/.github/skills/reviewing-skills/SKILL.md +189 -0
  29. data/.github/skills/rspec-unit-testing-standards/SKILL.md +639 -0
  30. data/.github/skills/tdd-refactor-step/SKILL.md +236 -0
  31. data/.github/skills/test-debugging/SKILL.md +160 -0
  32. data/.github/skills/yard-documentation/SKILL.md +793 -0
  33. data/.github/workflows/continuous_integration.yml +3 -2
  34. data/.github/workflows/enforce_conventional_commits.yml +1 -1
  35. data/.github/workflows/experimental_continuous_integration.yml +2 -2
  36. data/.github/workflows/release.yml +3 -4
  37. data/.gitignore +8 -0
  38. data/.husky/pre-commit +13 -0
  39. data/.release-please-manifest.json +1 -1
  40. data/.rspec +3 -0
  41. data/.rubocop.yml +7 -3
  42. data/.rubocop_todo.yml +23 -5
  43. data/.yardopts +1 -0
  44. data/CHANGELOG.md +0 -40
  45. data/CONTRIBUTING.md +694 -53
  46. data/README.md +17 -5
  47. data/Rakefile +61 -9
  48. data/commitlint.test +4 -0
  49. data/git.gemspec +14 -8
  50. data/lib/git/args_builder.rb +0 -8
  51. data/lib/git/base.rb +486 -410
  52. data/lib/git/branch.rb +380 -43
  53. data/lib/git/branch_delete_failure.rb +31 -0
  54. data/lib/git/branch_delete_result.rb +63 -0
  55. data/lib/git/branch_info.rb +178 -0
  56. data/lib/git/branches.rb +130 -24
  57. data/lib/git/command_line/base.rb +245 -0
  58. data/lib/git/command_line/capturing.rb +249 -0
  59. data/lib/git/command_line/result.rb +96 -0
  60. data/lib/git/command_line/streaming.rb +194 -0
  61. data/lib/git/command_line.rb +43 -322
  62. data/lib/git/command_line_result.rb +4 -88
  63. data/lib/git/commands/add.rb +131 -0
  64. data/lib/git/commands/am/abort.rb +43 -0
  65. data/lib/git/commands/am/apply.rb +252 -0
  66. data/lib/git/commands/am/continue.rb +43 -0
  67. data/lib/git/commands/am/quit.rb +43 -0
  68. data/lib/git/commands/am/retry.rb +47 -0
  69. data/lib/git/commands/am/show_current_patch.rb +64 -0
  70. data/lib/git/commands/am/skip.rb +42 -0
  71. data/lib/git/commands/am.rb +33 -0
  72. data/lib/git/commands/apply.rb +237 -0
  73. data/lib/git/commands/archive/list_formats.rb +46 -0
  74. data/lib/git/commands/archive.rb +140 -0
  75. data/lib/git/commands/arguments.rb +3510 -0
  76. data/lib/git/commands/base.rb +403 -0
  77. data/lib/git/commands/branch/copy.rb +94 -0
  78. data/lib/git/commands/branch/create.rb +173 -0
  79. data/lib/git/commands/branch/delete.rb +80 -0
  80. data/lib/git/commands/branch/list.rb +162 -0
  81. data/lib/git/commands/branch/move.rb +94 -0
  82. data/lib/git/commands/branch/set_upstream.rb +86 -0
  83. data/lib/git/commands/branch/show_current.rb +49 -0
  84. data/lib/git/commands/branch/unset_upstream.rb +57 -0
  85. data/lib/git/commands/branch.rb +34 -0
  86. data/lib/git/commands/cat_file/batch.rb +364 -0
  87. data/lib/git/commands/cat_file/filtered.rb +105 -0
  88. data/lib/git/commands/cat_file/raw.rb +210 -0
  89. data/lib/git/commands/cat_file.rb +49 -0
  90. data/lib/git/commands/checkout/branch.rb +151 -0
  91. data/lib/git/commands/checkout/files.rb +115 -0
  92. data/lib/git/commands/checkout.rb +38 -0
  93. data/lib/git/commands/checkout_index.rb +105 -0
  94. data/lib/git/commands/clean.rb +100 -0
  95. data/lib/git/commands/clone.rb +240 -0
  96. data/lib/git/commands/commit.rb +272 -0
  97. data/lib/git/commands/commit_tree.rb +100 -0
  98. data/lib/git/commands/config_option_syntax/add.rb +83 -0
  99. data/lib/git/commands/config_option_syntax/get.rb +117 -0
  100. data/lib/git/commands/config_option_syntax/get_all.rb +115 -0
  101. data/lib/git/commands/config_option_syntax/get_color.rb +91 -0
  102. data/lib/git/commands/config_option_syntax/get_color_bool.rb +93 -0
  103. data/lib/git/commands/config_option_syntax/get_regexp.rb +115 -0
  104. data/lib/git/commands/config_option_syntax/get_urlmatch.rb +102 -0
  105. data/lib/git/commands/config_option_syntax/list.rb +107 -0
  106. data/lib/git/commands/config_option_syntax/remove_section.rb +74 -0
  107. data/lib/git/commands/config_option_syntax/rename_section.rb +78 -0
  108. data/lib/git/commands/config_option_syntax/replace_all.rb +104 -0
  109. data/lib/git/commands/config_option_syntax/set.rb +114 -0
  110. data/lib/git/commands/config_option_syntax/unset.rb +89 -0
  111. data/lib/git/commands/config_option_syntax/unset_all.rb +89 -0
  112. data/lib/git/commands/config_option_syntax.rb +56 -0
  113. data/lib/git/commands/describe.rb +155 -0
  114. data/lib/git/commands/diff.rb +656 -0
  115. data/lib/git/commands/diff_files.rb +518 -0
  116. data/lib/git/commands/diff_index.rb +496 -0
  117. data/lib/git/commands/fetch.rb +352 -0
  118. data/lib/git/commands/fsck.rb +136 -0
  119. data/lib/git/commands/gc.rb +132 -0
  120. data/lib/git/commands/grep.rb +338 -0
  121. data/lib/git/commands/init.rb +99 -0
  122. data/lib/git/commands/log.rb +632 -0
  123. data/lib/git/commands/ls_files.rb +191 -0
  124. data/lib/git/commands/ls_remote.rb +155 -0
  125. data/lib/git/commands/ls_tree.rb +131 -0
  126. data/lib/git/commands/maintenance/register.rb +75 -0
  127. data/lib/git/commands/maintenance/run.rb +104 -0
  128. data/lib/git/commands/maintenance/start.rb +66 -0
  129. data/lib/git/commands/maintenance/stop.rb +55 -0
  130. data/lib/git/commands/maintenance/unregister.rb +79 -0
  131. data/lib/git/commands/maintenance.rb +31 -0
  132. data/lib/git/commands/merge/abort.rb +44 -0
  133. data/lib/git/commands/merge/continue.rb +44 -0
  134. data/lib/git/commands/merge/quit.rb +46 -0
  135. data/lib/git/commands/merge/start.rb +245 -0
  136. data/lib/git/commands/merge.rb +28 -0
  137. data/lib/git/commands/merge_base.rb +86 -0
  138. data/lib/git/commands/mv.rb +77 -0
  139. data/lib/git/commands/name_rev.rb +114 -0
  140. data/lib/git/commands/pull.rb +377 -0
  141. data/lib/git/commands/push.rb +246 -0
  142. data/lib/git/commands/read_tree.rb +149 -0
  143. data/lib/git/commands/remote/add.rb +91 -0
  144. data/lib/git/commands/remote/get_url.rb +66 -0
  145. data/lib/git/commands/remote/list.rb +54 -0
  146. data/lib/git/commands/remote/prune.rb +61 -0
  147. data/lib/git/commands/remote/remove.rb +52 -0
  148. data/lib/git/commands/remote/rename.rb +69 -0
  149. data/lib/git/commands/remote/set_branches.rb +63 -0
  150. data/lib/git/commands/remote/set_head.rb +82 -0
  151. data/lib/git/commands/remote/set_url.rb +71 -0
  152. data/lib/git/commands/remote/set_url_add.rb +61 -0
  153. data/lib/git/commands/remote/set_url_delete.rb +64 -0
  154. data/lib/git/commands/remote/show.rb +71 -0
  155. data/lib/git/commands/remote/update.rb +72 -0
  156. data/lib/git/commands/remote.rb +42 -0
  157. data/lib/git/commands/repack.rb +277 -0
  158. data/lib/git/commands/reset.rb +147 -0
  159. data/lib/git/commands/rev_parse.rb +297 -0
  160. data/lib/git/commands/revert/abort.rb +45 -0
  161. data/lib/git/commands/revert/continue.rb +57 -0
  162. data/lib/git/commands/revert/quit.rb +47 -0
  163. data/lib/git/commands/revert/skip.rb +44 -0
  164. data/lib/git/commands/revert/start.rb +153 -0
  165. data/lib/git/commands/revert.rb +29 -0
  166. data/lib/git/commands/rm.rb +114 -0
  167. data/lib/git/commands/show.rb +632 -0
  168. data/lib/git/commands/show_ref/exclude_existing.rb +120 -0
  169. data/lib/git/commands/show_ref/exists.rb +78 -0
  170. data/lib/git/commands/show_ref/list.rb +145 -0
  171. data/lib/git/commands/show_ref/verify.rb +120 -0
  172. data/lib/git/commands/show_ref.rb +42 -0
  173. data/lib/git/commands/stash/apply.rb +75 -0
  174. data/lib/git/commands/stash/branch.rb +65 -0
  175. data/lib/git/commands/stash/clear.rb +41 -0
  176. data/lib/git/commands/stash/create.rb +58 -0
  177. data/lib/git/commands/stash/drop.rb +67 -0
  178. data/lib/git/commands/stash/list.rb +39 -0
  179. data/lib/git/commands/stash/pop.rb +78 -0
  180. data/lib/git/commands/stash/push.rb +103 -0
  181. data/lib/git/commands/stash/show.rb +149 -0
  182. data/lib/git/commands/stash/store.rb +63 -0
  183. data/lib/git/commands/stash.rb +38 -0
  184. data/lib/git/commands/status.rb +169 -0
  185. data/lib/git/commands/symbolic_ref/delete.rb +68 -0
  186. data/lib/git/commands/symbolic_ref/read.rb +95 -0
  187. data/lib/git/commands/symbolic_ref/update.rb +76 -0
  188. data/lib/git/commands/symbolic_ref.rb +38 -0
  189. data/lib/git/commands/tag/create.rb +139 -0
  190. data/lib/git/commands/tag/delete.rb +55 -0
  191. data/lib/git/commands/tag/list.rb +143 -0
  192. data/lib/git/commands/tag/verify.rb +71 -0
  193. data/lib/git/commands/tag.rb +26 -0
  194. data/lib/git/commands/update_ref/batch.rb +140 -0
  195. data/lib/git/commands/update_ref/delete.rb +92 -0
  196. data/lib/git/commands/update_ref/update.rb +106 -0
  197. data/lib/git/commands/update_ref.rb +42 -0
  198. data/lib/git/commands/version.rb +52 -0
  199. data/lib/git/commands/worktree/add.rb +140 -0
  200. data/lib/git/commands/worktree/list.rb +64 -0
  201. data/lib/git/commands/worktree/lock.rb +58 -0
  202. data/lib/git/commands/worktree/management_base.rb +51 -0
  203. data/lib/git/commands/worktree/move.rb +66 -0
  204. data/lib/git/commands/worktree/prune.rb +67 -0
  205. data/lib/git/commands/worktree/remove.rb +63 -0
  206. data/lib/git/commands/worktree/repair.rb +76 -0
  207. data/lib/git/commands/worktree/unlock.rb +47 -0
  208. data/lib/git/commands/worktree.rb +43 -0
  209. data/lib/git/commands/write_tree.rb +68 -0
  210. data/lib/git/commands.rb +89 -0
  211. data/lib/git/detached_head_info.rb +54 -0
  212. data/lib/git/diff.rb +297 -7
  213. data/lib/git/diff_file_numstat_info.rb +29 -0
  214. data/lib/git/diff_file_patch_info.rb +134 -0
  215. data/lib/git/diff_file_raw_info.rb +127 -0
  216. data/lib/git/diff_info.rb +169 -0
  217. data/lib/git/diff_path_status.rb +78 -19
  218. data/lib/git/diff_result.rb +32 -0
  219. data/lib/git/diff_stats.rb +59 -14
  220. data/lib/git/dirstat_info.rb +86 -0
  221. data/lib/git/errors.rb +65 -2
  222. data/lib/git/execution_context/global.rb +56 -0
  223. data/lib/git/execution_context/repository.rb +147 -0
  224. data/lib/git/execution_context.rb +482 -0
  225. data/lib/git/file_ref.rb +74 -0
  226. data/lib/git/fsck_object.rb +9 -9
  227. data/lib/git/fsck_result.rb +1 -1
  228. data/lib/git/lib.rb +1606 -1028
  229. data/lib/git/log.rb +15 -2
  230. data/lib/git/object.rb +92 -22
  231. data/lib/git/parsers/branch.rb +224 -0
  232. data/lib/git/parsers/cat_file.rb +111 -0
  233. data/lib/git/parsers/diff.rb +585 -0
  234. data/lib/git/parsers/fsck.rb +133 -0
  235. data/lib/git/parsers/grep.rb +42 -0
  236. data/lib/git/parsers/ls_tree.rb +58 -0
  237. data/lib/git/parsers/stash.rb +208 -0
  238. data/lib/git/parsers/tag.rb +257 -0
  239. data/lib/git/remote.rb +133 -9
  240. data/lib/git/repository/branching.rb +572 -0
  241. data/lib/git/repository/committing.rb +191 -0
  242. data/lib/git/repository/configuring.rb +156 -0
  243. data/lib/git/repository/diffing.rb +775 -0
  244. data/lib/git/repository/inspecting.rb +153 -0
  245. data/lib/git/repository/logging.rb +247 -0
  246. data/lib/git/repository/merging.rb +295 -0
  247. data/lib/git/repository/object_operations.rb +1101 -0
  248. data/lib/git/repository/path_resolver.rb +207 -0
  249. data/lib/git/repository/remote_operations.rb +753 -0
  250. data/lib/git/repository/shared_private.rb +51 -0
  251. data/lib/git/repository/staging.rb +390 -0
  252. data/lib/git/repository/stashing.rb +107 -0
  253. data/lib/git/repository/status_operations.rb +180 -0
  254. data/lib/git/repository/worktree_operations.rb +159 -0
  255. data/lib/git/repository.rb +264 -1
  256. data/lib/git/stash.rb +85 -4
  257. data/lib/git/stash_info.rb +104 -0
  258. data/lib/git/stashes.rb +130 -13
  259. data/lib/git/status.rb +224 -18
  260. data/lib/git/tag_delete_failure.rb +31 -0
  261. data/lib/git/tag_delete_result.rb +63 -0
  262. data/lib/git/tag_info.rb +105 -0
  263. data/lib/git/version.rb +109 -2
  264. data/lib/git/version_constraint.rb +81 -0
  265. data/lib/git/worktree.rb +120 -5
  266. data/lib/git/worktrees.rb +107 -7
  267. data/lib/git.rb +114 -18
  268. data/redesign/1_architecture_existing.md +54 -18
  269. data/redesign/2_architecture_redesign.md +365 -46
  270. data/redesign/3_architecture_implementation.md +1451 -54
  271. data/tasks/gem_tasks.rake +4 -0
  272. data/tasks/npm_tasks.rake +7 -0
  273. data/tasks/rspec.rake +48 -0
  274. data/tasks/test.rake +13 -1
  275. data/tasks/yard.rake +34 -7
  276. metadata +349 -20
  277. data/lib/git/index.rb +0 -6
  278. data/lib/git/path.rb +0 -38
  279. data/lib/git/working_directory.rb +0 -6
  280. /data/{release-please-config.json → .release-please-config.json} +0 -0
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+ require 'git/commands/show_ref'
5
+
6
+ module Git
7
+ module Commands
8
+ module ShowRef
9
+ # Stdin filter mode for `git show-ref --exclude-existing`
10
+ #
11
+ # Reads ref names from the positional arguments, passes them to git's stdin,
12
+ # and outputs only those refs that do NOT already exist in the local repository.
13
+ # Useful for determining which remote refs would be new if fetched.
14
+ #
15
+ # Pass `exclude_existing: 'refs/heads/'` to limit filtering to refs matching
16
+ # the given prefix pattern. By default (no pattern), all refs are evaluated.
17
+ #
18
+ # For standard ref listing, use {Git::Commands::ShowRef::List}.
19
+ # For strict per-ref verification, use {Git::Commands::ShowRef::Verify}.
20
+ # For a boolean existence check (git >= 2.43), use {Git::Commands::ShowRef::Exists}.
21
+ #
22
+ # @example Filter refs that do not exist locally
23
+ # cmd = Git::Commands::ShowRef::ExcludeExisting.new(execution_context)
24
+ # result = cmd.call('refs/heads/main', 'refs/heads/feature')
25
+ # result.stdout # => "abc1234 refs/heads/feature\n"
26
+ #
27
+ # @example Limit filtering to a prefix pattern
28
+ # cmd = Git::Commands::ShowRef::ExcludeExisting.new(execution_context)
29
+ # result = cmd.call('refs/heads/main', exclude_existing: 'refs/heads/')
30
+ # # refs/heads/main already exists locally, so git echoes nothing
31
+ # result.stdout # => ""
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 ExcludeExisting < Git::Commands::Base
42
+ arguments do
43
+ literal 'show-ref'
44
+
45
+ # Mode selector: pass `true` (default) to test all refs, or a pattern
46
+ # string to restrict testing to refs whose names start with the pattern.
47
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---exclude-existingltpatterngt
48
+ flag_or_value_option :exclude_existing, inline: true
49
+
50
+ execution_option :timeout
51
+
52
+ # Ref names to pass to stdin, one per line. Never emitted in git argv.
53
+ operand :ref, repeatable: true, skip_cli: true
54
+ end
55
+
56
+ # @overload call(*ref, exclude_existing: true, **options)
57
+ #
58
+ # Execute `git show-ref --exclude-existing` to filter ref names against the
59
+ # local repository
60
+ #
61
+ # Each ref is passed to git's stdin. Git writes back only
62
+ # the refs that do not already exist locally.
63
+ #
64
+ # @param ref [Array<String>] ref names to test
65
+ #
66
+ # @param exclude_existing [true, String] filter mode selector
67
+ #
68
+ # Pass `true` (default) to test all refs, or a non-empty pattern string to
69
+ # restrict testing to refs whose names start with the pattern
70
+ # (e.g. `'refs/heads/'`). Passing `false` or `nil` raises `ArgumentError`.
71
+ #
72
+ # @param options [Hash] command options
73
+ #
74
+ # @option options [Numeric] :timeout (nil) abort the command after this many
75
+ # seconds
76
+ #
77
+ # @return [Git::CommandLineResult] the result of calling
78
+ # `git show-ref --exclude-existing`
79
+ #
80
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
81
+ #
82
+ def call(*, exclude_existing: true, **)
83
+ unless exclude_existing == true || (exclude_existing.is_a?(String) && !exclude_existing.empty?)
84
+ raise ArgumentError,
85
+ ":exclude_existing must be true or a non-empty String, got #{exclude_existing.inspect}"
86
+ end
87
+
88
+ bound = args_definition.bind(*, exclude_existing: exclude_existing, **)
89
+ validate_version!
90
+ stdin = Array(bound.ref).map { |r| "#{r}\n" }.join
91
+ with_stdin(stdin) { |reader| run_filter(bound, reader) }
92
+ end
93
+
94
+ private
95
+
96
+ # Run the bound show-ref command, supplying ref names to git via stdin
97
+ #
98
+ # @param bound [Git::Commands::Arguments::Bound] bound argument list
99
+ #
100
+ # @param reader [IO] readable IO connected to git's stdin
101
+ #
102
+ # @return [Git::CommandLineResult] the result of calling
103
+ # `git show-ref --exclude-existing`
104
+ #
105
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
106
+ #
107
+ def run_filter(bound, reader)
108
+ result = @execution_context.command_capturing(
109
+ *bound,
110
+ in: reader,
111
+ **bound.execution_options,
112
+ raise_on_failure: false
113
+ )
114
+ validate_exit_status!(result)
115
+ result
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+ require 'git/commands/show_ref'
5
+
6
+ module Git
7
+ module Commands
8
+ module ShowRef
9
+ # Checks whether a single ref exists via `git show-ref --exists`
10
+ #
11
+ # Returns without raising for three exit-status outcomes:
12
+ #
13
+ # - **exit 0** — the ref exists in the local repository
14
+ # - **exit 2** — the ref does not exist (a normal result for an existence check)
15
+ # - **exit 1** — a lookup error occurred (e.g. malformed ref name)
16
+ #
17
+ # Callers inspect `result.status.exitstatus` to distinguish the three states.
18
+ # Unlike {ShowRef::Verify}, this mode never prints any output.
19
+ #
20
+ # For standard ref listing, use {ShowRef::List}.
21
+ # For strict per-ref verification with output, use {ShowRef::Verify}.
22
+ # For stdin-based filtering, use {ShowRef::ExcludeExisting}.
23
+ #
24
+ # @example Check whether a branch exists
25
+ # cmd = Git::Commands::ShowRef::Exists.new(execution_context)
26
+ # result = cmd.call('refs/heads/main')
27
+ # result.status.exitstatus # => 0 (exists) or 2 (not found)
28
+ #
29
+ # @note Requires git 2.43 or later
30
+ #
31
+ # Earlier versions do not recognise the `--exists` flag and will exit
32
+ # non-zero with an "unknown option" error.
33
+ #
34
+ # @note `arguments` block audited against https://git-scm.com/docs/git-show-ref/2.53.0
35
+ #
36
+ # @see Git::Commands::ShowRef
37
+ #
38
+ # @see https://git-scm.com/docs/git-show-ref git-show-ref documentation
39
+ #
40
+ # @api private
41
+ #
42
+ class Exists < Git::Commands::Base
43
+ arguments do
44
+ literal 'show-ref'
45
+ literal '--exists'
46
+ execution_option :timeout
47
+ operand :ref, required: true
48
+ end
49
+
50
+ # Exit status 0 = ref found; 2 = ref not found (expected); 1 = lookup error.
51
+ # All three are valid results — callers check exitstatus to distinguish them.
52
+ allow_exit_status 0..2
53
+
54
+ # @!method call(*, **)
55
+ #
56
+ # @overload call(ref, **options)
57
+ #
58
+ # Execute `git show-ref --exists` to check whether a ref exists
59
+ #
60
+ # @param ref [String] the fully-qualified ref name to check
61
+ # (e.g. `"refs/heads/main"`)
62
+ #
63
+ # @param options [Hash] command options
64
+ #
65
+ # @option options [Numeric] :timeout (nil) abort the command after this many
66
+ # seconds
67
+ #
68
+ # @return [Git::CommandLineResult] the result of calling
69
+ # `git show-ref --exists`
70
+ #
71
+ # @raise [ArgumentError] if no ref is provided
72
+ #
73
+ # @raise [Git::FailedError] if git exits with a status outside `0..2`
74
+ #
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+ require 'git/commands/show_ref'
5
+
6
+ module Git
7
+ module Commands
8
+ module ShowRef
9
+ # Standard ref listing command via `git show-ref`
10
+ #
11
+ # Lists refs stored in the local repository together with their associated
12
+ # commit IDs. When no filters are given, all refs are listed. Filters can
13
+ # narrow output to heads, tags, or refs matching a given pattern.
14
+ #
15
+ # An exit status of 1 is not an error — it indicates that no matching refs
16
+ # were found. Exit status 0 means at least one match was found.
17
+ #
18
+ # For strict per-ref verification, use {Git::Commands::ShowRef::Verify}.
19
+ # For stdin-based filtering, use {Git::Commands::ShowRef::ExcludeExisting}.
20
+ # For a simple boolean existence check (git >= 2.43), use {Git::Commands::ShowRef::Exists}.
21
+ #
22
+ # @note `arguments` block audited against https://git-scm.com/docs/git-show-ref/2.53.0
23
+ #
24
+ # @example List all refs
25
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
26
+ # result = cmd.call
27
+ # result.stdout # => "abc1234 refs/heads/main\n..."
28
+ #
29
+ # @example List only tags
30
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
31
+ # result = cmd.call(tags: true)
32
+ #
33
+ # @example List with abbreviated SHA hashes
34
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
35
+ # result = cmd.call(hash: 7)
36
+ #
37
+ # @example Match a pattern
38
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
39
+ # result = cmd.call('v1.0', 'v2.0', tags: true)
40
+ #
41
+ # @see Git::Commands::ShowRef
42
+ #
43
+ # @see https://git-scm.com/docs/git-show-ref
44
+ #
45
+ # @api private
46
+ #
47
+ class List < Git::Commands::Base
48
+ arguments do
49
+ literal 'show-ref'
50
+
51
+ # Include the HEAD ref even if it would normally be filtered out
52
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---head
53
+ flag_option :head
54
+
55
+ # Dereference annotated tags; outputs an additional line per tag with
56
+ # the de-referenced object SHA followed by `^{}`
57
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---dereference
58
+ flag_option %i[dereference d]
59
+
60
+ # Show only the SHA part of the ref, optionally abbreviated to <n> hex digits;
61
+ # pass `true` for full-length SHA, or an integer for the abbreviation length
62
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---hashn
63
+ flag_or_value_option %i[hash s], inline: true
64
+
65
+ # Abbreviate the object names to at least <n> hex digits; pass `true` to
66
+ # use the default abbreviation length, or an integer for an explicit length
67
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---abbrevlength
68
+ flag_or_value_option :abbrev, inline: true
69
+
70
+ # Limit to refs under refs/heads/ only (preferred over :heads on git >= 2.46)
71
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---branches
72
+ flag_option :branches
73
+
74
+ # Limit to refs under refs/heads/ only (deprecated synonym for :branches in git >= 2.46)
75
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---branches
76
+ flag_option :heads
77
+
78
+ # Limit to refs under refs/tags/ only
79
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---tags
80
+ flag_option :tags
81
+
82
+ execution_option :timeout
83
+
84
+ end_of_options
85
+
86
+ # Optional glob patterns; only refs whose names contain a match are shown.
87
+ # Patterns are matched against the full ref name (without the leading `refs/`
88
+ # prefix on older git versions; full path on newer ones).
89
+ operand :pattern, repeatable: true
90
+ end
91
+
92
+ # Exit status 1 means no refs matched; that is a normal (non-error) outcome
93
+ allow_exit_status 0..1
94
+
95
+ # @!method call(*pattern, **options)
96
+ #
97
+ # @overload call(*pattern, **options)
98
+ #
99
+ # Execute `git show-ref` to list matching refs
100
+ #
101
+ # @param pattern [Array<String>] zero or more patterns to filter refs
102
+ #
103
+ # When empty, all refs are listed.
104
+ #
105
+ # @param options [Hash] command options
106
+ #
107
+ # @option options [Boolean, nil] :head (nil) show the HEAD ref even when filtered
108
+ #
109
+ # @option options [Boolean, nil] :dereference (nil) dereference annotated tags,
110
+ # emitting an extra line per tag whose SHA points to the tagged object
111
+ #
112
+ # Alias: `:d`
113
+ #
114
+ # @option options [Boolean, Integer, nil] :hash (nil) show only the SHA part of each ref
115
+ #
116
+ # Pass `true` for full-length SHAs or an integer for the abbreviation length
117
+ # (e.g. `hash: 7`).
118
+ #
119
+ # Alias: `:s`
120
+ #
121
+ # @option options [Boolean, Integer, nil] :abbrev (nil) abbreviate object names
122
+ #
123
+ # Pass `true` for the default length or an integer for a specific length.
124
+ #
125
+ # @option options [Boolean, nil] :branches (nil) limit output to local branches (refs/heads/)
126
+ #
127
+ # Prefer `:branches` over `:heads` on git >= 2.46; `:heads` emits the deprecated
128
+ # `--heads` flag.
129
+ #
130
+ # @option options [Boolean, nil] :heads (nil) limit output to refs under refs/heads/
131
+ #
132
+ # Deprecated at the git level in git 2.46. Use `:branches` instead.
133
+ #
134
+ # @option options [Boolean, nil] :tags (nil) limit output to refs under refs/tags/
135
+ #
136
+ # @option options [Numeric] :timeout (nil) abort the command after this many seconds
137
+ #
138
+ # @return [Git::CommandLineResult] the result of calling `git show-ref`
139
+ #
140
+ # @raise [Git::FailedError] if git exits with a status outside `0..1`
141
+ #
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+ require 'git/commands/show_ref'
5
+
6
+ module Git
7
+ module Commands
8
+ module ShowRef
9
+ # Strict per-ref verification command via `git show-ref --verify`
10
+ #
11
+ # Verifies that refs exist by their full canonical name (e.g.
12
+ # `refs/heads/main`, `refs/tags/v1.0`). Unlike {ShowRef::List}, partial
13
+ # name matching is not performed. Every named ref must start with `refs/`
14
+ # (or be `HEAD`); anything else will cause git to exit non-zero.
15
+ #
16
+ # When a ref cannot be resolved, git exits 1 and this class raises
17
+ # {Git::FailedError}. This strict behaviour makes the class suitable for
18
+ # validating that refs are fully qualified.
19
+ #
20
+ # For pattern-based listing, use {ShowRef::List}.
21
+ # For stdin-based filtering, use {ShowRef::ExcludeExisting}.
22
+ # For a silent boolean check (git >= 2.43), use {ShowRef::Exists}.
23
+ #
24
+ # @example Verify a single ref
25
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
26
+ # result = cmd.call('refs/heads/main')
27
+ # result.stdout # => "abc1234 refs/heads/main\n"
28
+ #
29
+ # @example Verify with hash-only output
30
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
31
+ # result = cmd.call('refs/heads/main', hash: true)
32
+ # result.stdout # => "abc1234\n"
33
+ #
34
+ # @example Silent existence check
35
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
36
+ # cmd.call('refs/heads/main', quiet: true) # raises FailedError if not found
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 git-show-ref documentation
43
+ #
44
+ # @api private
45
+ #
46
+ class Verify < Git::Commands::Base
47
+ arguments do
48
+ literal 'show-ref'
49
+ literal '--verify'
50
+
51
+ # Suppress output; useful when you only care whether the ref exists
52
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---quiet
53
+ flag_option %i[quiet q]
54
+
55
+ # Dereference annotated tags; emit an extra line per tag with SHA^{}
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; pass `true` for full-length or an integer for abbreviated length
60
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---hashn
61
+ flag_or_value_option %i[hash s], inline: true
62
+
63
+ # Abbreviate object names; pass `true` for default or integer for explicit length
64
+ # @see https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---abbrevlength
65
+ flag_or_value_option :abbrev, inline: true
66
+
67
+ execution_option :timeout
68
+
69
+ end_of_options
70
+
71
+ # One or more fully-qualified ref names to verify (e.g. `refs/heads/main`)
72
+ operand :ref, repeatable: true, required: true
73
+ end
74
+
75
+ # @!method call(*ref, **options)
76
+ #
77
+ # @overload call(*ref, **options)
78
+ #
79
+ # Execute `git show-ref --verify` to verify refs by their full name
80
+ #
81
+ # @param ref [Array<String>] one or more fully-qualified ref names
82
+ #
83
+ # Each name must begin with `refs/` (or be `HEAD`). At least one is required.
84
+ #
85
+ # @param options [Hash] command options
86
+ #
87
+ # @option options [Boolean, nil] :quiet (nil) suppress all output
88
+ #
89
+ # Useful when you only care whether the ref exists.
90
+ #
91
+ # Alias: `:q`
92
+ #
93
+ # @option options [Boolean, nil] :dereference (nil) dereference annotated tags,
94
+ # emitting an extra `^{}` line per tag
95
+ #
96
+ # Alias: `:d`
97
+ #
98
+ # @option options [Boolean, Integer, nil] :hash (nil) show only the SHA part
99
+ #
100
+ # Pass `true` for full-length SHAs or an integer for abbreviation length.
101
+ #
102
+ # Alias: `:s`
103
+ #
104
+ # @option options [Boolean, Integer, nil] :abbrev (nil) abbreviate object names
105
+ #
106
+ # Pass `true` for the default length or an integer for a specific length.
107
+ #
108
+ # @option options [Numeric] :timeout (nil) abort the command after this many
109
+ # seconds
110
+ #
111
+ # @return [Git::CommandLineResult] the result of calling `git show-ref --verify`
112
+ #
113
+ # @raise [ArgumentError] if no ref names are provided
114
+ #
115
+ # @raise [Git::FailedError] if any ref cannot be resolved (exit status 1)
116
+ #
117
+ end
118
+ end
119
+ end
120
+ 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
+ # @api private
25
+ #
26
+ # @see https://git-scm.com/docs/git-show-ref git-show-ref documentation
27
+ #
28
+ # @example List all refs matching a pattern
29
+ # cmd = Git::Commands::ShowRef::List.new(execution_context)
30
+ # result = cmd.call('refs/tags/', tags: true)
31
+ # result.stdout
32
+ # # => "abc1234 refs/tags/v1.0\ndef5678 refs/tags/v2.0\n"
33
+ #
34
+ # @example Verify a specific ref
35
+ # cmd = Git::Commands::ShowRef::Verify.new(execution_context)
36
+ # result = cmd.call('refs/heads/main')
37
+ # result.stdout # => "abc1234 refs/heads/main\n"
38
+ #
39
+ module ShowRef
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,75 @@
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
+ # @note `arguments` block audited against https://git-scm.com/docs/git-stash/2.53.0
14
+ #
15
+ # @see Git::Commands::Stash Git::Commands::Stash for usage examples
16
+ #
17
+ # @see https://git-scm.com/docs/git-stash git-stash documentation
18
+ #
19
+ # @api private
20
+ #
21
+ # @example Apply the latest stash
22
+ # Git::Commands::Stash::Apply.new(execution_context).call
23
+ #
24
+ # @example Apply a specific stash
25
+ # Git::Commands::Stash::Apply.new(execution_context).call('stash@\\{2}')
26
+ #
27
+ # @example Apply and restore index state
28
+ # Git::Commands::Stash::Apply.new(execution_context).call(index: true)
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
+ # @!method call(*, **)
40
+ #
41
+ # Apply stashed changes
42
+ #
43
+ # @overload call(**options)
44
+ #
45
+ # Apply the latest stash
46
+ #
47
+ # @param options [Hash] command options
48
+ #
49
+ # @option options [Boolean, nil] :index (nil) restore the index state as well
50
+ #
51
+ # @option options [Boolean, nil] :quiet (nil) suppress informational messages
52
+ #
53
+ # Alias: :q
54
+ #
55
+ # @overload call(stash, **options)
56
+ #
57
+ # Apply a specific stash
58
+ #
59
+ # @param stash [String] stash reference (e.g., 'stash@\\{0}', '0')
60
+ #
61
+ # @param options [Hash] command options
62
+ #
63
+ # @option options [Boolean, nil] :index (nil) restore the index state as well
64
+ #
65
+ # @option options [Boolean, nil] :quiet (nil) suppress informational messages
66
+ #
67
+ # Alias: :q
68
+ #
69
+ # @return [Git::CommandLineResult] the result of calling `git stash apply`
70
+ #
71
+ # @raise [Git::FailedError] if the stash does not exist
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,65 @@
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
+ # @note `arguments` block audited against https://git-scm.com/docs/git-stash/2.53.0
20
+ #
21
+ # @see Git::Commands::Stash Git::Commands::Stash for usage examples
22
+ #
23
+ # @see https://git-scm.com/docs/git-stash git-stash documentation
24
+ #
25
+ # @api private
26
+ #
27
+ # @example Create branch from latest stash
28
+ # Git::Commands::Stash::Branch.new(execution_context).call('my-branch')
29
+ #
30
+ # @example Create branch from specific stash
31
+ # Git::Commands::Stash::Branch.new(execution_context).call('my-branch', 'stash@{2}')
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::CommandLineResult] the result of calling `git stash branch`
60
+ #
61
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git/commands/base'
4
+
5
+ module Git
6
+ module Commands
7
+ module Stash
8
+ # Remove all stash entries
9
+ #
10
+ # Removes all stash entries. Use with caution as this cannot be undone.
11
+ #
12
+ # @note `arguments` block audited against https://git-scm.com/docs/git-stash/2.53.0
13
+ #
14
+ # @see Git::Commands::Stash Git::Commands::Stash for usage examples
15
+ #
16
+ # @see https://git-scm.com/docs/git-stash git-stash documentation
17
+ #
18
+ # @api private
19
+ #
20
+ # @example Clear all stashes
21
+ # Git::Commands::Stash::Clear.new(execution_context).call
22
+ #
23
+ class Clear < Git::Commands::Base
24
+ arguments do
25
+ literal 'stash'
26
+ literal 'clear'
27
+ end
28
+
29
+ # @!method call(*, **)
30
+ #
31
+ # @overload call()
32
+ #
33
+ # Clear all stash entries
34
+ #
35
+ # @return [Git::CommandLineResult] the result of calling `git stash clear`
36
+ #
37
+ # @raise [Git::FailedError] if git exits with a non-zero exit status
38
+ end
39
+ end
40
+ end
41
+ end