name: extract-facade-from-base-lib description: "Migrates a public method from Git::Base or Git::Lib to a Git::Repository facade method (under lib/git/repository/) as part of the v5.0.0 architectural redesign. Use when extracting a specific public method during the Strangler Fig migration of Git::Base / Git::Lib into Git::Repository."
Extract Facade from Base/Lib
Migrate an existing public method from Git::Base and/or Git::Lib to a
Git::Repository::* facade method. This is the second extraction step of the
v5.0.0 redesign — it follows
Extract Command from Lib, which moves
the underlying CLI invocation into a Git::Commands::* class.
In Phase 4 of the redesign, both Git::Base and Git::Lib will be deleted.
This migration moves their public surface to Git::Repository. Until Phase 4,
the original methods remain in place and delegate to the new facade method to
preserve backward compatibility within the migration window.
Contents
- How to use this skill
- Prerequisites
- Related skills
- Input
- Source patterns
- Signature compatibility policy
- Keyword-arg remediation list
- Determining the option allowlist
- Workflow
- Commit discipline
- Quality gates
- What stays vs. what moves
- Review mode
How to use this skill
Attach this file to your Copilot Chat context, then invoke with the public method to migrate. Examples:
Using the Extract Facade from Base/Lib skill, migrate Git::Base#commit to
Git::Repository#commit.
Extract Facade: Git::Lib#branches_all (called publicly via g.lib.branches_all)
Prerequisites
Before starting, you MUST load the following skill(s):
- Facade Implementation — drives the actual scaffolding of the new facade method
- YARD Documentation — baseline YARD rules
Related skills
- Facade Implementation — used in Step 5 to scaffold the new facade method
- Facade Test Conventions — unit and integration test conventions for the new facade method
- Facade YARD Documentation — YARD docs for the new facade module/method
- Extract Command from Lib — sibling
extraction skill that moves the underlying CLI call into a
Git::Commands::*class. Run first when no command class exists yet. - Command Implementation — used in Step 4
if a new
Git::Commands::*class needs to be scaffolded - Project Context — three-layer architecture and Phase 4 deletion plan
Input
Required:
- The
Git::Baseand/orGit::Libpublic method to migrate. - The git operation it performs (subcommand + flags).
Source patterns
Public methods being migrated fall into one of three patterns. Identify which pattern applies before planning the migration.
Pattern A — Git::Base wrapper + Git::Lib implementation
The most common pattern. Git::Base#foo is a thin wrapper that forwards to
Git::Lib#foo, which contains the orchestration logic.
Examples: commit, diff_full, branches, worktree_add.
# lib/git/base.rb
def commit(message, opts = {})
self.lib.commit(message, opts)
end
# lib/git/lib.rb
def commit(message, opts = {})
opts = opts.merge(message: message) if message
deprecate_commit_no_gpg_sign_option!(opts)
Git::Commands::Commit.new(self).call(edit: false, **opts).stdout
end
Public contract source: Git::Base#commit signature; Git::Lib#commit
implementation.
When migrating, the facade method must preserve this signature exactly (e.g.
commit(message, opts = {})) — even though greenfield facade methods would prefer**optionsper facade-implementation REFERENCE.md — Choosing the method signature. The legacy public contract wins during migration.
Pattern B — Git::Lib-only (public-by-exposure)
The public API is g.lib.foo — Git::Base exposes Git::Lib as #lib (or
through a similar accessor), so Git::Lib methods are reachable as public API
even when no Git::Base wrapper exists.
Examples: branches_all, worktrees_all, current_branch_state.
# lib/git/lib.rb (no Git::Base wrapper exists)
def branches_all
result = Git::Commands::Branch::List.new(self).call(all: true, format: ...)
Git::Parsers::Branch.parse_list(result.stdout)
end
Public contract source: Git::Lib#foo signature and implementation.
Migration consequence: After Phase 4, callers using g.lib.foo must migrate
to g.foo (or g.repository.foo). Document this in the migration plan.
Pattern C — Git::Base-only (no Git::Lib method)
The implementation lives entirely in Git::Base with no Git::Lib counterpart.
The method may call command(...) directly via lib.send(...) or implement
filesystem operations.
Examples: add_remote, with_index, repo_size, archive.
# lib/git/base.rb
def repo_size
all_files_size = 0
Find.find(repo.path) { |f| all_files_size += File.size(f) if File.file?(f) }
all_files_size
end
Public contract source: Git::Base#foo signature and implementation.
Signature compatibility policy
Use this policy in both extraction mode and review mode:
| Classification | When it applies | Signature requirement |
|---|---|---|
legacy-contract |
Method existed in Git::Base and/or Git::Lib as public API |
Copy the 4.x signature verbatim, including rare **opts forms where they already exist |
5.x-native |
Truly new facade API with no legacy public predecessor | Use opts = {} style (kwargs migration is deferred to v6.x for consistency) |
Rules:
legacy-contractmethods preserve the exact 4.x call shape verbatim, including rare**optssignatures; never alter the parameter list when a legacy predecessor exists.5.x-nativemethods useopts = {}style for consistency; a broader kwargs migration is deferred to v6.x so it can be applied uniformly across the entire public API.Every extracted method must be explicitly classified as
legacy-contractor5.x-nativebefore the PR is opened.The classification must appear in the PR description and in the extracted method's YARD
@note. Example:# @note Signature compatibility: legacy-contract — preserves the exact Git::Base#foo 4.x call shape.
Keyword-arg remediation list
See KEYWORD_ARG_REMEDIATION.md for the initial list
of facade methods that use **opts/** keyword-splat where the legacy predecessor
used opts = {}. Each method in this list must be resolved before
Git.open/.clone/.init/.bare are changed to return Git::Repository:
either fix the signature to match the legacy-contract classification, or
record an explicit 5.x-native justification.
Determining the option allowlist
When the facade method uses assert_valid_opts!, the allowlist (*_ALLOWED_OPTS) must
contain only the options that were accepted in the 4.x branch of this gem. Do not
expand the allowlist to match everything the underlying Git::Commands::* class
supports — new options are deferred to a follow-up PR so they can be properly
documented and tested.
How to find the 4.x allowlist for a method:
- Open
https://github.com/ruby-git/ruby-git/blob/4.x/lib/git/lib.rband search for the method's*_OPTION_MAPconstant (e.g.ADD_OPTION_MAP,RESET_OPTION_MAP). - The option keys declared in that map are the only keys that were valid in 4.x.
Any key not present in the map would have raised
ArgumentErrorviaArgsBuilder.validate!— confirmed byhttps://github.com/ruby-git/ruby-git/blob/4.x/lib/git/args_builder.rb. - Use those keys — and only those keys — in the facade's
*_ALLOWED_OPTSconstant,@optionYARD tags, and integration/unit tests. - If the underlying
Git::Commands::*class supports additional options beyond the 4.x map, note them in a follow-up issue rather than silently including them.
Workflow
Branch setup
All work must be done on a feature branch. Never commit or push directly to
main.
git checkout -b <feature-branch-name>
Step 1 — Identify the source pattern
Locate the public method in
Git::Baseand/orGit::Lib.Determine which Source pattern applies (A, B, or C).
Note:
- the public signature (positional args, options hash, keyword args)
- the signature classification (
legacy-contractor5.x-native) and justification - the exact return value of the legacy method — read the source code to
see whether it ends in
.stdout,.stdout.chomp, a parser call, a domain object,nil, etc. Do not assume from the YARD@returntag, which may be stale or missing. The facade must reproduce this exact value (e.g. ifGit::Lib#addends in.stdout, the facade returnsString, notGit::CommandLineResult). - any pre-processing (path expansion, option whitelisting, deprecation handling)
- any post-processing (parsing, result-class assembly)
- any execution-context arguments (
timeout:,chdir:,env:) - the 4.x-supported options: locate the corresponding
*_OPTION_MAPconstant in4.x/lib/git/lib.rband record which option keys it declared. These become the facade's*_ALLOWED_OPTSallowlist — see Determining the option allowlist.
Document the method's current public contract in writing — it must be preserved exactly by the facade method.
Run linters and rubocop to confirm a clean baseline:
bundle exec rubocop
Step 2 — Plan the migration and get approval
Before writing or changing any code, present a migration plan and wait for explicit confirmation from the user.
The plan must include:
| Public method | Source pattern | Underlying command class | Class exists? | Target facade module | Notes |
|---|---|---|---|---|---|
Git::Base#foo |
A / B / C | Git::Commands::Foo |
✅ / 🆕 | Git::Repository::Topic (existing or new) |
mapping decisions |
Also state:
- The exact public contract to preserve (signature + return type + raised errors).
- The signature classification and why (
legacy-contractor5.x-native). - For
legacy-contractmethods, confirm the exact 4.x call shape is preserved verbatim (including rare**optssignatures). - Whether a new topic module is required (justify per
facade-implementation REFERENCE.md).
When extracting one method at a time, scan
Git::Base/Git::Libfor siblings on the same git topic and checkredesign/3_architecture_implementation.mdbefore deciding — see One-at-a-time extraction. - The delegation strategy for
Git::Baseand/orGit::Lib(Step 6) — both remain in place during the migration window and delegate to the new facade. - For Pattern B: explicit note that
g.lib.foocallers will need to migrate before Phase 4; capture this as a follow-up issue or CHANGELOG entry.
Then ask:
Does this mapping look correct? Any changes before I start implementing?
Do not move to Step 3 until the user confirms the plan.
Step 3 — Ensure adequate legacy tests
Verify that legacy tests in tests/units/ and existing specs in spec/
adequately cover the public method. The legacy tests guarantee the migration
preserves backward compatibility.
Search for coverage:
grep -rn '<method_name>' tests/units/ spec/If coverage is insufficient, add minimal new tests that exercise the current public contract. Use existing legacy test conventions for
Test::Unittests intests/units/. Do not change existing tests.Add or update facade tests that prove signature behavior:
- for
legacy-contractmethods, test the expected legacy call shape(s) (positional hash and/or keyword-arg /**opts)
- for
Run the new tests and RuboCop:
bundle exec bin/test <test-file-basename> bundle exec rubocop tests/units/<test-file>Commit:
git commit -m "refactor(test): add legacy tests for <method_name>"
Step 4 — Ensure the underlying Git::Commands::* class exists
The facade method calls one or more Git::Commands::* classes. If any required
command class does not exist yet, scaffold it first using
Extract Command from Lib (which in turn
uses Command Implementation).
For Pattern C migrations, the source Git::Base method may not currently call
through a Git::Commands::* class at all (it uses command(...) directly or
filesystem operations). In that case, you must scaffold the Git::Commands::*
class before this step.
Skip this step when every required command class already exists.
Step 5 — Implement the facade method
Delegate to the Facade Implementation skill in Scaffold or Update mode. That skill handles:
- topic module selection
- generating or extending
lib/git/repository/<topic>.rb - generating or extending
spec/unit/git/repository/<topic>_spec.rb - generating or extending
spec/integration/git/repository/<topic>_spec.rb - YARD documentation
- running facade-side quality gates
The new facade method must preserve the source method's public contract
exactly — same signature, same return type, same raised errors. Use the
exact return type the source method documented (String, Array, Hash, domain
object, CommandLineResult).
Apply the Signature compatibility policy:
legacy-contract: preserve the 4.x call shape verbatim and add call-shape tests.5.x-native: useopts = {}style; classification must be explicit in migration notes.
For Pattern A and B migrations, copy any pre-processing logic
(option whitelisting, deprecation rewrites, key normalization) from Git::Lib
to the facade method. Do not leave it behind in Git::Lib — the facade is
now the source of truth.
When copying option whitelisting logic, use only the keys from the 4.x
*_OPTION_MAP for the *_ALLOWED_OPTS constant — do not expand to match the
full Git::Commands::* argument DSL. See
Determining the option allowlist.
For Pattern C migrations, port any pre-processing or filesystem logic from
Git::Base to the facade method.
After the facade method is in place and tests pass, commit:
git commit -m "feat(repository): add Git::Repository#<method_name> facade method"
Step 6 — Update Git::Base and/or Git::Lib to delegate
The original methods stay in place during the migration window and delegate to
the new facade method. Both Git::Base and Git::Lib will be deleted in
Phase 4; until then, delegation preserves backward compatibility.
For each source pattern, the delegation looks like:
Pattern A — both files delegate:
# lib/git/base.rb — already a wrapper; redirect to repository
def commit(message, opts = {})
repository.commit(message, opts)
end
# lib/git/lib.rb — keep public-by-exposure callers working
def commit(message, opts = {})
@repository.commit(message, opts)
end
Pattern B — Git::Lib delegates:
# lib/git/lib.rb
def branches_all
@repository.branches_all
end
Pattern C — Git::Base delegates:
# lib/git/base.rb
def remote_add(name, url, opts = {})
facade_repository.remote_add(name, url, opts)
end
(Use facade_repository to access the Git::Repository facade instance — this
is the accessor used by all migrated methods in Git::Base.)
After delegation is in place, verify:
bundle exec bin/test <legacy-test-file-basename>
bundle exec rspec
bundle exec rubocop
bundle exec rake yard
Commit:
git commit -m "refactor(base): delegate <method_name> to Git::Repository"
(Use refactor(lib): if only Git::Lib was updated. When both files change,
use two separate commits — one per scope — to keep each commit single-scoped.)
Commit discipline
Keep work organized into three logical commit categories (each optional if no changes were needed for that step):
refactor(test): add legacy tests for <method_name>— new tests intests/units/(Step 3)feat(repository): add Git::Repository#<method_name> facade method— new facade module/method, unit specs, integration specs (Step 5)refactor(base): delegate <method_name> to Git::Repository—Git::Baseupdated to delegate (Step 6); userefactor(lib):if onlyGit::Libchanged. When both files change, prefer two separate commits — one per scope — so each commit has a single conventional-commits scope.
If a new Git::Commands::* class was scaffolded in Step 4, it gets its own
commit (refactor(command): add Git::Commands::<Command> class) per
Extract Command from Lib.
Issue and PR references in commit bodies: Do not use #<number> in the
commit body — write issue 1000 not issue #1000. To close an issue/PR, use
Closes/Fixes/Resolves #<number> in the footer.
If further changes are needed after task commits are created, amend into the appropriate commit and rebase. Always verify quality gates pass after rebasing.
Quality gates
Run the gates discovered from the project's parallel default task at every step:
bundle exec ruby -e "require 'rake'; load 'Rakefile'; puts Rake::Task['default:parallel'].prerequisites"
Run each listed task individually via bundle exec rake <task> and fix
failures before advancing. All listed tasks must pass before committing.
What stays vs. what moves
Stays in Git::Base / Git::Lib until Phase 4:
- Delegating methods — one-line forwards to the new
Git::Repositoryfacade method, preserving backward compatibility during the migration window. - Methods not yet migrated — original implementation remains until extracted.
Moves to Git::Repository::*:
- The full public contract (signature, return type, raised errors).
- All pre-processing logic (option whitelisting, deprecation handling, key normalization, defaults).
- All post-processing logic (parsing, result-class assembly).
- The YARD docs that document the public API.
Branch workflow: Implement migrations on a feature branch. Never commit or push directly to
main— open a pull request when changes are ready to merge.
Review mode
Use this checklist to audit a completed extraction PR. For each item, read the relevant source files, check the box, and note any finding.
Invoke
Using the Extract Facade from Base/Lib skill (review mode), audit the extraction
of Git::Base#<method_name>.
R1 — Source analysis
- Pattern identified. Confirm which source pattern (A, B, or C) applies
by reading
Git::BaseandGit::Lib. - Classification recorded. The method is explicitly classified as
legacy-contractor5.x-native, with rationale. - Signature policy respected. For
legacy-contractmethods, facade signature behavior preserves the legacy call shape contract; for5.x-native,opts = {}style is confirmed (no**kwargsin v5). - Return type correct. The facade returns the same type as the legacy
implementation (e.g.
Stringfrom.stdout, notCommandLineResult). Read the source — do not rely on YARD tags alone. - 4.x options only in allowlist. The
*_ALLOWED_OPTSconstant contains only keys declared in the corresponding*_OPTION_MAPin4.x/lib/git/lib.rb. Look up the map athttps://github.com/ruby-git/ruby-git/blob/4.x/lib/git/lib.rb. Any extra keys are a finding. - Pre-processing ported. All option whitelisting, deprecation handling,
and key normalization from
Git::Libis reproduced in the facade. Nothing was left behind inGit::Lib. - Post-processing ported. Any parsing or result-class assembly that
lived in
Git::Libis reproduced in the facade.
R2 — Legacy test coverage
- Legacy tests exist and pass.
tests/units/has tests exercising the public method. Verify withbundle exec bin/test <test-file-basename>. - All 4.x options exercised. Every option in
*_ALLOWED_OPTShas at least one legacy or integration test that passes an actual value and asserts the outcome.
R3 — Command class
- Command class exists. The
Git::Commands::*class used by the facade exists inlib/git/commands/. - Arguments DSL covers the allowlisted options. Every key in
*_ALLOWED_OPTSmaps to a declared entry in the command'sargumentsblock.
R4 — Facade implementation
- Topic module correct. The facade method is placed in the right
Git::Repository::*module per the redesign topic groupings. -
assert_valid_opts!used. The facade callsGit::Repository::Internal.assert_valid_opts!(ALLOWED_OPTS, **)before forwarding to the command. -
*_ALLOWED_OPTSplacement correct. Each<METHOD>_ALLOWED_OPTSconstant is declared immediately before the public facade method that uses it (not grouped at the top of the module, not insidePrivate). - YARD docs complete. Each allowed option has an
@optiontag with type, name, default, and description.@param,@return,@raiseare present and accurate. - Unit specs present.
spec/unit/git/repository/<topic>_spec.rbcovers: default call, explicit path(s), each documented option, unknown option raisesArgumentError, return value is.stdout. - Call-shape tests present. For
legacy-contractmethods, tests assert the expected legacy call shape(s) as used in 4.x (positional hash and/or keyword-arg /**optswhere applicable). - Integration specs present (or explicitly skipped). Write
spec/integration/git/repository/<topic>_spec.rbonly when the facade adds behavior not exercised by any single command's integration tests — specifically multi-command orchestration or facade-owned post-processing of real git output. For one-line delegators (e.g.#add,#reset) the command's own integration tests already provide end-to-end coverage; omit the facade integration spec and add a comment in the unit spec explaining which command integration specs provide coverage.
R5 — Delegation
-
Git::Basedelegates. The originalGit::Basemethod is a one-line forward tofacade_repository.<method>(...). -
Git::Libdelegates (Pattern A/B only). The originalGit::Libmethod is a one-line forward to the facade. - Legacy tests still pass after delegation. Run
bundle exec bin/test <test-file-basename>against the delegating methods.
R6 — Quality gates
-
bundle exec rspecpasses -
bundle exec rubocoppasses -
bundle exec rake yardpasses (no undocumented public methods)