git 4.3.2 → 5.0.0.beta.2

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 (297) hide show
  1. checksums.yaml +4 -4
  2. data/.github/copilot-instructions.md +73 -2705
  3. data/.github/prompts/iteratively-address-copilot-reviews.prompt.md +188 -0
  4. data/.github/pull_request_template.md +3 -1
  5. data/.github/skills/breaking-change-analysis/SKILL.md +102 -0
  6. data/.github/skills/ci-cd-troubleshooting/SKILL.md +264 -0
  7. data/.github/skills/command-implementation/REFERENCE.md +993 -0
  8. data/.github/skills/command-implementation/SKILL.md +229 -0
  9. data/.github/skills/command-test-conventions/SKILL.md +660 -0
  10. data/.github/skills/command-yard-documentation/SKILL.md +426 -0
  11. data/.github/skills/dependency-management/SKILL.md +72 -0
  12. data/.github/skills/development-workflow/SKILL.md +506 -0
  13. data/.github/skills/extract-command-from-lib/SKILL.md +487 -0
  14. data/.github/skills/extract-facade-from-base-lib/KEYWORD_ARG_REMEDIATION.md +22 -0
  15. data/.github/skills/extract-facade-from-base-lib/SKILL.md +600 -0
  16. data/.github/skills/facade-implementation/REFERENCE.md +840 -0
  17. data/.github/skills/facade-implementation/SKILL.md +274 -0
  18. data/.github/skills/facade-test-conventions/SKILL.md +394 -0
  19. data/.github/skills/facade-yard-documentation/SKILL.md +429 -0
  20. data/.github/skills/make-skill-template/SKILL.md +176 -0
  21. data/.github/skills/pr-readiness-review/SKILL.md +185 -0
  22. data/.github/skills/project-context/SKILL.md +313 -0
  23. data/.github/skills/pull-request-review/SKILL.md +168 -0
  24. data/.github/skills/refactor-command-to-commandlineresult/SKILL.md +131 -0
  25. data/.github/skills/release-management/SKILL.md +125 -0
  26. data/.github/skills/review-arguments-dsl/CHECKLIST.md +788 -0
  27. data/.github/skills/review-arguments-dsl/SKILL.md +214 -0
  28. data/.github/skills/review-backward-compatibility/SKILL.md +275 -0
  29. data/.github/skills/review-cross-command-consistency/SKILL.md +139 -0
  30. data/.github/skills/reviewing-skills/SKILL.md +189 -0
  31. data/.github/skills/rspec-unit-testing-standards/SKILL.md +639 -0
  32. data/.github/skills/tdd-refactor-step/SKILL.md +236 -0
  33. data/.github/skills/test-debugging/SKILL.md +160 -0
  34. data/.github/skills/yard-documentation/SKILL.md +793 -0
  35. data/.github/workflows/continuous_integration.yml +3 -2
  36. data/.github/workflows/enforce_conventional_commits.yml +1 -1
  37. data/.github/workflows/experimental_continuous_integration.yml +2 -2
  38. data/.github/workflows/release.yml +3 -4
  39. data/.gitignore +8 -0
  40. data/.husky/pre-commit +13 -0
  41. data/.release-please-manifest.json +1 -1
  42. data/.rspec +3 -0
  43. data/.rubocop.yml +12 -3
  44. data/.rubocop_todo.yml +23 -5
  45. data/.yardopts +1 -0
  46. data/CHANGELOG.md +0 -40
  47. data/CONTRIBUTING.md +694 -53
  48. data/README.md +67 -15
  49. data/Rakefile +61 -9
  50. data/UPGRADING.md +141 -0
  51. data/commitlint.test +4 -0
  52. data/git.gemspec +18 -7
  53. data/lib/git/args_builder.rb +0 -8
  54. data/lib/git/branch.rb +369 -43
  55. data/lib/git/branch_delete_failure.rb +31 -0
  56. data/lib/git/branch_delete_result.rb +63 -0
  57. data/lib/git/branch_info.rb +178 -0
  58. data/lib/git/branches.rb +122 -24
  59. data/lib/git/command_line/base.rb +255 -0
  60. data/lib/git/command_line/capturing.rb +251 -0
  61. data/lib/git/command_line/result.rb +96 -0
  62. data/lib/git/command_line/streaming.rb +196 -0
  63. data/lib/git/command_line.rb +43 -322
  64. data/lib/git/command_line_result.rb +4 -88
  65. data/lib/git/commands/add.rb +131 -0
  66. data/lib/git/commands/am/abort.rb +43 -0
  67. data/lib/git/commands/am/apply.rb +252 -0
  68. data/lib/git/commands/am/continue.rb +43 -0
  69. data/lib/git/commands/am/quit.rb +43 -0
  70. data/lib/git/commands/am/retry.rb +47 -0
  71. data/lib/git/commands/am/show_current_patch.rb +64 -0
  72. data/lib/git/commands/am/skip.rb +42 -0
  73. data/lib/git/commands/am.rb +33 -0
  74. data/lib/git/commands/apply.rb +237 -0
  75. data/lib/git/commands/archive/list_formats.rb +46 -0
  76. data/lib/git/commands/archive.rb +140 -0
  77. data/lib/git/commands/arguments.rb +3510 -0
  78. data/lib/git/commands/base.rb +404 -0
  79. data/lib/git/commands/branch/copy.rb +94 -0
  80. data/lib/git/commands/branch/create.rb +173 -0
  81. data/lib/git/commands/branch/delete.rb +80 -0
  82. data/lib/git/commands/branch/list.rb +162 -0
  83. data/lib/git/commands/branch/move.rb +94 -0
  84. data/lib/git/commands/branch/set_upstream.rb +86 -0
  85. data/lib/git/commands/branch/show_current.rb +49 -0
  86. data/lib/git/commands/branch/unset_upstream.rb +57 -0
  87. data/lib/git/commands/branch.rb +34 -0
  88. data/lib/git/commands/cat_file/batch.rb +369 -0
  89. data/lib/git/commands/cat_file/filtered.rb +105 -0
  90. data/lib/git/commands/cat_file/raw.rb +216 -0
  91. data/lib/git/commands/cat_file.rb +49 -0
  92. data/lib/git/commands/checkout/branch.rb +151 -0
  93. data/lib/git/commands/checkout/files.rb +115 -0
  94. data/lib/git/commands/checkout.rb +38 -0
  95. data/lib/git/commands/checkout_index.rb +105 -0
  96. data/lib/git/commands/clean.rb +100 -0
  97. data/lib/git/commands/clone.rb +240 -0
  98. data/lib/git/commands/commit.rb +272 -0
  99. data/lib/git/commands/commit_tree.rb +100 -0
  100. data/lib/git/commands/config_option_syntax/add.rb +83 -0
  101. data/lib/git/commands/config_option_syntax/get.rb +117 -0
  102. data/lib/git/commands/config_option_syntax/get_all.rb +115 -0
  103. data/lib/git/commands/config_option_syntax/get_color.rb +91 -0
  104. data/lib/git/commands/config_option_syntax/get_color_bool.rb +93 -0
  105. data/lib/git/commands/config_option_syntax/get_regexp.rb +115 -0
  106. data/lib/git/commands/config_option_syntax/get_urlmatch.rb +107 -0
  107. data/lib/git/commands/config_option_syntax/list.rb +107 -0
  108. data/lib/git/commands/config_option_syntax/remove_section.rb +74 -0
  109. data/lib/git/commands/config_option_syntax/rename_section.rb +78 -0
  110. data/lib/git/commands/config_option_syntax/replace_all.rb +104 -0
  111. data/lib/git/commands/config_option_syntax/set.rb +114 -0
  112. data/lib/git/commands/config_option_syntax/unset.rb +89 -0
  113. data/lib/git/commands/config_option_syntax/unset_all.rb +89 -0
  114. data/lib/git/commands/config_option_syntax.rb +56 -0
  115. data/lib/git/commands/describe.rb +155 -0
  116. data/lib/git/commands/diff.rb +656 -0
  117. data/lib/git/commands/diff_files.rb +518 -0
  118. data/lib/git/commands/diff_index.rb +496 -0
  119. data/lib/git/commands/fetch.rb +352 -0
  120. data/lib/git/commands/fsck.rb +136 -0
  121. data/lib/git/commands/gc.rb +132 -0
  122. data/lib/git/commands/grep.rb +338 -0
  123. data/lib/git/commands/init.rb +99 -0
  124. data/lib/git/commands/log.rb +632 -0
  125. data/lib/git/commands/ls_files.rb +191 -0
  126. data/lib/git/commands/ls_remote.rb +155 -0
  127. data/lib/git/commands/ls_tree.rb +131 -0
  128. data/lib/git/commands/maintenance/register.rb +75 -0
  129. data/lib/git/commands/maintenance/run.rb +104 -0
  130. data/lib/git/commands/maintenance/start.rb +66 -0
  131. data/lib/git/commands/maintenance/stop.rb +55 -0
  132. data/lib/git/commands/maintenance/unregister.rb +79 -0
  133. data/lib/git/commands/maintenance.rb +31 -0
  134. data/lib/git/commands/merge/abort.rb +44 -0
  135. data/lib/git/commands/merge/continue.rb +44 -0
  136. data/lib/git/commands/merge/quit.rb +46 -0
  137. data/lib/git/commands/merge/start.rb +245 -0
  138. data/lib/git/commands/merge.rb +28 -0
  139. data/lib/git/commands/merge_base.rb +86 -0
  140. data/lib/git/commands/mv.rb +77 -0
  141. data/lib/git/commands/name_rev.rb +114 -0
  142. data/lib/git/commands/pull.rb +377 -0
  143. data/lib/git/commands/push.rb +246 -0
  144. data/lib/git/commands/read_tree.rb +149 -0
  145. data/lib/git/commands/remote/add.rb +91 -0
  146. data/lib/git/commands/remote/get_url.rb +66 -0
  147. data/lib/git/commands/remote/list.rb +54 -0
  148. data/lib/git/commands/remote/prune.rb +61 -0
  149. data/lib/git/commands/remote/remove.rb +52 -0
  150. data/lib/git/commands/remote/rename.rb +69 -0
  151. data/lib/git/commands/remote/set_branches.rb +63 -0
  152. data/lib/git/commands/remote/set_head.rb +82 -0
  153. data/lib/git/commands/remote/set_url.rb +71 -0
  154. data/lib/git/commands/remote/set_url_add.rb +61 -0
  155. data/lib/git/commands/remote/set_url_delete.rb +64 -0
  156. data/lib/git/commands/remote/show.rb +71 -0
  157. data/lib/git/commands/remote/update.rb +72 -0
  158. data/lib/git/commands/remote.rb +42 -0
  159. data/lib/git/commands/repack.rb +277 -0
  160. data/lib/git/commands/reset.rb +147 -0
  161. data/lib/git/commands/rev_parse.rb +297 -0
  162. data/lib/git/commands/revert/abort.rb +45 -0
  163. data/lib/git/commands/revert/continue.rb +57 -0
  164. data/lib/git/commands/revert/quit.rb +47 -0
  165. data/lib/git/commands/revert/skip.rb +44 -0
  166. data/lib/git/commands/revert/start.rb +153 -0
  167. data/lib/git/commands/revert.rb +29 -0
  168. data/lib/git/commands/rm.rb +114 -0
  169. data/lib/git/commands/show.rb +632 -0
  170. data/lib/git/commands/show_ref/exclude_existing.rb +120 -0
  171. data/lib/git/commands/show_ref/exists.rb +78 -0
  172. data/lib/git/commands/show_ref/list.rb +145 -0
  173. data/lib/git/commands/show_ref/verify.rb +120 -0
  174. data/lib/git/commands/show_ref.rb +42 -0
  175. data/lib/git/commands/stash/apply.rb +75 -0
  176. data/lib/git/commands/stash/branch.rb +65 -0
  177. data/lib/git/commands/stash/clear.rb +41 -0
  178. data/lib/git/commands/stash/create.rb +58 -0
  179. data/lib/git/commands/stash/drop.rb +67 -0
  180. data/lib/git/commands/stash/list.rb +39 -0
  181. data/lib/git/commands/stash/pop.rb +78 -0
  182. data/lib/git/commands/stash/push.rb +103 -0
  183. data/lib/git/commands/stash/show.rb +149 -0
  184. data/lib/git/commands/stash/store.rb +63 -0
  185. data/lib/git/commands/stash.rb +38 -0
  186. data/lib/git/commands/status.rb +169 -0
  187. data/lib/git/commands/symbolic_ref/delete.rb +68 -0
  188. data/lib/git/commands/symbolic_ref/read.rb +95 -0
  189. data/lib/git/commands/symbolic_ref/update.rb +76 -0
  190. data/lib/git/commands/symbolic_ref.rb +38 -0
  191. data/lib/git/commands/tag/create.rb +139 -0
  192. data/lib/git/commands/tag/delete.rb +55 -0
  193. data/lib/git/commands/tag/list.rb +143 -0
  194. data/lib/git/commands/tag/verify.rb +71 -0
  195. data/lib/git/commands/tag.rb +26 -0
  196. data/lib/git/commands/update_ref/batch.rb +140 -0
  197. data/lib/git/commands/update_ref/delete.rb +92 -0
  198. data/lib/git/commands/update_ref/update.rb +106 -0
  199. data/lib/git/commands/update_ref.rb +42 -0
  200. data/lib/git/commands/version.rb +57 -0
  201. data/lib/git/commands/worktree/add.rb +140 -0
  202. data/lib/git/commands/worktree/list.rb +64 -0
  203. data/lib/git/commands/worktree/lock.rb +58 -0
  204. data/lib/git/commands/worktree/management_base.rb +51 -0
  205. data/lib/git/commands/worktree/move.rb +66 -0
  206. data/lib/git/commands/worktree/prune.rb +67 -0
  207. data/lib/git/commands/worktree/remove.rb +63 -0
  208. data/lib/git/commands/worktree/repair.rb +76 -0
  209. data/lib/git/commands/worktree/unlock.rb +47 -0
  210. data/lib/git/commands/worktree.rb +43 -0
  211. data/lib/git/commands/write_tree.rb +68 -0
  212. data/lib/git/commands.rb +87 -0
  213. data/lib/git/config.rb +17 -0
  214. data/lib/git/config_entry_info.rb +106 -0
  215. data/lib/git/configuring.rb +665 -0
  216. data/lib/git/deprecation.rb +9 -0
  217. data/lib/git/detached_head_info.rb +54 -0
  218. data/lib/git/diff.rb +293 -7
  219. data/lib/git/diff_file_numstat_info.rb +29 -0
  220. data/lib/git/diff_file_patch_info.rb +134 -0
  221. data/lib/git/diff_file_raw_info.rb +127 -0
  222. data/lib/git/diff_info.rb +169 -0
  223. data/lib/git/diff_path_status.rb +67 -19
  224. data/lib/git/diff_result.rb +32 -0
  225. data/lib/git/diff_stats.rb +51 -14
  226. data/lib/git/dirstat_info.rb +86 -0
  227. data/lib/git/errors.rb +65 -2
  228. data/lib/git/execution_context/global.rb +31 -0
  229. data/lib/git/execution_context/repository.rb +136 -0
  230. data/lib/git/execution_context.rb +501 -0
  231. data/lib/git/file_ref.rb +74 -0
  232. data/lib/git/fsck_object.rb +9 -9
  233. data/lib/git/fsck_result.rb +1 -1
  234. data/lib/git/log.rb +9 -2
  235. data/lib/git/object.rb +90 -27
  236. data/lib/git/parsers/branch.rb +224 -0
  237. data/lib/git/parsers/cat_file.rb +111 -0
  238. data/lib/git/parsers/config_entry.rb +110 -0
  239. data/lib/git/parsers/diff.rb +585 -0
  240. data/lib/git/parsers/fsck.rb +133 -0
  241. data/lib/git/parsers/grep.rb +42 -0
  242. data/lib/git/parsers/ls_remote.rb +79 -0
  243. data/lib/git/parsers/ls_tree.rb +58 -0
  244. data/lib/git/parsers/stash.rb +208 -0
  245. data/lib/git/parsers/tag.rb +257 -0
  246. data/lib/git/remote.rb +120 -9
  247. data/lib/git/repository/branching.rb +743 -0
  248. data/lib/git/repository/committing.rb +187 -0
  249. data/lib/git/repository/configuring.rb +351 -0
  250. data/lib/git/repository/context_helpers.rb +264 -0
  251. data/lib/git/repository/diffing.rb +775 -0
  252. data/lib/git/repository/factories.rb +682 -0
  253. data/lib/git/repository/inspecting.rb +252 -0
  254. data/lib/git/repository/logging.rb +247 -0
  255. data/lib/git/repository/maintenance.rb +65 -0
  256. data/lib/git/repository/merging.rb +357 -0
  257. data/lib/git/repository/object_operations.rb +1199 -0
  258. data/lib/git/repository/path_resolver.rb +207 -0
  259. data/lib/git/repository/remote_operations.rb +898 -0
  260. data/lib/git/repository/shared_private.rb +51 -0
  261. data/lib/git/repository/staging.rb +554 -0
  262. data/lib/git/repository/stashing.rb +143 -0
  263. data/lib/git/repository/status_operations.rb +201 -0
  264. data/lib/git/repository/worktree_operations.rb +159 -0
  265. data/lib/git/repository.rb +203 -1
  266. data/lib/git/stash.rb +78 -4
  267. data/lib/git/stash_info.rb +104 -0
  268. data/lib/git/stashes.rb +125 -13
  269. data/lib/git/status.rb +215 -18
  270. data/lib/git/tag_delete_failure.rb +31 -0
  271. data/lib/git/tag_delete_result.rb +63 -0
  272. data/lib/git/tag_info.rb +105 -0
  273. data/lib/git/version.rb +109 -2
  274. data/lib/git/version_constraint.rb +81 -0
  275. data/lib/git/worktree.rb +108 -6
  276. data/lib/git/worktrees.rb +94 -7
  277. data/lib/git.rb +260 -61
  278. data/redesign/1_architecture_existing.md +54 -18
  279. data/redesign/2_architecture_redesign.md +365 -46
  280. data/redesign/3_architecture_implementation.md +1497 -63
  281. data/redesign/Phase 4 - Step A.md +360 -0
  282. data/redesign/beta_release.md +107 -0
  283. data/redesign/c1c2_audit.md +566 -0
  284. data/redesign/c1c2_bucket6_lib_orphans.md +626 -0
  285. data/redesign/config_design.rb +501 -0
  286. data/tasks/gem_tasks.rake +4 -0
  287. data/tasks/npm_tasks.rake +7 -0
  288. data/tasks/rspec.rake +48 -0
  289. data/tasks/test.rake +13 -1
  290. data/tasks/yard.rake +34 -7
  291. metadata +365 -22
  292. data/lib/git/base.rb +0 -1128
  293. data/lib/git/index.rb +0 -6
  294. data/lib/git/lib.rb +0 -2277
  295. data/lib/git/path.rb +0 -38
  296. data/lib/git/working_directory.rb +0 -6
  297. /data/{release-please-config.json → .release-please-config.json} +0 -0
@@ -1,65 +1,1291 @@
1
1
  # Implementation Plan for Git Gem Redesign (v5.0.0)
2
2
 
3
- This document outlines a step-by-step plan to implement the proposed architectural redesign. The plan is structured to be incremental, ensuring that the gem remains functional and passes its test suite after each major step. This approach minimizes risk and allows for a gradual, controlled migration to the new architecture.
3
+ This document outlines a step-by-step plan to implement the proposed architectural
4
+ redesign. The plan is structured to be incremental, ensuring that the gem remains
5
+ functional and passes its test suite after each major step. This approach minimizes
6
+ risk and allows for a gradual, controlled migration to the new architecture.
4
7
 
8
+ - [Progress Tracker](#progress-tracker)
9
+ - [Facade Modules Completed](#facade-modules-completed)
10
+ - [Facade module naming convention](#facade-module-naming-convention)
11
+ - [Next Task](#next-task)
12
+ - [D2 / Phase 4 is the remaining redesign step](#d2--phase-4-is-the-remaining-redesign-step)
13
+ - [Phase 3 Overview](#phase-3-overview)
14
+ - [Workstream A — Fill facade coverage gaps](#workstream-a--fill-facade-coverage-gaps)
15
+ - [Workstream B — C0: Redirect `Git::Base` factory methods to `facade_repository`](#workstream-b--c0-redirect-gitbase-factory-methods-to-facade_repository)
16
+ - [Workstream C — C1: Prepare and flip top-level entry points to return `Git::Repository`](#workstream-c--c1-prepare-and-flip-top-level-entry-points-to-return-gitrepository)
17
+ - [Workstream D — C3: Remove compatibility fallbacks](#workstream-d--c3-remove-compatibility-fallbacks)
18
+ - [Workstream E — Migrate or deprecate instance helper methods](#workstream-e--migrate-or-deprecate-instance-helper-methods)
19
+ - [Workstream F — `Git` module utility methods still using `Git::Lib` directly](#workstream-f--git-module-utility-methods-still-using-gitlib-directly)
20
+ - [Phase 3 dependency order](#phase-3-dependency-order)
21
+ - [Phase 3 steps and release compatibility](#phase-3-steps-and-release-compatibility)
22
+ - [Phase 3 completion criteria](#phase-3-completion-criteria)
23
+ - [Facade coverage checklist](#facade-coverage-checklist)
24
+ - [Quality gates (per step)](#quality-gates-per-step)
25
+ - [Reference Files](#reference-files)
5
26
  - [Phase 1: Foundation and Scaffolding](#phase-1-foundation-and-scaffolding)
6
27
  - [Phase 2: The Strangler Fig Pattern - Migrating Commands](#phase-2-the-strangler-fig-pattern---migrating-commands)
28
+ - [Key Architectural Insight: Git::Lib as the Adapter Layer](#key-architectural-insight-gitlib-as-the-adapter-layer)
29
+ - [Architectural Insights from Command Migrations](#architectural-insights-from-command-migrations)
30
+ - [Command Migration Checklist](#command-migration-checklist)
31
+ - [✅ Migrated Commands](#-migrated-commands)
32
+ - [⏳ Commands To Migrate](#-commands-to-migrate)
7
33
  - [Phase 3: Refactoring the Public Interface](#phase-3-refactoring-the-public-interface)
8
34
  - [Phase 4: Final Cleanup and Release Preparation](#phase-4-final-cleanup-and-release-preparation)
35
+ - [Phase 4 step graph](#phase-4-step-graph)
36
+ - [Step A — Remove old code](#step-a--remove-old-code)
37
+ - [Step B — Finalize test suite](#step-b--finalize-test-suite)
38
+ - [Step C — Update documentation](#step-c--update-documentation)
9
39
 
10
- ## Phase 1: Foundation and Scaffolding
40
+ ## Progress Tracker
41
+
42
+ | Phase | Status | Description | Estimated Effort | Percent Complete |
43
+ | ----- | ------ | ----------- | :--------------: | :--------------: |
44
+ | Phase 1 | ✅ Complete | Foundation and scaffolding | 5% | 100% |
45
+ | Phase 2 | ✅ Complete | Migrating commands (all checklist items done) | 40% | 100% |
46
+ | Phase 3 | ✅ Complete | Refactoring public interface — see [Facade Modules Completed](#facade-modules-completed) and [Facade coverage checklist](#facade-coverage-checklist) | 45% | 100% |
47
+ | Phase 4 | 🔲 Not Started | Final cleanup and release | 10% | 0% |
48
+ | **TOTAL** | -- | -- | **100%** | **90%** |
49
+
50
+ ### Facade Modules Completed
51
+
52
+ | Module | File | Included in `Git::Repository` | `Git::Base` delegates |
53
+ | ------ | ---- | ------------------------------ | --------------------- |
54
+ | `Git::Repository::Staging` | `lib/git/repository/staging.rb` | ✅ | `add`, `reset`, `reset_hard`, `apply`, `apply_mail`, `read_tree`, `rm`, `mv`, `clean`, `ignored_files` |
55
+ | `Git::Repository::Committing` | `lib/git/repository/committing.rb` | ✅ | `commit`, `commit_all`, `write_tree`; `commit_tree` and `write_and_commit_tree` wrap the SHA result in `Git::Object::Commit.new(self, ...)` |
56
+ | `Git::Repository::Branching` | `lib/git/repository/branching.rb` | ✅ | `checkout`, `checkout_file`, `checkout_index`, `current_branch`, `current_branch_state`, `local_branch?`, `remote_branch?`, `branch?`, `branch`, `branches`, `branch_delete`, `branch_new`, `change_head_branch`, `branch_contains`, `branches_all`, `update_ref` |
57
+ | `Git::Repository::ContextHelpers` | `lib/git/repository/context_helpers.rb` | ✅ | `chdir`, `with_index`, `with_temp_index`, `with_working`, `with_temp_working`, `set_index`, `set_working` |
58
+ | `Git::Repository::Merging` | `lib/git/repository/merging.rb` | ✅ | `merge`, `revert`, `each_conflict`; `merge_base` wraps the returned SHA strings in `Git::Object::Commit.new(self, ...)` instances |
59
+ | `Git::Repository::RemoteOperations` | `lib/git/repository/remote_operations.rb` | ✅ | `fetch`, `pull`, `push`, `remote_add` (alias: `add_remote`), `remote_remove` (alias: `remove_remote`), `remote_set_url` (alias: `set_remote_url`), `config_remote`, `remote`, `remotes`, `ls_remote`, `remote_set_branches` |
60
+ | `Git::Repository::Stashing` | `lib/git/repository/stashing.rb` | ✅ | `stash_list`, `stash_save`, `stash_apply`, `stash_clear`, `stashes_all` |
61
+ | `Git::Repository::Diffing` | `lib/git/repository/diffing.rb` | ✅ | `diff_full`, `diff_numstat`, `diff_stats`, `diff`, `diff_path_status` (alias: `diff_name_status`), `diff_files`, `diff_index` |
62
+ | `Git::Repository::Inspecting` | `lib/git/repository/inspecting.rb` | ✅ | `describe`, `show`, `fsck` |
63
+ | `Git::Repository::Logging` | `lib/git/repository/logging.rb` | ✅ | `log`, `full_log_commits` |
64
+ | `Git::Repository::Maintenance` | `lib/git/repository/maintenance.rb` | ✅ | `repack`, `gc` |
65
+ | `Git::Repository::ObjectOperations` | `lib/git/repository/object_operations.rb` | ✅ | `cat_file_contents`, `cat_file_size`, `cat_file_type`, `cat_file_commit`, `cat_file_tag`, `rev_parse`, `tag_sha`, `full_tree`, `tree_depth`, `name_rev`, `ls_tree`, `grep`, `archive`, `gblob`, `gcommit`, `gtree`, `tag`, `object`, `tags`, `add_tag`, `delete_tag` |
66
+ | `Git::Repository::StatusOperations` | `lib/git/repository/status_operations.rb` | ✅ | `ls_files`, `no_commits?` / `empty?`, `untracked_files`, `status` |
67
+ | `Git::Repository::Configuring` | `lib/git/repository/configuring.rb` | ✅ | `config`, `config_get`, `config_list`, `config_set`, `global_config`, `global_config_get`, `global_config_list`, `global_config_set` |
68
+ | `Git::Repository::WorktreeOperations` | `lib/git/repository/worktree_operations.rb` | ✅ | `worktrees_all`, `worktree_add`, `worktree_remove`, `worktree_prune`, `worktree`, `worktrees` |
69
+
70
+ #### Facade module naming convention
71
+
72
+ New topic modules follow a **three-tier** convention:
73
+
74
+ - **Gerund** (verb-ing) when a single action word clearly names the whole module:
75
+ `Staging`, `Committing`, `Branching`, `Merging`, `Logging`, `Diffing`, `Stashing`,
76
+ `Configuring`, `Inspecting`.
77
+ - **Noun + `Operations`** when the module is a mixed bag of methods grouped by git
78
+ concept rather than a single action: `RemoteOperations`, `ObjectOperations`,
79
+ `StatusOperations`, `WorktreeOperations`.
80
+ - **Descriptive utility names** for cross-cutting helpers or housekeeping APIs that
81
+ are not domain-object names: `ContextHelpers`, `Maintenance`.
82
+
83
+ Do **not** use plain nouns that clash with existing domain-object class names
84
+ such as `Branch`, `Diff`, `Log`, `Object`, `Remote`, `Status`, `Worktree`, etc.
85
+
86
+ ### Next Task
87
+
88
+ #### D2 / Phase 4 is the remaining redesign step
89
+
90
+ F1 and F2 are both ✅ complete. All Phase 4 prerequisites are now satisfied, and
91
+ the remaining unchecked redesign item is D2.
92
+
93
+ Phase 4 (final cleanup and release — deleting `Git::Base`/`Git::Lib`) can now begin.
94
+ The first cleanup PR should remove the `base_object` / `from_base` bridge in the
95
+ same releasable change that deletes or retires `Git::Base`.
96
+ The following are also required and are already ✅ complete:
97
+
98
+ | Step | Status |
99
+ | ---- | ------ |
100
+ | C1c-2: public-API parity audit and remediation sweep | ✅ |
101
+ | E: block-based helper/path-context methods migrated | ✅ |
102
+
103
+ Steps C1d-1, C1d-2, and C1d-3 are ✅ complete (see their detail sections below for full specs).
104
+
105
+ ---
106
+
107
+ #### Phase 3 Overview
108
+
109
+ All 9 domain-object migrations are ✅ complete:
110
+
111
+ | Domain objects | PRs |
112
+ | -------------- | --- |
113
+ | `Git::Stash` + `Git::Stashes` | [PR #1306](https://github.com/ruby-git/ruby-git/pull/1306) |
114
+ | `Git::DiffPathStatus` | — |
115
+ | `Git::Object::*` | — |
116
+ | `Git::Log` | [PR #1327](https://github.com/ruby-git/ruby-git/pull/1327) |
117
+ | `Git::Diff` + `Git::DiffStats` | — |
118
+ | `Git::Status` | — |
119
+ | `Git::Branch` + `Git::Remote` | — |
120
+ | `Git::Branches` | [PR #1356](https://github.com/ruby-git/ruby-git/pull/1356), [PR #1357](https://github.com/ruby-git/ruby-git/pull/1357), [PR #1358](https://github.com/ruby-git/ruby-git/pull/1358), [PR #1359](https://github.com/ruby-git/ruby-git/pull/1359) |
121
+ | `Git::Worktree` + `Git::Worktrees` | — |
122
+
123
+ The work was organized into six workstreams (A–F). All workstreams that are
124
+ prerequisites for C1d are now ✅ complete. F1 and F2 are both ✅ complete — F2
125
+ moved the remaining `Git` module utility methods off `Git::Lib`. Phase 4 is
126
+ ready to proceed.
127
+
128
+ **Sequencing** (see [Phase 3 dependency order](#phase-3-dependency-order) for the
129
+ reasoning behind each edge):
130
+
131
+ ```mermaid
132
+ graph LR
133
+ A1 --> C1c-2
134
+ A2 --> C1c-2
135
+ A3 --> B --> C1c-2
136
+ A3 --> C1c-2
137
+ A4 --> C1c-2
138
+ C1a-1 --> C1a-2
139
+ C1a-1 --> E --> C1c-2
140
+ C1a-1 --> C1c-2
141
+ C1a-2 --> C1c-2
142
+ C1b --> C1c-2
143
+ C1c-1 --> C1c-2
144
+ C1c-2 --> C1d-1
145
+ C1d-1 --> C1d-2 --> C1d-3 --> D1 --> Phase4["Phase 4"]
146
+ D2 --> Phase4
147
+ F1 --> Phase4
148
+ F2 --> Phase4
149
+ ```
150
+
151
+ ---
152
+
153
+ #### Workstream A — Fill facade coverage gaps
154
+
155
+ `Git::Base` still calls `lib.*` directly for 11 high-priority methods that have no
156
+ `Git::Repository` counterpart yet. Each step below adds the missing facade methods and
157
+ updates `Git::Base` to delegate.
158
+
159
+ **Step A1 — Extend `Git::Repository::Staging`: `rm`, `clean`, `ignored_files`** ✅
160
+
161
+ | `Git::Base` method | Facade to add |
162
+ | --- | --- |
163
+ | `rm(path, opts)` | `Git::Repository::Staging#rm` → `Commands::Rm` |
164
+ | `clean(opts)` | `Git::Repository::Staging#clean` → `Commands::Clean`; the `migrate_clean_legacy_options` deprecation adapter (`:ff`/`:force_force`) moves into the facade |
165
+ | `ignored_files` | `Git::Repository::Staging#ignored_files` → `Commands::LsFiles` |
166
+
167
+ Files touched: `lib/git/repository/staging.rb`, `spec/unit/git/repository/staging_spec.rb`, `lib/git/base.rb`
168
+
169
+ **Step A2 — Extend `Git::Repository::RemoteOperations`: `remotes`, `set_remote_url`, `remote_set_branches`** ✅
170
+
171
+ | `Git::Base` method | Facade to add |
172
+ | --- | --- |
173
+ | `remotes` | `Git::Repository::RemoteOperations#remotes` → `Commands::Remote::List`; returns `Array<Git::Remote>` |
174
+ | `set_remote_url(name, url)` | `Git::Repository::RemoteOperations#set_remote_url` → `Commands::Remote::SetUrl`; coerce local-repo `Git::Base` url to string in facade pre-processing; return `Git::Remote` |
175
+ | `remote_set_branches(name, *branches, add:)` | `Git::Repository::RemoteOperations#remote_set_branches` → `Commands::Remote::SetBranches` |
176
+
177
+ Files touched: `lib/git/repository/remote_operations.rb`, `spec/unit/git/repository/remote_operations_spec.rb`, `lib/git/base.rb`
178
+
179
+ **Step A3 — Extend `Git::Repository::ObjectOperations`: `tags`, `add_tag`, `delete_tag`** ✅
180
+
181
+ | `Git::Base` method | Facade to add |
182
+ | --- | --- |
183
+ | `tags` | `Git::Repository::ObjectOperations#tags` → `Commands::Tag::List` + `Parsers::Tag`; returns `Array<Git::Object::Tag>` |
184
+ | `add_tag(name, *options)` | `Git::Repository::ObjectOperations#add_tag` → `Commands::Tag::Create`; `validate_tag_options!` validation logic moves into the facade |
185
+ | `delete_tag(name)` | `Git::Repository::ObjectOperations#delete_tag` → `Commands::Tag::Delete` |
186
+
187
+ Files touched: `lib/git/repository/object_operations.rb`, `spec/unit/git/repository/object_operations_spec.rb`, `lib/git/base.rb`
188
+
189
+ **Step A4 — New `Git::Repository::Inspecting` module: `show`, `fsck`** ✅
190
+
191
+ These are read-only repository inspection operations that don't fit an existing topic module.
192
+
193
+ | `Git::Base` method | Facade to add |
194
+ | --- | --- |
195
+ | `show(objectish, path)` | `Git::Repository::Inspecting#show` → `Commands::Show`; returns `String` |
196
+ | `fsck(*objects, **opts)` | `Git::Repository::Inspecting#fsck` → `Commands::Fsck` + `Parsers::Fsck`; returns `Git::FsckResult` |
197
+
198
+ Files touched: `lib/git/repository/inspecting.rb` (new), `lib/git/repository.rb` (add `include Git::Repository::Inspecting`), `spec/unit/git/repository/inspecting_spec.rb` (new), `lib/git/base.rb`
199
+
200
+ **Later covered by C1c-2:** lower-level public methods such as `describe`,
201
+ `repack`, `gc`, `apply`, `apply_mail`, `read_tree`, and `cat_file_*` were
202
+ subsequently migrated into `Inspecting`, `Maintenance`, `Staging`, and
203
+ `ObjectOperations` before `Git.open` started returning `Git::Repository`.
204
+
205
+ ---
206
+
207
+ #### Workstream B — C0: Redirect `Git::Base` factory methods to `facade_repository`
208
+
209
+ These `Git::Base` methods construct domain objects directly with `self` instead of
210
+ delegating. All corresponding facade methods already exist — this is pure delegation
211
+ wiring with no new facade code needed. Ship as one PR (`feat/c0-delegate-base-factories`).
212
+
213
+ ⚠️ Depends on A3 (`tags`/`add_tag`/`delete_tag`) before `tag` can be redirected.
214
+
215
+ **Step B — Redirect `Git::Base` domain-object factories to `facade_repository`** ✅
216
+
217
+ | `Git::Base` method | Current | Replace with |
218
+ | --- | --- | --- |
219
+ | `branch(branch_name)` [L936] | `Git::Branch.new(self, ...)` | `facade_repository.branch(branch_name)` |
220
+ | `branches` [L950] | `Git::Branches.new(self)` | `facade_repository.branches` |
221
+ | `gblob(objectish)` [L993] | `Git::Object.new(self, objectish, 'blob')` | `facade_repository.gblob(objectish)` |
222
+ | `gcommit(objectish)` [L998] | `Git::Object.new(self, objectish, 'commit')` | `facade_repository.gcommit(objectish)` |
223
+ | `gtree(objectish)` [L1003] | `Git::Object.new(self, objectish, 'tree')` | `facade_repository.gtree(objectish)` |
224
+ | `object(objectish)` [L1030] | `Git::Object.new(self, objectish)` | `facade_repository.object(objectish)` |
225
+ | `remote(remote_name)` [L1035] | `Git::Remote.new(self, remote_name)` | `facade_repository.remote(remote_name)` |
226
+ | `tag(tag_name)` [L1045] | `Git::Object::Tag.new(self, tag_name)` | `facade_repository.tag(tag_name)` |
227
+
228
+ ---
229
+
230
+ #### Workstream C — C1: Prepare and flip top-level entry points to return `Git::Repository`
231
+
232
+ ⚠️ C1d, the actual return-type flip, depends on all of Workstreams A, B, and E plus
233
+ C1a-1/C1a-2/C1b/C1c being complete.
234
+
235
+ This workstream has six sub-tasks. C1a-1, C1a-2, and C1b can land early; C1c-1 and C1c-2 must run after
236
+ facade/helper coverage; C1d is the final step.
237
+
238
+ **C1a — Add factory class methods to `Git::Repository`** (group: Step C1a-1 and Step C1a-2)
239
+
240
+ The construction logic currently in `Git::Base.open`, `.bare`, `.clone`, and
241
+ `Git.init` must move to equivalent factory class methods on `Git::Repository` so
242
+ that `Git.open` etc. can call `Git::Repository.open` instead of `Git::Base.open`.
243
+ The notable complexity is clone result parsing/path resolution: `Git::Base.clone`
244
+ currently delegates to `Git::Lib#clone`, which already wraps `Git::Commands::Clone`.
245
+ Move that adapter behavior into `Git::Repository.clone` without reintroducing a
246
+ `Git::Lib` dependency.
247
+
248
+ This workstream is intentionally split into two PRs because the path/accessor
249
+ state work is independent of the clone/init work, and combining them would make a
250
+ very large PR.
251
+
252
+ **Step C1a-1 — Path state, accessors, and `.open`/`.bare` factories** ✅
253
+
254
+ | `Git::Base` class method | Target |
255
+ | --- | --- |
256
+ | `.open(working_dir, options)` | `Git::Repository.open` — path validation + `resolve_paths` + constructor |
257
+ | `.bare(git_dir, options)` | `Git::Repository.bare` — bare path resolution + constructor |
258
+
259
+ Also move `resolve_paths` and `root_of_worktree` private helpers from `Git::Base`
260
+ to `Git::Repository` (or a private `RepositoryPaths` helper module). `Git::Repository`
261
+ must also expose the path/accessor surface currently provided by `Git::Base`: `dir`,
262
+ `repo`, `index`, and `repo_size`.
263
+
264
+ Files touched: `lib/git/repository.rb`, `lib/git/base.rb`
265
+
266
+ **Step C1a-2 — `.clone` and `.init` factories** ✅
267
+
268
+ | `Git::Base` / `Git` method | Target |
269
+ | --- | --- |
270
+ | `.clone(url, dir, options)` | `Git::Repository.clone` — delegates to `Commands::Clone`, resolves paths, constructs instance |
271
+ | `Git.init(dir, options)` | `Git::Repository.init` — delegates to `Commands::Init` using `Git::ExecutionContext::Global` (not `Git::Lib`), then calls `.open`/`.bare` |
272
+
273
+ Note: `Git.init` in `lib/git.rb` currently passes `Git::Lib.new` into
274
+ `Git::Commands::Init`. That `Git::Lib.new` call is removed here by routing
275
+ through `Git::Repository.init` instead.
276
+
277
+ Note: `.repository_default_branch` is **not** part of C1a. That class method
278
+ routes through `Git::Lib` and belongs with the `LsRemote` parser migration in
279
+ Workstream F.
280
+
281
+ Files touched: `lib/git/repository.rb`, `lib/git/base.rb`, `lib/git.rb`
282
+
283
+ **Step C1b — Move global config singleton ownership off `Git::Base`** ✅
284
+
285
+ `Git.configure` and `Git.config` both delegate to `Base.config`, which returns the
286
+ `Git::Base`-owned `Git::Config` singleton. When `Git::Base` is deleted, these break.
287
+ The fix is to move `config` to `Git::Config` itself as a class-level singleton (or to
288
+ the `Git` module directly) and update `Git.configure`, `Git.config`,
289
+ `Git.git_version`, `Git.binary_version`, and the surviving `Git::ExecutionContext`
290
+ classes to reference it without going through `Git::Base`. While `Git::Base` exists,
291
+ `Git::Base.config` can remain as a delegator for compatibility.
292
+
293
+ Note: Both `Git.git_version` and the deprecated `Git.binary_version` in `lib/git.rb`
294
+ currently evaluate `Git::Base.config.binary_path` at call time (not definition time),
295
+ so both method bodies must be updated in this PR.
296
+
297
+ Files touched: `lib/git/config.rb`, `lib/git.rb`, `lib/git/base.rb`,
298
+ `lib/git/execution_context.rb`, `lib/git/execution_context/global.rb`,
299
+ `lib/git/execution_context/repository.rb`
300
+
301
+ **C1c — Public API parity/deprecation audit before the flip** (group: Step C1c-1 and Step C1c-2)
302
+
303
+ Before `Git.open`, `Git.clone`, `Git.init`, and `Git.bare` return
304
+ `Git::Repository`, every public `Git::Base` method that should survive in v5.0 must
305
+ exist on `Git::Repository`; every method that should not survive must be explicitly
306
+ documented as a v5 breaking change or already deprecated for removal. This audit is
307
+ the gate that prevents the entry-point flip from silently dropping public methods
308
+ just because `Git::Base` still exists in the tree.
309
+
310
+ **Step C1c-1 — Signature-compatibility guidance and process** ✅
311
+
312
+ Update extraction and review skills to document the signature-compatibility
313
+ classification policy (legacy-contract vs 5.x-native), parity-check requirements,
314
+ and test-creation expectations so that all future extraction work follows consistent
315
+ rules before the remediation sweep begins.
316
+
317
+ | Artifact | Change |
318
+ | --- | --- |
319
+ | `extract-facade-from-base-lib/SKILL.md` | Add `## Signature compatibility policy` section with legacy-contract vs 5.x-native classification table and four rules (legacy-contract preserves exact 4.x signatures, including rare `**opts`; 5.x-native uses `opts = {}` for consistency) |
320
+ | `facade-implementation/SKILL.md` | Add policy classification check to review workflow (step 4) |
321
+ | `facade-test-conventions/SKILL.md` | Add `context 'signature compatibility'` grouping convention and review checks |
322
+
323
+ Files touched: `.github/skills/extract-facade-from-base-lib/SKILL.md`,
324
+ `.github/skills/facade-implementation/SKILL.md`,
325
+ `.github/skills/facade-test-conventions/SKILL.md`
326
+
327
+ Tracked as [Issue #1369](https://github.com/ruby-git/ruby-git/issues/1369).
11
328
 
12
- ***Goal**: Set up the new file structure and class names without altering existing logic. The gem will be fully functional after this phase.*
329
+ **Step C1c-2 End-of-Phase-3 public-API parity audit and remediation sweep**
13
330
 
14
- 1. **Create New Directory Structure**:
331
+ Compare every public `Git::Base` method against `Git::Repository`; fix mismatches
332
+ or explicitly record each as a documented v5 breaking change. No unclassified
333
+ compatibility gap may remain before C1d.
15
334
 
16
- - Create the new directories that will house the refactored components:
335
+ Required audit buckets:
17
336
 
18
- - `lib/git/commands/`
337
+ | Surface | Required decision before C1d |
338
+ | --- | --- |
339
+ | Path/accessors | `dir`, `repo`, `index`, `repo_size` must exist on `Git::Repository` (C1a-1 owns this) |
340
+ | Compatibility aliases/wrappers | `remove`, `revparse`, `diff_name_status`, `reset_hard`, `is_local_branch?`, `is_remote_branch?`, `is_branch?`, `checkout` must be migrated or intentionally removed with upgrade notes (`checkout` is called by `Git.export` on the `Git.clone` result) |
341
+ | Low-level public methods | Resolved in the current tree: `describe` → `Inspecting`; `repack`/`gc` → `Maintenance`; `apply`/`apply_mail`/`read_tree` → `Staging`; `cat_file_*` → `ObjectOperations`. Any intentional removals still require upgrade notes. |
342
+ | Factory/domain-object returns | Confirm B plus A2/A3 cover `branch`, `branches`, `remote`, `remotes`, `tag`, `tags`, object factories, and tag create/delete return shapes |
343
+ | Keyword-arg facades | For `legacy-contract` methods, preserve the exact 4.x call shape (including rare `**opts` signatures); for `5.x-native` methods, use `opts = {}` style for consistency |
19
344
 
20
- - `lib/git/repository/` (for the facade modules)
345
+ Files touched: `lib/git/repository/*.rb` (topic modules for migrated methods),
346
+ `lib/git/base.rb`, upgrade notes / CHANGELOG for documented removals
21
347
 
22
- 2. **Rename Path Classes**:
348
+ Tracked as [Issue #1370](https://github.com/ruby-git/ruby-git/issues/1370).
23
349
 
24
- - Perform a project-wide, safe rename of the existing path-related classes. This is a low-risk mechanical change.
350
+ ##### Step C1d-1 Flip entry points
25
351
 
26
- - `Git::WorkingDirectory` -> `Git::WorkingTreePath`
352
+ With C1a, C1b, C1c, A, B, and E in place, update `Git.open`, `Git.clone`,
353
+ `Git.init`, and `Git.bare` in `lib/git.rb` to call `Git::Repository.*` and return
354
+ `Git::Repository` directly, bypassing `Git::Base` entirely.
27
355
 
28
- - `Git::Index` -> `Git::IndexPath`
356
+ **Prerequisite fix before landing C1d-1:** delete `spec/integration/git/lib/config_spec.rb`
357
+ after confirming behavior coverage exists in `spec/integration/git/repository/configuring_spec.rb`.
358
+ The `def lib = self` shim causes `subject(:lib) { repo.lib }` to return `Git::Repository` (self),
359
+ which triggers deprecation warnings from every deprecated alias call (config_set, config_get,
360
+ global_config_set, etc.) in that spec.
29
361
 
30
- - `Git::Repository` -> `Git::RepositoryPath`
362
+ ##### Step C1d-2 Eliminate internal `.lib` callers
31
363
 
32
- - Run the test suite to ensure everything still works as expected.
364
+ Clean up all `.lib` callers from tests while the silent `def lib = self` shim is still in
365
+ place, then add `Git::Deprecation.behavior = :raise` to both test suites. See the phase table
366
+ in the [Next Task](#next-task) section for the full per-phase breakdown.
33
367
 
34
- 3. **Introduce New Core Classes (Empty Shells)**:
368
+ ##### Step C1d-3 Remove dead fallbacks and add deprecation warning
35
369
 
36
- - Create the new `Git::ExecutionContext` class in `lib/git/execution_context.rb`. For now, its implementation can be a simple shell or a thin wrapper around the existing `Git::Lib`.
370
+ - Add `diff_numstat` delegator to `Git::Base` (prerequisite: not currently defined there)
371
+ - Remove dead `respond_to?` + `.lib` fallback branches from `lib/git/diff.rb`,
372
+ `lib/git/diff_stats.rb`, `lib/git/diff_path_status.rb`, `lib/git/status.rb`
373
+ - Replace `def lib = self` in `lib/git/repository.rb` with a `Git::Deprecation.warn` body
374
+ (removal version: v6.0.0; returns `self`)
375
+ - Remove `command_capturing`, `command_streaming`, and private `env_overrides` from
376
+ `lib/git/repository.rb` — these were added only to feed the silent shim
377
+ - Add unit test asserting the deprecation warning and `self` return
37
378
 
38
- - Create the new `Git::Repository` class in `lib/git/repository.rb`. This will initially be an empty class.
379
+ ---
39
380
 
40
- 4. **Set Up RSpec Environment**:
381
+ #### Workstream D C3: Remove compatibility fallbacks
41
382
 
42
- - Add rspec dependencies to the `Gemfile` as a development dependency.
383
+ ⚠️ These are v5-only cleanup steps. They are not 4.x-compatible and must be kept out
384
+ of 4.x release candidates unless an explicit breaking-change decision has already
385
+ been recorded.
43
386
 
44
- - Configure the test setup to allow both TestUnit and RSpec tests to run concurrently.
387
+ ##### Step D1 Remove domain-object compatibility fallbacks
388
+
389
+ ⚠️ Depends on C1d. This can be a releasable v5 cleanup PR after `Git.open` returns
390
+ `Git::Repository`, because normal construction paths no longer pass `Git::Base` into
391
+ domain objects. It is breaking for callers that directly construct domain objects
392
+ with a `Git::Base` provider, so that removal must be documented in the upgrade notes.
393
+
394
+ Remove `is_a?(Git::Base)` guards. Current sites:
395
+
396
+ | File | Line |
397
+ | --- | --- |
398
+ | `lib/git/branch.rb` | L478 (`branch_repository` helper) |
399
+ | `lib/git/branches.rb` | L150 (`branches_repository` helper) |
400
+ | `lib/git/log.rb` | L170 (`log_repository` helper) |
401
+ | `lib/git/object.rb` | L137, L329, L405 |
402
+ | `lib/git/remote.rb` | L149 (`remote_repository` helper) |
403
+ | `lib/git/stash.rb` | L104 (`stash_repository` helper) |
404
+ | `lib/git/stashes.rb` | L170 (`stashes_repository` helper) |
405
+ | `lib/git/worktree.rb` | L151 (`worktree_repository` helper) |
406
+ | `lib/git/worktrees.rb` | L144 (`worktrees_repository` helper) |
407
+ | `lib/git/repository/remote_operations.rb` | L418 (`url.is_a?(Git::Base)` coercion — handled in A2 facade pre-processing instead) |
408
+
409
+ Each guard simplifies to just the `Git::Repository` branch — the `Git::Base` branch is deleted.
410
+
411
+ Verify no guards remain: `grep -r 'is_a?(Git::Base)' lib/`
412
+
413
+ Also remove legacy `@base.lib` fallback paths that only exist to support
414
+ `Git::Base`/`Git::Lib`-backed domain objects:
415
+
416
+ | File | Fallback |
417
+ | --- | --- |
418
+ | `lib/git/diff.rb` | `@base.lib.diff_full` |
419
+ | `lib/git/diff_stats.rb` | `@base.lib.diff_stats` |
420
+ | `lib/git/diff_path_status.rb` | `@base.lib.diff_path_status` |
421
+
422
+ After D1, domain objects should assume their provider is `Git::Repository` (or a
423
+ compatible object that implements the repository facade methods directly), not an
424
+ object with a `.lib` escape hatch.
425
+
426
+ ---
427
+
428
+ #### Workstream E — Migrate or deprecate instance helper methods
429
+
430
+ ⚠️ Depends on C1a (factory/path state must exist so the helpers have a home). E must
431
+ complete before C1d, because `Git.open` returning `Git::Repository` without these
432
+ helpers would drop existing public `Git::Base` behavior.
433
+
434
+ `Git::Base` exposes several block-based helper methods that have no counterpart on
435
+ `Git::Repository`. They must either be migrated before `Git::Base` can be deleted,
436
+ or explicitly deprecated with removal in v6.0. The recommended path is migration.
437
+
438
+ **Step E — Migrate block-based helper/path-context methods to `Git::Repository`** ✅
439
+
440
+ | `Git::Base` method | Proposed destination | Notes |
441
+ | --- | --- | --- |
442
+ | `#chdir(&block)` | `Git::Repository#chdir` | `Dir.chdir(dir.to_s) { yield dir }` — trivial; just needs the `dir` accessor on `Git::Repository` |
443
+ | `#with_index(new_index, &block)` | `Git::Repository#with_index` | Invalidates and restores `@index`; rebuilds the repository execution context |
444
+ | `#with_temp_index(&block)` | `Git::Repository#with_temp_index` | Creates a `Tempfile`-backed index, delegates to `with_index` |
445
+ | `#with_working(work_dir, &block)` | `Git::Repository#with_working` | Invalidates and restores `@working_directory`; rebuilds the repository execution context |
446
+ | `#with_temp_working(&block)` | `Git::Repository#with_temp_working` | Creates a `Dir.mktmpdir`-backed working dir, delegates to `with_working` |
447
+
448
+ `set_index` and `set_working` (the non-block mutators) must also be migrated or
449
+ removed at the same time, since `with_index`/`with_working` depend on the same
450
+ invalidation logic.
451
+
452
+ Files touched: `lib/git/repository/context_helpers.rb`, `lib/git/base.rb`,
453
+ `spec/unit/git/repository/` (new or extended spec)
454
+
455
+ ---
456
+
457
+ #### Workstream F — `Git` module utility methods still using `Git::Lib` directly
458
+
459
+ ⚠️ These are **Phase 4 prerequisites** — they do not block A–E but must be done
460
+ before `Git::Lib` can be deleted.
461
+
462
+ Three `Git`-module-level methods bypass `Git::Repository` entirely and call
463
+ `Git::Lib` directly. The required command classes already exist; each method needs a
464
+ non-`Git::Lib` adapter path using `Git::ExecutionContext::Global` plus existing
465
+ parsing logic.
466
+
467
+ **Step F1 — Move `Git.ls_remote` and `Git.default_branch` off `Git::Lib`** ✅
468
+
469
+ | `Git` module method | Current path | Required work |
470
+ | --- | --- | --- |
471
+ | `Git.default_branch(repo, options)` | `Base.repository_default_branch` → `Git::Lib.new.repository_default_branch` | Use `Git::Commands::LsRemote` with `symref: true` and migrate the default-branch parser out of `Git::Lib` |
472
+ | `Git.ls_remote(location, options)` | `Git::Lib.new.ls_remote` | Migrate to `Git::Commands::LsRemote` (shared with `default_branch`) |
473
+
474
+ Also migrate `Git::Base.repository_default_branch` to use `Git::Commands::LsRemote`
475
+ directly (sharing the `LsRemote` parser with `Git.ls_remote`). This is the call
476
+ chain behind `Git.default_branch` and can be migrated in the same F1 PR since both
477
+ use the same command class.
478
+
479
+ Files touched: `lib/git.rb`, `lib/git/base.rb`, and parser/helper code extracted
480
+ from `Git::Lib` as needed
481
+
482
+ **Step F2 — Move `Git.global_config`, `#config`, and `#global_config` off `Git::Lib`** ✅
483
+
484
+ | `Git` module method | Current path | Required work |
485
+ | --- | --- | --- |
486
+ | `Git.global_config(name, value)` | `Git::Lib.new.global_config_{get,set,list}` | Use `Git::Commands::ConfigOptionSyntax::{Get,List,Set}` with `global: true` |
487
+
488
+ Also audit the `Git` module instance methods `#config` and `#global_config` for
489
+ callers that `include Git`; `#global_config` should continue delegating to the class
490
+ method, while `#config` must either be reimplemented without `Git::Lib.new` or
491
+ documented as removed.
492
+
493
+ Files touched: `lib/git.rb`, `lib/git/base.rb`, and parser/helper code extracted
494
+ from `Git::Lib` as needed
495
+
496
+ ---
497
+
498
+ #### Phase 3 dependency order
499
+
500
+ 1. **Parallel starters**: A1–A4, C1a, C1b, F1, and F2 can begin independently.
501
+ 2. **B after A3**: B can start once A3 supplies facade tag factories.
502
+ 3. **E after C1a**: helper/path-context methods need `Git::Repository` path state.
503
+ 4. **C1c-2 after A+B+E+C1c-1**: API parity remediation can only be actioned after facade and helper coverage exists and the guidance/policy (C1c-1) is in place.
504
+ 5. **C1d is the v5 boundary step**: the `Git.open`/`.clone`/`.init`/`.bare` return-type flip waits for A, B, C1a, C1b, C1c-1, C1c-2, and E, and is explicitly not a 4.x-compatible change.
505
+ 6. **D1 after C1d**: domain-object fallback removal waits until normal construction no longer passes `Git::Base` into domain objects.
506
+ 7. **Phase 4 after D1+F1+F2**: deleting `Git::Base`/`Git::Lib` waits for domain-object fallback removal and `Git` module utilities to stop using `Git::Lib`; D2 lands with that deletion, not before it.
507
+
508
+ ---
509
+
510
+ #### Phase 3 steps and release compatibility
511
+
512
+ Default rule: every step before C1d that produces code must be small, independently releasable on the
513
+ 4.x-compatible line, and must preserve public signatures, return values, deprecation
514
+ warnings, and top-level factory behavior. Any intentional break must be explicitly
515
+ classified as a v5-only PR with upgrade-note coverage before it lands.
516
+
517
+ **GitHub PR column:** ⬜ = not yet opened; replace with a PR link (e.g. `[#1234](…)`) when opened, then append ✅ when merged.
518
+
519
+ | Step | GitHub PR | Scope | Release lane | Backward-compatibility rule |
520
+ | --- | --- | --- | --- | --- |
521
+ | A1 | ✅ | Add `rm`, `clean`, `ignored_files` facade coverage | 4.x-compatible | `Git::Base` public methods keep the same signatures, return values, and deprecation behavior. |
522
+ | A2 | ✅ | Add `remotes`, `set_remote_url`, `remote_set_branches` facade coverage | 4.x-compatible | `Git::Base` remote methods keep the same return objects and validation behavior. |
523
+ | A3 | ✅ | Add `tags`, `add_tag`, `delete_tag` facade coverage | 4.x-compatible | Tag list/create/delete return contracts match 4.x behavior. |
524
+ | A4 | ✅ | Add `Inspecting#show` and `#fsck` | 4.x-compatible | `Git::Base#show` and `#fsck` remain behavior-compatible and delegate internally. |
525
+ | B | ✅ | Redirect `Git::Base` domain-object factories | 4.x-compatible | Method signatures and return types stay the same; only the internal provider changes to `Git::Repository`. Split into object/tag factories and branch/remote factories if the PR grows. |
526
+ | C1a-1 | ✅ | Add `Git::Repository.open`/`.bare`, path state, and `dir`/`repo`/`index`/`repo_size` | 4.x-compatible additive | `Git.open`/`.bare` still return `Git::Base`; new repository factories are additive until C1d. |
527
+ | C1a-2 | ✅ | Add `Git::Repository.clone`/`.init` | 4.x-compatible additive | `Git.clone`/`.init` still return `Git::Base`; clone/init behavior is duplicated behind new factories without changing public entry points. |
528
+ | C1b | [#1385](https://github.com/ruby-git/ruby-git/pull/1385) ✅ | Move global config ownership | 4.x-compatible | `Git.config`, `Git.configure`, and `Git::Base.config` keep working; `Git::Base.config` remains as a delegator. |
529
+ | E | ✅ | Add repository helper/path-context methods | 4.x-compatible additive | `Git::Base` helpers keep working; `Git::Repository` gains equivalent behavior before any top-level return-type change. Split index helpers and working-directory helpers if needed. |
530
+ | F1 | ✅ | Move `Git.ls_remote` and `Git.default_branch` off `Git::Lib` | 4.x-compatible | Return formats and error behavior match current 4.x-compatible behavior. |
531
+ | F2 | ✅ | Move `Git.global_config`, module `#config`, and module `#global_config` off `Git::Lib` | 4.x-compatible | Config methods keep the same return formats and write behavior. |
532
+ | C1c-1 | ✅ | Guidance/process: signature-compatibility policy for extraction and review ([#1369](https://github.com/ruby-git/ruby-git/issues/1369)) | 4.x-compatible / docs-only | Guidance and review checklists define legacy-contract vs 5.x-native signatures, including test expectations. |
533
+ | C1c-2 | ✅ | End-of-Phase-3 public-API parity audit and remediation sweep ([#1370](https://github.com/ruby-git/ruby-git/issues/1370)) | 4.x-compatible | All four parity audit buckets resolved (fix or documented removal) before C1d; no unclassified compatibility gap remains. |
534
+ | C1d | ✅ | Flip `Git.open`/`.clone`/`.init`/`.bare` to return `Git::Repository` | v5 boundary | Explicit breaking change because class identity changes from `Git::Base` to `Git::Repository`; method-level parity must be complete first. Split into C1d-1 (entry point flip), C1d-2 (eliminate internal .lib callers + add deprecation enforcement to both test suites), and C1d-3 (remove dead fallbacks + replace silent lib shim with real deprecation warning). |
535
+ | D1 | ✅ | Remove domain-object `Git::Base` guards and `@base.lib` fallbacks | v5 cleanup | Explicitly drops direct `Git::Base` provider support in domain-object constructors; normal factory-created objects remain supported. |
536
+ #### Phase 3 completion criteria
537
+
538
+ Use this table to decide whether a checklist item can be marked complete. A step is
539
+ done only when its code, focused specs, and delegation/cleanup checks are all true.
540
+
541
+ | Step | Done when |
542
+ | --- | --- |
543
+ | A1: `Staging` — `rm`, `clean`, `ignored_files` | `Git::Repository::Staging` implements all three methods; `Git::Base#rm`, `#clean`, and `#ignored_files` delegate to `facade_repository`; legacy clean option deprecations still fire; focused staging specs cover success, option validation, and return values. |
544
+ | A2: `RemoteOperations` — `remotes`, `set_remote_url`, `remote_set_branches` | `Git::Repository::RemoteOperations` implements all three methods; returned remotes are `Git::Remote` objects backed by `Git::Repository`; local repository URL coercion no longer requires a `Git::Base` branch after D1; focused remote-operation specs cover branch validation, return values, and command arguments. |
545
+ | A3: `ObjectOperations` — `tags`, `add_tag`, `delete_tag` | `Git::Repository::ObjectOperations` implements all three methods; tag parsing/validation matches the legacy `Git::Lib` behavior; `tags`/`add_tag` return repository-backed tag objects; `delete_tag` preserves the legacy return contract; focused object-operation specs cover create/delete/list paths. |
546
+ | A4: `Inspecting` — `show`, `fsck` | `Git::Repository::Inspecting` exists, is required and included by `Git::Repository`, and implements both methods; `show` returns the expected string output; `fsck` returns `Git::FsckResult`; `Git::Base#show` and `#fsck` delegate to the facade; focused inspecting specs cover parser and command wiring. |
547
+ | B: `Git::Base` factory delegation wiring | Every listed `Git::Base` factory delegates to `facade_repository`; constructed domain objects receive a `Git::Repository` provider, not `self`; legacy method signatures and default arguments stay unchanged; focused specs prove each factory return type and provider. |
548
+ | C1a-1: `Git::Repository.open`/`.bare` + path state | `Git::Repository.open` and `.bare` exist; `resolve_paths` and `root_of_worktree` helpers are on `Git::Repository`; repository instances expose `dir`, `repo`, `index`, and `repo_size`; focused specs cover working and bare construction. |
549
+ | C1a-2: `Git::Repository.clone`/`.init` | `Git::Repository.clone` and `.init` exist and preserve legacy path resolution, `git_ssh:`, `binary_path:`, `log:`, `index:`, and `repository:` behavior; clone/init use `Git::ExecutionContext::Global`, not `Git::Lib`; `Git.init` in `lib/git.rb` no longer passes `Git::Lib.new` into `Commands::Init`; focused specs cover clone and init construction. |
550
+ | C1b: global config ownership | `Git.config`, `Git.configure`, `Git.git_version`, `Git.binary_version`, and `Git::ExecutionContext` resolve global config without referencing `Git::Base.config`; both the method body of `git_version` and the default-parameter expression of `binary_version` are updated; `Git::Base.config` remains only as a compatibility delegator while `Git::Base` exists; specs prove runtime changes to global `binary_path` and `git_ssh` are still honored. |
551
+ | C1c-1: signature-compatibility guidance | Skill updates merged (Issue #1369): `extract-facade-from-base-lib`, `facade-implementation`, and `facade-test-conventions` skills document the legacy-contract vs 5.x-native classification policy, parity-check requirements, and test-creation expectations; legacy-contract methods preserve exact 4.x call shapes while 5.x-native methods use `opts = {}`; keyword-arg remediation list for C1c-2 is established. |
552
+ | C1c-2: public-API parity audit and remediation | End-of-Phase-3 sweep complete (Issue #1370): a public-method inventory compares `Git::Base` and `Git::Repository`; every surviving public method has a repository implementation and focused coverage; every intentional removal has an upgrade-note/deprecation decision; no unclassified compatibility gap remains. |
553
+ | C1d: entry-point flip | `Git.open`, `Git.clone`, `Git.init`, and `Git.bare` return `Git::Repository`; common existing workflows still pass through those entry points; YARD return docs are updated; no top-level factory method calls `Git::Base.*`; full suite passes. |
554
+ | D1: domain-object fallback removal | No `is_a?(Git::Base)` guards remain; no `@base.lib` fallback remains in domain objects; direct `Git::Base` provider support is documented as a v5-only removal; full suite passes. |
555
+ | E: instance helper methods | `Git::Repository` implements or explicitly deprecates `chdir`, `with_index`, `with_temp_index`, `with_working`, `with_temp_working`, `set_index`, and `set_working`; context rebuilding after index/worktree changes is covered by specs; helpers yield the same values and restore state after block exit/errors. |
556
+ | F: `Git` module utilities off `Git::Lib` | `Git.default_branch`, `Git.global_config`, `Git.ls_remote`, module instance `#config`, and module instance `#global_config` no longer call `Git::Lib.new`; `Git::Base.repository_default_branch` migrated to use `Git::Commands::LsRemote` directly; existing `LsRemote` and `ConfigOptionSyntax` commands provide the behavior; parser/helper code needed from `Git::Lib` has moved; `grep -n 'Lib.new' lib/git.rb` returns no matches. |
557
+
558
+ ---
559
+
560
+ #### Facade coverage checklist
561
+
562
+ | Step | Status |
563
+ | --- | --- |
564
+ | A1: `Staging` — `rm`, `clean`, `ignored_files` | ✅ |
565
+ | A2: `RemoteOperations` — `remotes`, `set_remote_url`, `remote_set_branches` | ✅ |
566
+ | A3: `ObjectOperations` — `tags`, `add_tag`, `delete_tag` | ✅ |
567
+ | A4: new `Inspecting` — `show`, `fsck` | ✅ |
568
+ | B (C0): `Git::Base` factory delegation wiring | ✅ |
569
+ | C1a-1: `Git::Repository.open`/`.bare`, path state (`dir`, `repo`, `index`, `repo_size`) | ✅ |
570
+ | C1a-2: `Git::Repository.clone`/`.init` (no `Git::Lib` dependency) | ✅ |
571
+ | C1b: Global config ownership (`Base.config` → `Git::Config`) | ✅ |
572
+ | C1c-1: Guidance/process updates for signature compatibility (#1369) | ✅ |
573
+ | C1c-2: End-of-Phase-3 public-API parity audit and remediation (#1370) | ✅ |
574
+ | C1d: Entry-point flip (`Git.open` etc. → `Git::Repository`) | ✅ |
575
+ | D1 (C3): Remove `is_a?(Git::Base)` guards + `@base.lib` fallbacks | ✅ |
576
+ | E: Instance helpers (`#chdir`, `#with_index`, `#with_temp_index`, `#with_working`, `#with_temp_working`) | ✅ |
577
+ | F: `Git` module utilities (`default_branch`, `global_config`, `ls_remote`) off `Git::Lib` | ✅ |
578
+
579
+ #### Quality gates (per step)
580
+
581
+ 1. Run the focused spec for the touched module: `bundle exec rspec spec/unit/git/repository/<topic>_spec.rb`
582
+ 2. Run the full suite: `bundle exec rake default:parallel` — CI-equivalent aggregate task covering Test::Unit, RSpec, RuboCop, YARD, and build
583
+ 3. For every 4.x-compatible step before C1d: confirm no public `Git`, `Git::Base`, or `Git::Lib` method signature/return contract changes unless the step explicitly documents a compatible deprecation path
584
+ 4. After C1b: confirm `Git.configure`, `Git.config`, `Git.git_version`, and `Git::ExecutionContext` no longer depend on `Git::Base.config`
585
+ 5. After C1c-2: compare `Git::Base` public methods against `Git::Repository` and record every intentional removal in upgrade notes
586
+ 6. After C1d: confirm `Git.open(...)` returns a `Git::Repository` instance and common legacy call sites still work or fail with documented breaking-change coverage
587
+ 7. After D1: confirm no guards or legacy lib fallbacks remain: `grep -r 'is_a?(Git::Base)\|@base\.lib' lib/`
588
+ 8. After D2: confirm no `base_object` or `from_base` bridge remains and `Git::Base` is deleted or retired in the same releasable PR
589
+ 9. After F: confirm no `Git::Lib.new` calls remain in `lib/git.rb`: `grep -n 'Lib.new' lib/git.rb`
590
+
591
+ #### Reference Files
592
+
593
+ - Facade shell: `lib/git/repository.rb`
594
+ - Staging module (pattern reference): `lib/git/repository/staging.rb`
595
+ - Staging spec (pattern reference): `spec/unit/git/repository/staging_spec.rb`
596
+ - RemoteOperations (more complex example): `lib/git/repository/remote_operations.rb`
597
+ - Command classes: `lib/git/commands/` (especially `clone.rb`, `ls_remote.rb`, and `config_option_syntax/*`)
598
+
599
+ ## Phase 1: Foundation and Scaffolding
600
+
601
+ ***Goal**: Set up the new file structure and class names without altering existing
602
+ logic. The gem will be fully functional after this phase.*
603
+
604
+ 1. **Create New Directory Structure**
605
+
606
+ - `lib/git/commands/` ✅
607
+ - `lib/git/repository/` ✅ — populated with 15 included modules in Phase 3 (see [Facade Modules Completed](#facade-modules-completed))
608
+
609
+ 2. **Eliminate Custom Path Classes**
610
+
611
+ Path wrapper classes removed and replaced with `Pathname` objects:
612
+
613
+ - `Git::Path` ✅
614
+ - `Git::WorkingDirectory` ✅
615
+ - `Git::Index` ✅
616
+ - `Git::Repository` (the path class) ✅
617
+
618
+ `Git::Base` now stores paths as `Pathname` objects directly via
619
+ `@working_directory`, `@repository`, and `@index` instance variables.
620
+
621
+ 3. **Introduce New Core Classes (Empty Shells)**
622
+
623
+ - `Git::ExecutionContext` in `lib/git/execution_context.rb` ✅
624
+ - Real base class with `command_capturing`, `command_streaming`, `git_version`
625
+ - `Git::ExecutionContext::Repository` subclass in `lib/git/execution_context/repository.rb` ✅
626
+ - `Git::ExecutionContext::Global` subclass in `lib/git/execution_context/global.rb` ✅
627
+
628
+ - `Git::Repository` in `lib/git/repository.rb` ✅
629
+ - Now includes 15 modules via `include` (see [Facade Modules Completed](#facade-modules-completed))
630
+
631
+ - `Git::Commands::Arguments` DSL in `lib/git/commands/arguments.rb` ✅
632
+ - Provides declarative argument definition for command classes
633
+
634
+ 4. **Set Up RSpec Environment**
635
+
636
+ RSpec configured and working alongside Test::Unit. Specs live in `spec/` and can be
637
+ run with `bundle exec rspec`. ✅
45
638
 
46
639
  ## Phase 2: The Strangler Fig Pattern - Migrating Commands
47
640
 
48
- ***Goal**: Incrementally move the implementation of each git command from `Git::Lib` to a new `Command` class, strangling the old implementation one piece at a time using a Test-Driven Development workflow.*
641
+ ***Goal**: Incrementally move the implementation of each git command from `Git::Lib`
642
+ to a new `Command` class, strangling the old implementation one piece at a time using
643
+ a Test-Driven Development workflow.*
644
+
645
+ **Important Note**: During this phase, `Git::Lib` acts as a stand-in for the
646
+ `ExecutionContext` hierarchy:
647
+
648
+ - `Git::Lib.new(nil, logger)` effectively acts like `ExecutionContext::Global` (no repository
649
+ paths set)
650
+ - `Git::Lib.new(base, logger)` effectively acts like `ExecutionContext::Repository` (repository
651
+ paths set)
652
+
653
+ All new `Git::Commands::*` classes should accept any object that responds to
654
+ `command` (duck typing), not a specific context class. This allows them to work with
655
+ `Git::Lib` during migration and the proper context classes in Phase 3.
656
+
657
+ The `command` method provides important functionality including default options
658
+ (normalize, chomp, timeout), option validation, and a simplified interface that
659
+ returns just stdout. Commands should call `@execution_context.command('subcommand',
660
+ *args, **opts)` rather than working with `CommandLine` instances directly.
661
+
662
+ ### Key Architectural Insight: Git::Lib as the Adapter Layer
663
+
664
+ A fundamental principle of this migration is that `Git::Lib` methods serve as
665
+ **adapters** between the legacy public interface and the new `Git::Commands::*`
666
+ classes. This separation of concerns provides several benefits:
667
+
668
+ 1. **Legacy Interface Acceptance**: `Git::Lib` methods continue to accept the
669
+ historical interface—positional arguments, deprecated options, and quirky
670
+ parameter names that users have come to rely on.
671
+
672
+ 2. **Interface Translation**: The adapter converts legacy patterns to the clean
673
+ `Git::Commands::*` API. For example:
674
+ - Positional `message` argument → `:message` keyword
675
+ - `:no_gpg_sign => true` → `:gpg_sign => false`
676
+ - Options hash → keyword arguments via `**options`
677
+
678
+ 3. **Deprecation Handling**: Warnings about deprecated options are issued in the
679
+ adapter layer, *before* delegating to the command class. This ensures users are
680
+ informed even if they're making other errors.
681
+
682
+ 4. **Clean Command Classes**: `Git::Commands::*` classes remain free of legacy
683
+ baggage. They have a consistent, modern API that:
684
+ - Uses keyword arguments with sensible defaults
685
+ - Matches the underlying git command's interface closely
686
+ - Is easier to test in isolation
687
+ - Could potentially be used directly by advanced users
49
688
 
50
- - **1. Migrate the First Command (`config`)**:
689
+ Example adapter pattern:
51
690
 
52
- - **Write Unit Tests First**: Write comprehensive RSpec unit tests for the *proposed* `Git::Commands::Config` class. These tests will fail initially because the class doesn't exist yet. The tests should be fast and mock the `ExecutionContext`.
691
+ ```ruby
692
+ # Git::Lib#commit - the adapter layer
693
+ def commit(message, opts = {})
694
+ # Legacy: positional message → keyword argument
695
+ opts = opts.merge(message: message) if message
53
696
 
54
- - **Create Command Class**: Implement `Git::Commands::Config` to make the tests pass. This class will contain all the logic for building git config arguments and parsing its output. It will accept an `ExecutionContext` instance in its constructor.
697
+ # Legacy: :no_gpg_sign :gpg_sign => false (with deprecation warning)
698
+ if opts[:no_gpg_sign]
699
+ Git::Deprecation.warn(':no_gpg_sign option is deprecated...')
700
+ raise ArgumentError, '...' if opts.key?(:gpg_sign)
701
+ opts.delete(:no_gpg_sign)
702
+ opts[:gpg_sign] = false
703
+ end
55
704
 
56
- - **Delegate from `Git::Lib`**: Modify the `config_*` methods within the existing `Git::Lib` class. Instead of containing the implementation, they will now instantiate and call the new `Git::Commands::Config` object.
705
+ # Delegate to clean interface
706
+ Git::Commands::Commit.new(self).call(**opts)
707
+ end
708
+ ```
57
709
 
58
- - **Verify**: Run the full test suite (both TestUnit and RSpec). The existing tests for `g.config` should still pass, but they will now be executing the new, refactored code.
710
+ This pattern makes future cleanup straightforward—once deprecation periods end, the
711
+ adapter logic can be simplified or removed entirely.
712
+
713
+ **Parameter Design Principle**: Command class `#call` method parameters should
714
+ generally match the underlying git command's interface. This keeps the Commands layer
715
+ thin and transparent—directly mapping to git documentation. The public facade API
716
+ (Git.*, Git::Repository#*) can add convenience features like:
717
+
718
+ - Path expansion or normalization
719
+ - Ruby-idiomatic defaults
720
+ - Parameter validation specific to the Ruby context
721
+ - Combining multiple git operations into one public method
722
+
723
+ Keep Command parameters matching git closely for simplicity, maintainability, and
724
+ easier testing. Allow the public API to diverge when it adds real value, but without
725
+ obscuring what's actually happening underneath.
726
+
727
+ **Method Signature Convention**: The `#call` signature SHOULD, if possible, use
728
+ anonymous repeatable arguments for both positional and keyword arguments:
729
+
730
+ ```ruby
731
+ # ✅ Preferred: anonymous forwarding with ARGS.bind
732
+ # Note: defaults defined in the DSL (e.g., `positional :paths, default: ['.']`)
733
+ # are applied automatically by ARGS.bind
734
+ def call(*, **)
735
+ @execution_context.command('add', *ARGS.bind(*, **))
736
+ end
737
+
738
+ # ✅ Acceptable: assign bound_args when you need to access argument values
739
+ def call(*, **)
740
+ bound_args = ARGS.bind(*, **)
741
+ output = @execution_context.command('diff', *bound_args).stdout
742
+ Parsers::Diff.parse(output, include_dirstat: !bound_args.dirstat.nil?)
743
+ end
744
+
745
+ # ❌ Incorrect: options hash parameter
746
+ def call(paths = '.', options = {})
747
+ @execution_context.command('add', *ARGS.bind(*Array(paths), **options))
748
+ end
749
+ ```
750
+
751
+ This convention provides:
752
+
753
+ - **Better IDE support**: Editors can autocomplete and validate keyword arguments
754
+ - **Clearer method signatures**: The `#call` signature documents available options
755
+ - **Centralized validation**: `ARGS.bind` enforces allowed options and raises errors for unknown or invalid keywords
756
+ - **Consistency**: All command classes follow the same pattern
757
+
758
+ The facade layer (`Git::Lib`, `Git::Base`) may accept either keyword arguments or an
759
+ options hash for backward compatibility, but must use `**options` when delegating to
760
+ command classes.
761
+
762
+ ### Architectural Insights from Command Migrations
763
+
764
+ The following insights were discovered during command migrations and should guide
765
+ future work:
766
+
767
+ 1. **`Data.define` creates frozen objects—no memoization allowed**
768
+
769
+ Ruby's `Data.define` creates immutable, frozen objects. This means patterns like
770
+ `@cached ||= expensive_computation` will raise `FrozenError`. When using
771
+ `Data.define` for value objects, either:
772
+ - Accept repeated computation (preferred for simple operations)
773
+ - Move caching outside the value object
774
+ - Use a regular class with `freeze` called explicitly after initialization
775
+
776
+ 2. **Parsing logic duplication is unavoidable when one path needs repository context**
777
+
778
+ Value objects like `BranchInfo` cannot create domain objects like `Remote` because
779
+ they lack repository context. This leads to seemingly duplicate parsing:
780
+
781
+ ```ruby
782
+ # Value object (pure, no context)
783
+ BranchInfo#short_name # → returns String
784
+
785
+ # Domain object (has @base context)
786
+ Branch#parse_name # → returns [Remote, String]
787
+ ```
788
+
789
+ This is **intentional duplication**, not a code smell. Eliminating it would couple
790
+ the value object to the repository, defeating its purpose.
791
+
792
+ 3. **The command's return type shapes the entire downstream architecture**
793
+
794
+ When a command returns primitive types (`Array<Array>`), all consumers need magic
795
+ index knowledge. Changing to value objects (`Array<BranchInfo>`) ripples through
796
+ every consumer. Plan return types carefully—they define contracts across the
797
+ system.
798
+
799
+ 4. **Constructor polymorphism enables gradual deprecation**
800
+
801
+ When changing a constructor's expected argument type, accept both old and new
802
+ types with a deprecation warning for the legacy path:
803
+
804
+ ```ruby
805
+ def initialize(base, branch_info_or_name)
806
+ if branch_info_or_name.is_a?(Git::BranchInfo)
807
+ initialize_from_branch_info(branch_info_or_name)
808
+ else
809
+ Git::Deprecation.warn('...')
810
+ initialize_from_name(branch_info_or_name)
811
+ end
812
+ end
813
+ ```
814
+
815
+ This allows migrating internal code first while external users continue working.
816
+
817
+ 5. **The boundary between "pure data" and "contextualized operations" is the most
818
+ important architectural decision**
819
+
820
+ Commands should return pure value objects (no repository context needed).
821
+ Domain objects wrap those value objects and add operations requiring context.
822
+ This single decision determines where parsing lives, what types flow where, and
823
+ how the system layers together.
824
+
825
+ 6. **Use `flag_or_value_option ..., negatable: true` for options with positive, negative, and value forms**
826
+
827
+ When a git option supports `--flag`, `--no-flag`, AND `--flag=value` forms (like
828
+ `--track`/`--no-track`/`--track=inherit`), use `flag_or_value_option` with
829
+ `negatable: true` instead of defining separate options with conflict declarations.
830
+ Under the companion-key model this registers two entries (`:track` and
831
+ `:no_track`), each following standard boolean semantics, with an automatic
832
+ conflict between them:
833
+
834
+ ```ruby
835
+ # ✅ Preferred: single declaration registers the companion-key pair
836
+ flag_or_value_option :track, negatable: true, inline: true
837
+ # track: nil → (omitted)
838
+ # track: true → --track
839
+ # track: 'inherit' → --track=inherit
840
+ # no_track: true → --no-track
841
+ # track: false → (omitted; false is always absent)
842
+
843
+ # ❌ Avoid: separate definitions require manual conflict management
844
+ flag_option :track
845
+ flag_option :no_track
846
+ conflicts :track, :no_track
847
+ ```
848
+
849
+ **Validation delegation policy — constraint DSL declarations are not used in
850
+ command classes.** The Arguments DSL provides `conflicts`, `requires`,
851
+ `requires_one_of`, `requires_exactly_one_of`, `forbid_values`, and
852
+ `allowed_values` for declaring inter-option constraints. Command classes
853
+ generally do **not** use these declarations. Git is the single source of truth
854
+ for its own option semantics. Command classes use per-argument validation
855
+ parameters (`required:`, `type:`, `allow_nil:`, etc.) and operand format
856
+ validation (option-like operand rejection before `--`). The narrow exception is
857
+ arguments that git cannot observe — see the exception policy below.
858
+
859
+ **What command classes validate:**
860
+
861
+ | Validation | Mechanism | Rationale |
862
+ | --- | --- | --- |
863
+ | Unknown options | `validate_unsupported_options!` in Arguments DSL | Catches typos/misspellings before spawning a process. Git would also reject these, but the error message would be less clear about the Ruby-side fix needed. |
864
+ | Required options | `required: true` in Arguments DSL | Enforces the minimum contract for a command to be meaningful. Avoids spawning a process that will certainly fail. |
865
+ | Type checking | `type:` in Arguments DSL | Catches programming errors (e.g., passing an Integer where a String is expected) that would produce confusing git errors or silent coercion. |
866
+ | Option-like operand rejection | Automatic for operands before `--` | Security concern: prevents user-supplied strings like `'-s'` from being misinterpreted as git flags. |
867
+
868
+ **What command classes do NOT validate (semantic concerns — delegated to git):**
869
+
870
+ | Validation | Delegated to | Rationale |
871
+ | --- | --- | --- |
872
+ | Option conflicts (`--soft` vs `--hard`) | Git (stderr → `Git::FailedError`) | Git is the authority on which options conflict. Constraints drift as git evolves. |
873
+ | Option dependencies (`--all-match` requires `--grep`) | Git (stderr or silent behavior) | Same drift risk. Some dependencies are version-specific. |
874
+ | At-least-one-of groups | Git (stderr → `Git::FailedError`) | Git enforces its own required-argument semantics. |
875
+ | Value-set membership (`--chmod` only accepts `+x`/`-x`) | Git (stderr → `Git::FailedError`) | Git may expand accepted values in future versions. |
876
+ | Forbidden value combinations | Git (stderr → `Git::FailedError`) | Specific to git's internal semantics. |
877
+
878
+ **Design rationale:**
879
+
880
+ 1. **Git is the single source of truth.** Git validates its own option
881
+ interactions and reports clear errors via stderr, surfaced as
882
+ `Git::FailedError`. Ruby-side constraints duplicate this validation and risk
883
+ becoming stale — potentially blocking valid usage when git relaxes a
884
+ restriction in a newer version.
885
+
886
+ 2. **Partial coverage is worse than none.** Inconsistent constraint coverage
887
+ creates a false promise of safety: users can't know whether the absence of
888
+ an `ArgumentError` means "this combination is valid" or "this command
889
+ doesn't have constraints."
890
+
891
+ 3. **Constraint violations are programming errors.** When a developer passes
892
+ conflicting options, they must stop and fix their code regardless of whether
893
+ the error is `ArgumentError` or `Git::FailedError`. The cost difference is
894
+ negligible.
895
+
896
+ 4. **Uniform error semantics.** All invalid-option errors surface uniformly as
897
+ `Git::FailedError` with git's actual error message, rather than a mix of
898
+ `ArgumentError` (Ruby constraint) and `Git::FailedError` (git rejection).
899
+
900
+ 5. **The DSL infrastructure remains available.** The constraint methods in
901
+ `Git::Commands::Arguments` are kept intact. If a compelling case arises for
902
+ a specific constraint (e.g., preventing data loss that git silently allows),
903
+ it can be added on a case-by-case basis with documented justification.
904
+
905
+ **Exception policy — declare constraints only for arguments git cannot observe:**
906
+
907
+ The test: *does this argument appear in git's argv?*
908
+ - **Yes** (normal `flag_option`, `value_option`, etc.) → git can observe it and
909
+ report the error → do not declare a constraint.
910
+ - **No** (`skip_cli: true` arguments, or arguments transformed before reaching
911
+ argv) → git has no mechanism to detect incompatibilities → Ruby must enforce
912
+ them with a constraint declaration.
913
+
914
+ The canonical case is `skip_cli: true` operands routed via stdin. `cat-file
915
+ --batch` commands declare both `conflicts :objects, :batch_all_objects` and
916
+ `requires_one_of :objects, :batch_all_objects`. `:objects` is `skip_cli: true`
917
+ — git never sees it, only `:batch_all_objects` reaches argv. Git cannot detect
918
+ that you passed both (silent wrong result: dumps entire object database) or
919
+ neither (empty output with exit 0), so Ruby must enforce those constraints.
920
+
921
+ A secondary exception: if a combination of **git-visible** arguments causes
922
+ git to **silently discard data** (no error, wrong result), a `conflicts`
923
+ declaration MAY be added with: a code comment explaining why, a reference to
924
+ the git version(s) where the behavior was verified, and a test. As of this
925
+ writing, no such case has been identified.
926
+
927
+ 7. **Adapter methods should forward all positional arguments, not just options**
928
+
929
+ **BUT ONLY IF BACKWARD COMPATIBILITY IS MAINTAINED**
930
+
931
+ When `Git::Lib` methods delegate to command classes, ensure the method signature
932
+ supports ALL positional arguments the command class accepts:
933
+
934
+ ```ruby
935
+ # ❌ Wrong: loses start_point positional argument
936
+ def branch_new(branch, options = {})
937
+ Git::Commands::Branch::Create.new(self).call(branch, **options)
938
+ end
939
+
940
+ # ✅ Correct: forwards all positional arguments
941
+ def branch_new(branch, start_point = nil, options = {})
942
+ Git::Commands::Branch::Create.new(self).call(branch, start_point = nil, **options)
943
+ end
944
+ ```
945
+
946
+ Review the command class's `#call` signature when writing the adapter to ensure
947
+ no arguments are lost in translation.
948
+
949
+ 8. **Arguments are rendered in definition order**
950
+
951
+ The Arguments DSL outputs arguments in the exact order they are defined,
952
+ regardless of type. This allows precise control over argument positioning,
953
+ which is important for commands like `git checkout` where `--` must appear
954
+ between options and pathspecs only when pathspecs are present:
955
+
956
+ ```ruby
957
+ # Arguments render in definition order; end_of_options emits '--' only when
958
+ # at least one following operand produces output
959
+ ARGS = Arguments.define do
960
+ flag_option :force
961
+ operand :tree_ish
962
+ end_of_options
963
+ operand :paths, repeatable: true
964
+ end
965
+ # bind('HEAD', 'file.txt', force: true) => ['--force', 'HEAD', '--', 'file.txt']
966
+ # bind('HEAD', force: true) => ['--force', 'HEAD'] (no trailing --)
967
+
968
+ # Common pattern: static flags first for subcommands like branch --delete
969
+ ARGS = Arguments.define do
970
+ literal '--delete'
971
+ flag_option %i[force f], args: '--force'
972
+ operand :branch_names, repeatable: true, required: true
973
+ end
974
+ # build('feature', force: true) => ['--delete', '--force', 'feature']
975
+ ```
976
+
977
+ 9. **Use `%i[long short]` array syntax for flag aliases**
978
+
979
+ When defining flags with short aliases, use the `%i[]` symbol array syntax with
980
+ the long (canonical) name first. This provides a clean, consistent pattern:
981
+
982
+ ```ruby
983
+ flag_option %i[force f], args: '--force' # force: true OR f: true
984
+ flag_option %i[remotes r], args: '--remotes' # remotes: true OR r: true
985
+ flag_option %i[quiet q], args: '--quiet' # quiet: true OR q: true
986
+ ```
987
+
988
+ The first symbol becomes the primary name used in documentation and error
989
+ messages; subsequent symbols are aliases.
990
+
991
+ 10. **Consider repeatable support in adapter methods when command supports it**
992
+
993
+ When a command class supports repeatable positional arguments (e.g., deleting
994
+ multiple branches), consider whether the `Git::Lib` adapter should expose this
995
+ capability:
996
+
997
+ ```ruby
998
+ # Command class supports multiple branches
999
+ def call(*, **) # repeatable positional
1000
+ @execution_context.command('branch', *ARGS.bind(*, **))
1001
+ end
1002
+
1003
+ # ❌ Adapter only accepts single branch
1004
+ def branch_delete(branch, options = {})
1005
+ Git::Commands::Branch::Delete.new(self).call(branch, **options)
1006
+ end
1007
+
1008
+ # ✅ Adapter exposes repeatable capability
1009
+ def branch_delete(*branches, **options)
1010
+ options = { force: true }.merge(options)
1011
+ Git::Commands::Branch::Delete.new(self).call(*branches, **options)
1012
+ end
1013
+ ```
1014
+
1015
+ This allows callers to delete multiple branches efficiently in one git command.
1016
+
1017
+ 11. **Use `def call(*, **)` when Arguments DSL handles all validation**
1018
+
1019
+ When using the Arguments DSL with patterns where optional positionals precede
1020
+ required ones (matching Ruby's parameter binding semantics), prefer the
1021
+ catch-all signature `def call(*, **)` and let `ARGS.bind(*, **)` handle
1022
+ all validation.
1023
+
1024
+ Note: `ARGS.bind` validates per-argument parameters (unknown options,
1025
+ `required:`, `type:`, `allow_nil:`, and operand format) and also evaluates
1026
+ any declared cross-argument constraints (`conflicts`, `requires`,
1027
+ `requires_one_of`, `requires_exactly_one_of`, `forbid_values`, `allowed_values`).
1028
+ Command classes generally do not declare cross-argument constraints (see Insight
1029
+ 6 validation delegation policy) — inter-option constraint enforcement is
1030
+ delegated to git, with the exception of `skip_cli: true` arguments that never
1031
+ reach git's argv (see the `cat-file --batch` example above).
1032
+
1033
+ ```ruby
1034
+ # git branch -m [<old-branch>] <new-branch>
1035
+ ARGS = Arguments.define do
1036
+ literal '--move'
1037
+ flag_option :force
1038
+ operand :old_branch # optional (no required: true)
1039
+ operand :new_branch, required: true # required
1040
+ end.freeze
1041
+
1042
+ # ✅ Preferred: let ARGS.bind handle validation
1043
+ def call(*, **)
1044
+ @execution_context.command('branch', *ARGS.bind(*, **))
1045
+ end
1046
+
1047
+ # ❌ Avoid: explicit params trigger RuboCop Style/OptionalArguments
1048
+ def call(old_branch = nil, new_branch, **)
1049
+ # ...
1050
+ end
1051
+ ```
1052
+
1053
+ The Arguments DSL with Ruby-like positional allocation correctly fills
1054
+ required parameters before optional ones, so `move.call('new-name')` works
1055
+ as expected.
1056
+
1057
+ 12. **Arguments DSL supports Ruby-like positional parameter allocation**
1058
+
1059
+ The `PositionalAllocator` in the Arguments DSL follows Ruby's method parameter
1060
+ binding semantics. When optional positionals precede required ones, values are
1061
+ allocated to required parameters first:
1062
+
1063
+ ```ruby
1064
+ # Ruby method: def foo(a = 'default', b); end
1065
+ # foo('value') → a='default', b='value' (required b filled first)
1066
+
1067
+ # Arguments DSL equivalent:
1068
+ operand :old_branch # optional
1069
+ operand :new_branch, required: true # required
1070
+
1071
+ # Single value: ARGS.bind('new-name')
1072
+ # → old_branch=nil, new_branch='new-name'
1073
+
1074
+ # Two values: ARGS.bind('old-name', 'new-name')
1075
+ # → old_branch='old-name', new_branch='new-name'
1076
+ ```
1077
+
1078
+ This enables command interfaces that match git CLI patterns like
1079
+ `git branch -m [<old-branch>] <new-branch>` without awkward workarounds.
1080
+
1081
+ 13. **Commands layer maps option semantics, not argument ergonomics**
1082
+
1083
+ The Commands layer should strictly mirror git CLI semantics. When git uses
1084
+ `--option=value` syntax, the Commands class should use a keyword argument—even
1085
+ if a positional would feel more natural in Ruby:
1086
+
1087
+ ```ruby
1088
+ # Git CLI: git branch --set-upstream-to=<upstream> [<branch>]
1089
+ # ↑ <upstream> is the VALUE of --set-upstream-to option, not a positional
1090
+
1091
+ # ✅ Commands layer: strict CLI mapping
1092
+ class SetUpstream
1093
+ ARGS = Arguments.define do
1094
+ value_option :set_upstream_to, inline: true # keyword, not positional
1095
+ operand :branch_name
1096
+ end
1097
+
1098
+ def call(*, **)
1099
+ @execution_context.command('branch', *ARGS.bind(*, **))
1100
+ end
1101
+ end
1102
+
1103
+ # ✅ Higher-layer facade: ergonomic Ruby API (Phase 3)
1104
+ # This wrapper belongs in Git::Repository or Git::Branch, NOT in Git::Lib.
1105
+ # Git::Lib only adapts methods that existed in v4.3.0.
1106
+ def branch_set_upstream(upstream, branch_name = nil)
1107
+ SetUpstream.new(@execution_context).call(branch_name, set_upstream_to: upstream)
1108
+ end
1109
+ ```
1110
+
1111
+ This separation keeps Commands classes predictable (they mirror git 1:1) while
1112
+ allowing higher layers to provide intuitive Ruby interfaces. Ergonomic
1113
+ transformations—like reordering arguments or converting keywords to
1114
+ positionals—belong in higher layers (`Git::Repository`, `Git::Base`, `Git::Branch`),
1115
+ not in `Git::Lib` (which only adapts pre-existing methods for backward compatibility).
1116
+
1117
+ 14. **Use `allow_nil: true` for positional arguments that can be intentionally omitted**
1118
+
1119
+ Some git commands have positional arguments that are semantically present but
1120
+ should not appear in the command line. For example, `git checkout -- file.txt`
1121
+ restores from the index (no tree-ish), while `git checkout HEAD -- file.txt`
1122
+ restores from a commit.
1123
+
1124
+ Use `allow_nil: true` to mark a positional that can accept `nil` as a valid
1125
+ "present but empty" value:
1126
+
1127
+ ```ruby
1128
+ ARGS = Arguments.define do
1129
+ operand :tree_ish, required: true, allow_nil: true
1130
+ end_of_options
1131
+ operand :paths, repeatable: true
1132
+ end
1133
+
1134
+ # Restore from index (tree_ish intentionally nil)
1135
+ ARGS.bind(nil, 'file.txt')
1136
+ # → ['--', 'file.txt']
1137
+
1138
+ # Restore from commit
1139
+ ARGS.bind('HEAD', 'file.txt')
1140
+ # → ['HEAD', '--', 'file.txt']
1141
+ ```
1142
+
1143
+ Without `allow_nil: true`, passing `nil` would either skip the positional slot
1144
+ (causing argument misalignment) or raise a validation error for required
1145
+ arguments.
1146
+
1147
+ 15. **Namespace commands by mode, not just by operation**
1148
+
1149
+ When a git command has fundamentally different modes (not just different
1150
+ operations on the same concept), use nested namespaces that reflect the mode:
1151
+
1152
+ ```ruby
1153
+ # ✅ Different modes of git checkout → separate namespaces
1154
+ Git::Commands::Checkout::Branch # branch switching, creation
1155
+ Git::Commands::Checkout::Files # file restoration from tree-ish/index
1156
+
1157
+ # ✅ Different operations on same concept → flat namespace with operation suffix
1158
+ Git::Commands::Branch::Create
1159
+ Git::Commands::Branch::Delete
1160
+ Git::Commands::Branch::Move
1161
+ ```
1162
+
1163
+ The distinction: `Checkout::Branch` and `Checkout::Files` accept fundamentally
1164
+ different arguments and have different semantics. `Branch::Create` and
1165
+ `Branch::Delete` operate on the same conceptual entity (a branch) with the same
1166
+ core argument (branch name).
1167
+
1168
+ 16. **Subclass by operation, not output mode; `literal` is for operation selectors only**
1169
+
1170
+ Early command migrations created output-mode subclasses (`Diff::Patch`,
1171
+ `Diff::Numstat`, `Diff::Raw`, `Stash::ShowPatch`, etc.) that hardcoded format
1172
+ flags as `literal` entries. This was an anti-pattern: those subclasses were
1173
+ differentiated only by which output format they requested, not by which git
1174
+ operation they performed. The result was that every format change required a
1175
+ new class, the facade had to choose between them by type, and the parser
1176
+ contract was invisible.
1177
+
1178
+ **Correct subclass criterion:** Create a subclass (or a separate class in a
1179
+ namespace) only when the git operation itself differs — e.g.,
1180
+ `Branch::Create` vs `Branch::Delete` (different `--delete` flag makes them
1181
+ different operations). Do **not** create subclasses for the same operation
1182
+ with different `--format`, `--patch`, `--numstat`, `--raw`, etc. flags.
1183
+
1184
+ **Correct `literal` criterion:** A `literal` entry is justified only when it
1185
+ is an operation selector that defines what the class does — e.g.,
1186
+ `literal 'stash'` and `literal 'show'` in `Stash::Show`, or
1187
+ `literal '--delete'` in `Branch::Delete`. Output-mode flags (`--patch`,
1188
+ `--numstat`, `--raw`, `--no-color`, `--format=…`) are never operation
1189
+ selectors; they are options the facade passes to fulfill its own parsing or
1190
+ display requirements.
1191
+
1192
+ **Correct option placement:** Output-mode flags and parser-contract options
1193
+ belong at the facade call site, not inside the command class as `literal`
1194
+ entries. Declare them with `flag_option` or `value_option` in the DSL so the
1195
+ facade can pass them explicitly:
1196
+
1197
+ ```ruby
1198
+ # ❌ Anti-pattern: output mode hardcoded as literal
1199
+ class Diff::Patch < Git::Commands::Base
1200
+ arguments do
1201
+ literal 'diff'
1202
+ literal '--patch' # ← hides the parser contract; wrong layer
1203
+ ...
1204
+ end
1205
+ end
1206
+
1207
+ # ✅ Correct: single class; facade controls output mode
1208
+ class Diff < Git::Commands::Base
1209
+ arguments do
1210
+ literal 'diff'
1211
+ flag_option :patch # facade passes patch: true when it needs patch output
1212
+ flag_option :numstat # facade passes numstat: true when it needs numstat
1213
+ flag_option :raw # facade passes raw: true when it needs raw output
1214
+ ...
1215
+ end
1216
+ end
1217
+
1218
+ # lib/git/lib.rb — parser contract is now explicit and auditable:
1219
+ Git::Commands::Diff.new(self).call(patch: true, numstat: true, ...)
1220
+ ```
1221
+
1222
+ **Known anti-patterns (now fixed):** `Git::Commands::Diff::Patch`,
1223
+ `Git::Commands::Diff::Numstat`, `Git::Commands::Diff::Raw`,
1224
+ `Git::Commands::Stash::ShowPatch`, `Git::Commands::Stash::ShowNumstat`,
1225
+ `Git::Commands::Stash::ShowRaw` — all collapsed in this refactor.
1226
+ Additionally, `literal '--no-color'` in `Log` and `Grep`, and
1227
+ `literal "--format=…"` in `Branch::List` and `Tag::List` were moved to
1228
+ their respective facade call sites.
1229
+
1230
+ 17. **Command classes are neutral; the facade owns policy**
1231
+
1232
+ Command classes are faithful, neutral representations of the git CLI. They
1233
+ never hardcode `literal` entries for output-control, editor-suppression, or
1234
+ progress flags. The facade (`Git::Lib`) sets safe defaults at each call site
1235
+ (e.g. `edit: false`, `progress: false`); callers may override when needed.
1236
+ The execution layer (`GIT_EDITOR='true'`) is an unconditional safety net.
1237
+
1238
+ ```ruby
1239
+ # ❌ Anti-pattern: policy embedded in command class
1240
+ class Pull < Git::Commands::Base
1241
+ arguments do
1242
+ literal 'pull'
1243
+ literal '--no-edit' # ← wrong layer
1244
+ literal '--no-progress' # ← same problem
1245
+ end
1246
+ end
1247
+
1248
+ # ✅ Correct: command is neutral; facade passes policy options
1249
+ class Pull < Git::Commands::Base
1250
+ arguments do
1251
+ literal 'pull'
1252
+ flag_option :edit, negatable: true
1253
+ flag_option :progress, negatable: true
1254
+ end
1255
+ end
1256
+
1257
+ # lib/git/lib.rb — facade sets safe defaults:
1258
+ Git::Commands::Pull.new(self).call(edit: false, progress: false)
1259
+ ```
1260
+
1261
+ See "Command-layer neutrality" in CONTRIBUTING.md for the full policy.
1262
+
1263
+ - **1. Migrate the First Command (`add`)**:
1264
+
1265
+ - **Write Unit Tests First**: Write comprehensive RSpec unit tests for the
1266
+ *proposed* `Git::Commands::Add` class. These tests will fail initially because
1267
+ the class doesn't exist yet. The tests should be fast and mock an object with a
1268
+ `command` method that returns stdout strings.
1269
+
1270
+ - **Create Command Class**: Implement `Git::Commands::Add` to make the tests pass.
1271
+ This class will contain all the logic for building git add arguments and parsing
1272
+ its output. It will accept an execution context (any object responding to
1273
+ `command`) in its constructor and call `@execution_context.command('add', *args,
1274
+ **opts)` to execute commands.
1275
+
1276
+ - **Delegate from `Git::Lib`**: Modify the `add` method within the existing
1277
+ `Git::Lib` class. Instead of containing the implementation, it will now
1278
+ instantiate and call the new `Git::Commands::Add` object, passing `self` as the
1279
+ context.
1280
+
1281
+ - **Verify**: Run the full test suite (both Test::Unit and RSpec). The existing tests
1282
+ for `g.add` should still pass, but they will now be executing the new, refactored
1283
+ code.
59
1284
 
60
1285
  - **2. Incrementally Migrate Remaining Commands:**
61
1286
 
62
- - Repeat the process from the previous step for all other commands, one by one or in logical groups (e.g., all `diff` related commands, then all `log` commands).
1287
+ - Repeat the process from the previous step for all other commands, one by one or
1288
+ in logical groups (e.g., all `diff` related commands, then all `log` commands).
63
1289
 
64
1290
  - For each command (`add`, `commit`, `log`, `diff`, `status`, etc.):
65
1291
 
@@ -71,68 +1297,276 @@ This document outlines a step-by-step plan to implement the proposed architectur
71
1297
 
72
1298
  4. Run the full test suite to ensure no regressions have been introduced.
73
1299
 
74
- ## Phase 3: Refactoring the Public Interface
1300
+ ### Command Migration Checklist
1301
+
1302
+ The following tracks the migration status of commands from `Git::Lib` to
1303
+ `Git::Commands::*` classes.
1304
+
1305
+ **Reference implementations** (use these as templates):
1306
+
1307
+ - Simple command: `lib/git/commands/add.rb` + `spec/unit/git/commands/add_spec.rb`
1308
+ - Command with output parsing: `lib/git/commands/fsck.rb` +
1309
+ `spec/unit/git/commands/fsck_spec.rb`
1310
+ - Command with complex options: `lib/git/commands/clone.rb` +
1311
+ `spec/unit/git/commands/clone_spec.rb`
1312
+
1313
+ #### ✅ Migrated Commands
75
1314
 
76
- ***Goal**: Switch the public-facing classes to use the new architecture directly, breaking the final ties to the old implementation.*
1315
+ | Git::Lib Method | Command Class | Spec | Git Command |
1316
+ | --------------- | ------------- | ---- | ----------- |
1317
+ | `add` | `Git::Commands::Add` | `spec/unit/git/commands/add_spec.rb` | `git add` |
1318
+ | `clone` | `Git::Commands::Clone` | `spec/unit/git/commands/clone_spec.rb` | `git clone` |
1319
+ | `commit` | `Git::Commands::Commit` | `spec/unit/git/commands/commit_spec.rb` | `git commit` |
1320
+ | `fsck` | `Git::Commands::Fsck` | `spec/unit/git/commands/fsck_spec.rb` | `git fsck` |
1321
+ | `init` | `Git::Commands::Init` | `spec/unit/git/commands/init_spec.rb` | `git init` |
1322
+ | `mv` | `Git::Commands::Mv` | `spec/unit/git/commands/mv_spec.rb` | `git mv` |
1323
+ | `reset` | `Git::Commands::Reset` | `spec/unit/git/commands/reset_spec.rb` | `git reset` |
1324
+ | `rm` | `Git::Commands::Rm` | `spec/unit/git/commands/rm_spec.rb` | `git rm` |
1325
+ | `clean` | `Git::Commands::Clean` | `spec/unit/git/commands/clean_spec.rb` | `git clean` |
1326
+ | `branches_all` | `Git::Commands::Branch::List` | `spec/unit/git/commands/branch/list_spec.rb` | `git branch --list` |
1327
+ | `branch_new` | `Git::Commands::Branch::Create` | `spec/unit/git/commands/branch/create_spec.rb` | `git branch <name>` |
1328
+ | `branch_delete` | `Git::Commands::Branch::Delete` | `spec/unit/git/commands/branch/delete_spec.rb` | `git branch --delete <branch>` |
1329
+ | N/A (new) | `Git::Commands::Branch::Move` | `spec/unit/git/commands/branch/move_spec.rb` | `git branch --move <old-name> <new-name>` |
1330
+ | `branch_current` | `Git::Commands::Branch::ShowCurrent` | `spec/unit/git/commands/branch/show_current_spec.rb` | `git branch --show-current` |
1331
+ | N/A (new) | `Git::Commands::Branch::Copy` | `spec/unit/git/commands/branch/copy_spec.rb` | `git branch --copy <old-name> <new-name>` |
1332
+ | N/A (new) | `Git::Commands::Branch::SetUpstream` | `spec/unit/git/commands/branch/set_upstream_spec.rb` | `git branch --set-upstream-to <upstream> [<branch>]` |
1333
+ | N/A (new) | `Git::Commands::Branch::UnsetUpstream` | `spec/unit/git/commands/branch/unset_upstream_spec.rb` | `git branch --unset-upstream [<branch>]` |
1334
+ | `diff_full` / `diff_stats` / `diff_path_status` / `diff_index` | `Git::Commands::Diff` | `spec/unit/git/commands/diff_spec.rb` | `git diff` |
1335
+ | `stashes_list` | `Git::Commands::Stash::List` | `spec/unit/git/commands/stash/list_spec.rb` | `git stash list` |
1336
+ | `stash_save` | `Git::Commands::Stash::Push` | `spec/unit/git/commands/stash/push_spec.rb` | `git stash push` |
1337
+ | `stash_pop` | `Git::Commands::Stash::Pop` | `spec/unit/git/commands/stash/pop_spec.rb` | `git stash pop` |
1338
+ | `stash_apply` | `Git::Commands::Stash::Apply` | `spec/unit/git/commands/stash/apply_spec.rb` | `git stash apply` |
1339
+ | `stash_drop` | `Git::Commands::Stash::Drop` | `spec/unit/git/commands/stash/drop_spec.rb` | `git stash drop` |
1340
+ | `stash_clear` | `Git::Commands::Stash::Clear` | `spec/unit/git/commands/stash/clear_spec.rb` | `git stash clear` |
1341
+ | `checkout` / `checkout_file` | `Git::Commands::Checkout::Branch` / `Git::Commands::Checkout::Files` | `spec/unit/git/commands/checkout/branch_spec.rb` / `spec/unit/git/commands/checkout/files_spec.rb` | `git checkout` (branch) / `git checkout` (files) |
1342
+ | `merge` | `Git::Commands::Merge::Start` | `spec/unit/git/commands/merge/start_spec.rb` | `git merge` |
1343
+ | `tag` | `Git::Commands::Tag::*` | `spec/unit/git/commands/tag/*_spec.rb` | `git tag` |
1344
+ | N/A (new) | `Git::Commands::Merge::Abort` | `spec/unit/git/commands/merge/abort_spec.rb` | `git merge --abort` |
1345
+ | N/A (new) | `Git::Commands::Merge::Continue` | `spec/unit/git/commands/merge/continue_spec.rb` | `git merge --continue` |
1346
+ | N/A (new) | `Git::Commands::Merge::Quit` | `spec/unit/git/commands/merge/quit_spec.rb` | `git merge --quit` |
1347
+ | `merge_base` | `Git::Commands::MergeBase` | `spec/unit/git/commands/merge_base_spec.rb` | `git merge-base <commit> <commit>...` |
1348
+ | N/A (new) | `Git::Commands::Stash::Create` | `spec/unit/git/commands/stash/create_spec.rb` | `git stash create` |
1349
+ | N/A (new) | `Git::Commands::Stash::Store` | `spec/unit/git/commands/stash/store_spec.rb` | `git stash store` |
1350
+ | N/A (new) | `Git::Commands::Stash::Branch` | `spec/unit/git/commands/stash/branch_spec.rb` | `git stash branch` |
1351
+ | N/A (new) | `Git::Commands::Stash::Show` | `spec/unit/git/commands/stash/show_spec.rb` | `git stash show` |
1352
+ | `cat_file_*` | `Git::Commands::CatFile::*` | `spec/unit/git/commands/cat_file/*_spec.rb` | `git cat-file` |
1353
+ | `checkout_index` | `Git::Commands::CheckoutIndex` | `spec/unit/git/commands/checkout_index_spec.rb` | `git checkout-index` |
1354
+ | `archive` | `Git::Commands::Archive` | `spec/unit/git/commands/archive_spec.rb` | `git archive` |
1355
+ | `grep` | `Git::Commands::Grep` | `spec/unit/git/commands/grep_spec.rb` | `git grep` |
1356
+ | `log_commits` / `full_log_commits` | `Git::Commands::Log` | `spec/unit/git/commands/log_spec.rb` | `git log` |
1357
+ | `show` | `Git::Commands::Show` | `spec/unit/git/commands/show_spec.rb` | `git show` |
1358
+ | `describe` | `Git::Commands::Describe` | `spec/unit/git/commands/describe_spec.rb` | `git describe` |
1359
+ | `ls_files` | `Git::Commands::LsFiles` | `spec/unit/git/commands/ls_files_spec.rb` | `git ls-files` |
1360
+ | `ls_tree` / `full_tree` / `tree_depth` | `Git::Commands::LsTree` | `spec/unit/git/commands/ls_tree_spec.rb` | `git ls-tree` |
1361
+ | `fetch` | `Git::Commands::Fetch` | `spec/unit/git/commands/fetch_spec.rb` | `git fetch` |
1362
+ | `pull` | `Git::Commands::Pull` | `spec/unit/git/commands/pull_spec.rb` | `git pull` |
1363
+ | `push` | `Git::Commands::Push` | `spec/unit/git/commands/push_spec.rb` | `git push` |
1364
+ | `ls_remote` / `repository_default_branch` | `Git::Commands::LsRemote` | `spec/unit/git/commands/ls_remote_spec.rb` | `git ls-remote` |
1365
+ | `unmerged` | `Git::Commands::Diff` (existing) | — | `git diff --cached` |
1366
+ | N/A (index refresh for `diff_files`/`diff_index`) | `Git::Commands::Status` | `spec/unit/git/commands/status_spec.rb` | `git status` |
1367
+ | N/A (ref listing namespace) | `Git::Commands::ShowRef::List` | `spec/unit/git/commands/show_ref/list_spec.rb` | `git show-ref` |
1368
+ | N/A (ref verification namespace) | `Git::Commands::ShowRef::Verify` | `spec/unit/git/commands/show_ref/verify_spec.rb` | `git show-ref --verify` |
1369
+ | N/A (stdin filter namespace) | `Git::Commands::ShowRef::ExcludeExisting` | `spec/unit/git/commands/show_ref/exclude_existing_spec.rb` | `git show-ref --exclude-existing` |
1370
+ | N/A (existence check namespace) | `Git::Commands::ShowRef::Exists` | `spec/unit/git/commands/show_ref/exists_spec.rb` | `git show-ref --exists` |
1371
+ | `tag_sha` | `Git::Commands::ShowRef::List` | `spec/unit/git/lib_command_spec.rb` | `git show-ref --tags --hash` |
1372
+ | `apply` | `Git::Commands::Apply` | `spec/unit/git/commands/apply_spec.rb` | `git apply` |
1373
+ | `apply_mail` | `Git::Commands::Am::Apply` | `spec/unit/git/commands/am/apply_spec.rb` | `git am` |
1374
+ | N/A (new) | `Git::Commands::Am::Abort` | `spec/unit/git/commands/am/abort_spec.rb` | `git am --abort` |
1375
+ | N/A (new) | `Git::Commands::Am::Continue` | `spec/unit/git/commands/am/continue_spec.rb` | `git am --continue` |
1376
+ | N/A (new) | `Git::Commands::Am::Skip` | `spec/unit/git/commands/am/skip_spec.rb` | `git am --skip` |
1377
+ | N/A (new) | `Git::Commands::Am::Quit` | `spec/unit/git/commands/am/quit_spec.rb` | `git am --quit` |
1378
+ | N/A (new) | `Git::Commands::Am::Retry` | `spec/unit/git/commands/am/retry_spec.rb` | `git am --retry` |
1379
+ | N/A (new) | `Git::Commands::Am::ShowCurrentPatch` | `spec/unit/git/commands/am/show_current_patch_spec.rb` | `git am --show-current-patch` |
1380
+ | `name_rev` | `Git::Commands::NameRev` | `spec/unit/git/commands/name_rev_spec.rb` | `git name-rev` |
1381
+ | `commit_tree` | `Git::Commands::CommitTree` | `spec/unit/git/commands/commit_tree_spec.rb` | `git commit-tree` |
1382
+ | `update_ref` | `Git::Commands::UpdateRef::Update` | `spec/unit/git/commands/update_ref/update_spec.rb` | `git update-ref` |
1383
+ | N/A (new) | `Git::Commands::UpdateRef::Delete` | `spec/unit/git/commands/update_ref/delete_spec.rb` | `git update-ref -d` |
1384
+ | N/A (new) | `Git::Commands::UpdateRef::Batch` | `spec/unit/git/commands/update_ref/batch_spec.rb` | `git update-ref --stdin` |
1385
+ | `gc` | `Git::Commands::Gc` | `spec/unit/git/commands/gc_spec.rb` | `git gc` |
1386
+ | `repack` | `Git::Commands::Repack` | `spec/unit/git/commands/repack_spec.rb` | `git repack` |
1387
+ | `config_get` / `global_config_get` | `Git::Commands::ConfigOptionSyntax::Get` | `spec/unit/git/commands/config_option_syntax/get_spec.rb` | `git config --get` |
1388
+ | `config_list` / `global_config_list` / `parse_config` | `Git::Commands::ConfigOptionSyntax::List` | `spec/unit/git/commands/config_option_syntax/list_spec.rb` | `git config --list` |
1389
+ | `config_set` / `global_config_set` | `Git::Commands::ConfigOptionSyntax::Set` | `spec/unit/git/commands/config_option_syntax/set_spec.rb` | `git config` (set value) |
1390
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::Add` | `spec/unit/git/commands/config_option_syntax/add_spec.rb` | `git config --add` |
1391
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::GetAll` | `spec/unit/git/commands/config_option_syntax/get_all_spec.rb` | `git config --get-all` |
1392
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::GetColor` | `spec/unit/git/commands/config_option_syntax/get_color_spec.rb` | `git config --get-color` |
1393
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::GetColorBool` | `spec/unit/git/commands/config_option_syntax/get_color_bool_spec.rb`, `spec/integration/git/commands/config_option_syntax/get_color_bool_spec.rb` | `git config --get-colorbool` |
1394
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::GetRegexp` | `spec/unit/git/commands/config_option_syntax/get_regexp_spec.rb` | `git config --get-regexp` |
1395
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::GetUrlmatch` | `spec/unit/git/commands/config_option_syntax/get_urlmatch_spec.rb` | `git config --get-urlmatch` |
1396
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::RemoveSection` | `spec/unit/git/commands/config_option_syntax/remove_section_spec.rb` | `git config --remove-section` |
1397
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::RenameSection` | `spec/unit/git/commands/config_option_syntax/rename_section_spec.rb` | `git config --rename-section` |
1398
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::ReplaceAll` | `spec/unit/git/commands/config_option_syntax/replace_all_spec.rb` | `git config --replace-all` |
1399
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::Unset` | `spec/unit/git/commands/config_option_syntax/unset_spec.rb` | `git config --unset` |
1400
+ | N/A (new) | `Git::Commands::ConfigOptionSyntax::UnsetAll` | `spec/unit/git/commands/config_option_syntax/unset_all_spec.rb` | `git config --unset-all` |
77
1401
 
78
- 1. **Refactor Factory Methods**:
1402
+ | `worktrees_all` / `worktree_add` / `worktree_remove` / `worktree_prune` | `Git::Commands::Worktree::List` / `Git::Commands::Worktree::Add` / `Git::Commands::Worktree::Remove` / `Git::Commands::Worktree::Prune` (+ `Lock`, `Unlock`, `Move`, `Repair`) | `spec/unit/git/commands/worktree/*_spec.rb` | `git worktree` |
1403
+ | `change_head_branch` | `Git::Commands::SymbolicRef::Update` (+ `Read`, `Delete`) | `spec/unit/git/commands/symbolic_ref/*_spec.rb` | `git symbolic-ref` |
1404
+ | `current_command_version` | `Git::Commands::Version` | `spec/unit/git/commands/version_spec.rb` | `git version` |
1405
+ | `diff_as_hash` (private) | `Git::Commands::DiffFiles` / `Git::Commands::DiffIndex` | `spec/unit/git/commands/diff_files_spec.rb` / `spec/unit/git/commands/diff_index_spec.rb` | `git diff-files` / `git diff-index` |
1406
+ | `remote_add` / `remote_remove` / `remote_set_url` / `remote_set_branches` | `Git::Commands::Remote::*` | `spec/unit/git/commands/remote/*_spec.rb` | `git remote` |
1407
+ | `revert` | `Git::Commands::Revert::*` | `spec/unit/git/commands/revert/*_spec.rb` | `git revert` |
1408
+ | `rev_parse` | `Git::Commands::RevParse` | `spec/unit/git/commands/rev_parse_spec.rb` | `git rev-parse` |
1409
+ | `read_tree` | `Git::Commands::ReadTree` | `spec/unit/git/commands/read_tree_spec.rb` | `git read-tree` |
1410
+ | `write_tree` | `Git::Commands::WriteTree` | `spec/unit/git/commands/write_tree_spec.rb` | `git write-tree` |
1411
+ | N/A (new) | `Git::Commands::Maintenance::*` | `spec/unit/git/commands/maintenance/*_spec.rb` ⚠️ missing — needs specs | `git maintenance` |
79
1412
 
80
- - Modify the factory methods in the top-level `Git` module (`.open`, `.clone`, etc.).
1413
+ #### Commands To Migrate
81
1414
 
82
- - These methods will now be responsible for creating an instance of `Git::ExecutionContext` and injecting it into the constructor of a `Git::Repository` object.
1415
+ Commands are listed in recommended migration order within each group. Migrate in
1416
+ order: Basic Snapshotting → Branching & Merging → etc.
83
1417
 
84
- The return value of these factories will now be a `Git::Repository` instance, not a `Git::Base` instance.
1418
+ **Basic Snapshotting**:
85
1419
 
86
- 2. **Implement the Facade**:
1420
+ - [x] `rm` → `Git::Commands::Rm` — `git rm`
1421
+ - [x] `mv` → `Git::Commands::Mv` — `git mv`
1422
+ - [x] `commit` → `Git::Commands::Commit` — `git commit`
1423
+ - [x] `reset` → `Git::Commands::Reset` — `git reset`
1424
+ - [x] `clean` → `Git::Commands::Clean` — `git clean`
87
1425
 
88
- - Populate the `Git::Repository` class with the simple, one-line facade methods that delegate to the `Command` objects. For example:
1426
+ **Branching & Merging:**
1427
+
1428
+ - [x] `branches_all` → `Git::Commands::Branch::List` — `git branch --list` (returns `BranchInfo` value objects)
1429
+ - [x] `branch_new` → `Git::Commands::Branch::Create` — `git branch <name> [start-point]`
1430
+ - [x] `branch_delete` → `Git::Commands::Branch::Delete` — `git branch --delete <branch>`
1431
+ - [x] N/A (new) → `Git::Commands::Branch::Move` — `git branch --move <old-name> <new-name>`
1432
+ - [x] `branch_current` → `Git::Commands::Branch::ShowCurrent` — `git branch --show-current`
1433
+ - [x] N/A (new) → `Git::Commands::Branch::Copy` — `git branch --copy <old-name> <new-name>`
1434
+ - [x] N/A (new) → `Git::Commands::Branch::SetUpstream` — `git branch --set-upstream-to <upstream> [<branch>]`
1435
+ - [x] N/A (new) → `Git::Commands::Branch::UnsetUpstream` — `git branch --unset-upstream [<branch>]`
1436
+ - [x] `merge_base` → `Git::Commands::MergeBase` — `git merge-base <commit> <commit>...`
1437
+ - [x] `checkout` / `checkout_file` → `Git::Commands::Checkout::Branch` / `Git::Commands::Checkout::Files` — `git checkout`
1438
+ - [x] `merge` → `Git::Commands::Merge::Start` — `git merge`
1439
+ - [x] N/A (new) → `Git::Commands::Merge::Abort` / `Git::Commands::Merge::Continue` / `Git::Commands::Merge::Quit` — `git merge --abort/--continue/--quit`
1440
+ - [x] `tag` → `Git::Commands::Tag::*` — `git tag` (implemented as `List`, `Create`, `Delete`, and `Verify`)
1441
+ - [x] `stash_*` → `Git::Commands::Stash::*` — `git stash` (List, Push, Pop, Apply, Drop, Clear, Create, Store, Branch, Show)
1442
+
1443
+ **Inspection & Comparison:**
1444
+
1445
+ - [x] `log_commits` / `full_log_commits` → `Git::Commands::Log` — `git log`
1446
+ - [x] `diff_full` / `diff_stats` / `diff_path_status` / `diff_index` →
1447
+ `Git::Commands::Diff` — `git diff`
1448
+ - [x] `unmerged` → (use existing `Git::Commands::Diff` class) — `git diff`
1449
+ (one unmigrated call site in `Git::Lib#unmerged`; command class already exists)
1450
+ - [x] `diff_as_hash` (private) → `Git::Commands::DiffFiles` / `Git::Commands::DiffIndex`
1451
+ — `git diff-files` / `git diff-index`
1452
+ - [x] `status` → `Git::Commands::Status` — `git status`
1453
+ - [x] `tag_sha` (uses `show-ref` internally) → `Git::Commands::ShowRef::List` — `git show-ref`
1454
+ - [x] `show` → `Git::Commands::Show` — `git show`
1455
+ - [x] `describe` → `Git::Commands::Describe` — `git describe`
1456
+ - [x] `grep` → `Git::Commands::Grep` — `git grep`
1457
+ - [x] `ls_files` → `Git::Commands::LsFiles` — `git ls-files`
1458
+ - [x] `ls_tree` / `full_tree` / `tree_depth` → `Git::Commands::LsTree` — `git ls-tree`
1459
+
1460
+ **Sharing & Updating:**
1461
+
1462
+ - [x] `fetch` → `Git::Commands::Fetch` — `git fetch`
1463
+ - [x] `pull` → `Git::Commands::Pull` — `git pull`
1464
+ - [x] `push` → `Git::Commands::Push` — `git push`
1465
+ - [x] `remote_add` / `remote_remove` / `remote_set_url` / `remote_set_branches` →
1466
+ `Git::Commands::Remote` — `git remote`
1467
+ - [x] `ls_remote` / `repository_default_branch` → `Git::Commands::LsRemote` — `git ls-remote`
1468
+
1469
+ **Patching:**
1470
+
1471
+ - [x] `apply` / `apply_mail` → `Git::Commands::Apply` / `Git::Commands::Am::Apply` — `git apply` / `git am`
1472
+ - [x] `revert` → `Git::Commands::Revert::*` — `git revert` (implemented as `Start`, `Continue`, `Skip`, `Abort`, and `Quit`)
1473
+
1474
+ **Plumbing:**
1475
+
1476
+ - [x] `rev_parse` → `Git::Commands::RevParse` — `git rev-parse`
1477
+ - [x] `name_rev` → `Git::Commands::NameRev` — `git name-rev`
1478
+ - [x] `cat_file_*` → `Git::Commands::CatFile::*` — `git cat-file` (implemented as `Full`, `Meta`, `Pretty`, and `Typed`, with `Git::Lib#cat_file_*` delegating through these classes)
1479
+ - [x] `read_tree` → `Git::Commands::ReadTree` — `git read-tree`
1480
+ - [x] `commit_tree` → `Git::Commands::CommitTree` — `git commit-tree`
1481
+ - [x] `update_ref` → `Git::Commands::UpdateRef::*` — `git update-ref` (implemented as `Update`, `Delete`, and `Batch`)
1482
+ - [x] `checkout_index` → `Git::Commands::CheckoutIndex` — `git checkout-index`
1483
+ - [x] `archive` → `Git::Commands::Archive` — `git archive`
1484
+ - [x] `write_tree` → `Git::Commands::WriteTree` — `git write-tree`
1485
+
1486
+ **Administration:**
1487
+
1488
+ - [x] `gc` → `Git::Commands::Gc` — `git gc`
1489
+ - [x] `repack` → `Git::Commands::Repack` — `git repack`
1490
+
1491
+ **Setup & Config:**
1492
+
1493
+ - [x] `config_get` / `config_set` / `global_config_*` / `config_list` →
1494
+ `Git::Commands::ConfigOptionSyntax::*` — `git config`
1495
+
1496
+ **Other:**
1497
+
1498
+ - [x] `worktree_add` / `worktree_remove` → `Git::Commands::Worktree` — `git worktree`
1499
+ - [x] `branch_contains` → (part of `Git::Commands::Branch`)
1500
+ - [x] `change_head_branch` → `Git::Commands::SymbolicRef` — `git symbolic-ref`
1501
+ - [x] `repository_default_branch` → (part of `Git::Commands::LsRemote`)
1502
+ - [x] `current_command_version` → `Git::Commands::Version` — `git version`
1503
+ - [x] N/A (new) → `Git::Commands::Maintenance::*` — `git maintenance` (Register, Run, Start, Stop, Unregister) ⚠️ missing specs
1504
+
1505
+ ## Phase 3: Refactoring the Public Interface
89
1506
 
90
- ```ruby
91
- def commit(msg)
92
- Git::Commands::Commit.new(@execution_context, msg).run
93
- end
94
- ```
1507
+ ***Goal**: Switch the public-facing classes to use the new architecture directly,
1508
+ breaking the final ties to the old implementation.*
95
1509
 
96
- - Organize these facade methods into modules as planned (`lib/git/repository/branching.rb`, etc.) and include them in the main `Git::Repository` class.
1510
+ > **Status**: Phase 3 is complete. Tasks 1 and 2 are both complete; the remaining
1511
+ > redesign work is the Phase 4 cleanup described in the [Next Task](#next-task)
1512
+ > section above.
97
1513
 
98
- 3. **Deprecate and Alias `Git::Base`**:
1514
+ 1. **Add `binary_path:` to `Git::ExecutionContext`** ✅
99
1515
 
100
- - To maintain a degree of backward compatibility through the transition, make `Git::Base` a deprecated constant that points to `Git::Repository`.
1516
+ `Git::ExecutionContext` gained `binary_path:` in its constructor; all subclasses
1517
+ forward it. `command_line_capturing`/`command_line_streaming` use `@binary_path`.
1518
+ `Git::ExecutionContext::Repository.from_base` forwards `binary_path:`. The `Open3`
1519
+ stopgap in `Git.run_git_version` was replaced with
1520
+ `Git::Commands::Version.new(Git::ExecutionContext::Global.new(...)).call`.
101
1521
 
102
- ```ruby
103
- Git::Base = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(
104
- 'Git::Base',
105
- 'Git::Repository',
106
- Git::Deprecation
107
- )
108
- ```
1522
+ 2. **Implement the Facade** ✅
109
1523
 
110
- - This ensures that any user code checking `is_a?(Git::Base)` will not immediately break.
1524
+ `Git::Repository` now includes 15 modules via `include` in
1525
+ `lib/git/repository.rb` (see [Facade Modules Completed](#facade-modules-completed)).
1526
+ `Git::Base` wraps the corresponding methods via `facade_repository`, and the
1527
+ end-of-Phase-3 parity sweep landed the remaining low-level facade coverage
1528
+ needed before the entry-point flip — including `describe`, `show`, `fsck`,
1529
+ `apply`, `apply_mail`, `read_tree`, `cat_file_*`, `repack`, `gc`, helper/path
1530
+ context methods, and the remaining remote/tag convenience APIs.
111
1531
 
112
1532
  ## Phase 4: Final Cleanup and Release Preparation
113
1533
 
114
- ***Goal**: Remove all old code, finalize the test suite, and prepare for the v5.0.0 release.*
1534
+ ***Goal**: Remove all old code, finalize the test suite, and prepare for the v5.0.0
1535
+ release.*
115
1536
 
116
- 1. **Remove Old Code**:
1537
+ ### Phase 4 step graph
117
1538
 
118
- - Delete the `Git::Lib` class entirely.
1539
+ ```mermaid
1540
+ graph LR
1541
+ A --> B
1542
+ B --> C
1543
+ ```
119
1544
 
120
- - Delete the `Git::Base` class file and remove the deprecation proxy.
1545
+ #### Step A Remove old code
121
1546
 
122
- - Remove any other dead code that was part of the old implementation.
1547
+ - Delete `attr_reader :base_object`, remove `base_object:` from `#initialize`, and remove or convert `from_base`.
1548
+ - Delete the `Git::Lib` class entirely.
1549
+ - Delete the `Git::Base` class file.
1550
+ - Remove any other dead code that was part of the old implementation.
123
1551
 
124
- 2. **Finalize Test Suite**:
1552
+ **Done when**: `lib/git/lib.rb` and `lib/git/base.rb` are deleted; `Git::ExecutionContext::Repository` no longer accepts or exposes `base_object`; no references to `Git::Lib` or `Git::Base` remain in `lib/`.
125
1553
 
126
- - Convert any remaining, relevant TestUnit tests to RSpec.
1554
+ **Planning tip**: Before generating a deletion plan, audit all remaining callers of `Git::Lib`, `Git::Base`, and `from_base` across `lib/` and `spec/`. The bridge removal and `Git::Base` deletion must land atomically in the same PR — plan for a single large deletion commit rather than incremental removals.
127
1555
 
128
- - Remove the `test-unit` dependency from the `Gemfile`.
1556
+ #### Step B Finalize test suite
129
1557
 
130
- - Ensure the RSpec suite has comprehensive coverage for the new architecture.
1558
+ - Convert any remaining, relevant Test::Unit tests to RSpec.
1559
+ - Remove the `test-unit` dependency from the `Gemfile`.
1560
+ - Ensure the RSpec suite has comprehensive coverage for the new architecture.
131
1561
 
132
- 3. **Update Documentation**:
1562
+ **Done when**: The `tests/` directory is empty or removed; `test-unit` is no longer
1563
+ in `Gemfile`; RSpec is the sole test framework.
133
1564
 
134
- - Thoroughly document the new public API (`Git`, `Git::Repository`, etc.).
1565
+ #### Step C Update documentation
135
1566
 
136
- - Mark all internal classes (`ExecutionContext`, `Commands`, `*Path`) with `@api private` in the YARD documentation.
1567
+ - Thoroughly document the new public API (`Git`, `Git::Repository`, etc.).
1568
+ - Mark all internal classes (`ExecutionContext`, `Commands`, `*Path`) with `@api private` in the YARD documentation.
1569
+ - Update the `README.md` and create a `UPGRADING.md` guide explaining the breaking changes for v5.0.0.
137
1570
 
138
- - Update the `README.md` and create a `UPGRADING.md` guide explaining the breaking changes for v5.0.0.
1571
+ **Done when**: `yard stats` reports no missing docs on public API; `UPGRADING.md`
1572
+ covers all breaking changes; `README.md` reflects the new entry points.