Repository navigation
Add replace command for dependency redirects - #236
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new git pkgs replace command to support redirecting a dependency to a local checkout, git ref, or explicit version (via the existing add flow) to enable downstream testing workflows across multiple ecosystems.
Changes:
- Adds a new
replaceCLI subcommand wired into the root command. - Implements replace behavior via manager subprocess calls (Go/npm-family/Composer) and manifest edits (Cargo/uv/Bundler).
- Documents
replaceusage in the README and adds tests for dry-run output, validation, and manifest editing behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new replace command and supported behaviors/limitations. |
| cmd/root.go | Registers the new replace subcommand. |
| cmd/replace.go | Implements replace command logic, manager dispatch, and manifest edits. |
| cmd/replace_test.go | Adds tests for dry-run output, validation, and manifest editing. |
| cmd/pager_test.go | Ensures replace accepts the global --pager flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0d1072b to
2c66b54
Compare
andrew
left a comment
There was a problem hiding this comment.
Thanks for picking this up. The CLI surface matches #181 and the Gemfile/TOML round-tripping is more careful than I expected. A few structural things before this lands.
Subprocess managers should go through the managers schema. #181 says gomod/npm/composer "fit the existing managers command schema" — i.e. define a replace operation in git-pkgs/managers and call it via BuildCommands(mgr, "replace", input) the way add does. This PR hardcodes argv in buildGoReplaceCommands/buildNPMReplaceCommands/buildComposerReplaceCommands and runs them through a bespoke runShellCommands. That duplicates the runner, the dry-run formatting, and -x handling that managers already owns. The version-mode path already does it right — the other modes should match.
No capability declarations. #181 asks for replace_path/replace_git capabilities per manager so callers can check support up front. The PR switches on a hardcoded name list instead. Once the operations move into managers the capabilities fall out of the schema, but they need to be queryable.
Gemfile filter misses github: and hash-rocket syntax. filterGemReplacementArgs strips git:/path:/branch:/tag:/ref: but not github: (bundler's shorthand) or :git => "...". So replace rails --git ... on gem "rails", github: "rails/rails" writes a line with both github: and git:, which bundler rejects. Add github:/gist:/bitbucket: and the :key => form to the filter.
gomod --git --ref produces an unbuildable go.mod. go mod edit -replace x=github.com/fork/x@feature-branch writes replace x => github.com/fork/x feature-branch, but the replace directive needs a version, not a ref. go mod tidy will reject it. The test only checks argv shape so this isn't caught. Either resolve the ref to a pseudo-version first (go list -m github.com/fork/x@feature-branch) or document that --ref for gomod must be a version.
Cargo --ref always emits rev =. #181 specced branch = "...". rev works but pins to the commit at fetch time rather than tracking the branch. Probably want branch when the ref isn't a SHA.
Manifest editing location. #181 points the cargo/uv/bundler edits at the manifests package, but that package is parse-only today so I understand inlining. Fine to leave the ~300 lines of TOML/Gemfile munging here for now, but please pull updateTOMLSectionEntry/updateGemfileLine and friends into cmd/replace_manifest.go (or similar) so replace.go stays readable — it's 767 lines vs add.go at 135.
Smaller:
updateTOMLSectionEntryleaves an empty[patch.crates-io]header behind after--drop, and won't match a header with a trailing comment.appendExtraappends-xargs to every command in a multi-command sequence (composer git+ref runs two commands; extras land on bothconfigandrequire).
2c66b54 to
3b9cbe2
Compare
|
Thanks, fixed
Added regression coverage for the Go ref boundary, Cargo branch refs, Gemfile shorthand/hash-rocket filtering, empty TOML section removal and Composer extras placement. |
|
The replace operation has landed in What moves:
What stays in
After detection it becomes roughly: result, err := mgr.Replace(ctx, opts.Package, managers.ReplaceOptions{
Path: opts.Path,
Git: opts.Git,
Ref: opts.Ref,
Drop: opts.Mode == replaceModeDrop,
Extra: opts.Extra,
})One behaviour difference: the library now requires |
b3ba23d to
08ea394
Compare
|
Updated this to use The local replace overlay/capability injection is gone, and For I also updated the tests around gomod ref validation, delegated dry-run command generation, cargo/uv/bundler manifest behavior, npm unsupported drop and composer extra-arg placement. Verified with:
|
andrew
left a comment
There was a problem hiding this comment.
Refactor to managers v0.10.0 looks right. The MockRunner-driven dry-run is a nice way to keep the preview in lockstep with the real path; the replaceManifestPath duplication of the library's manager→manifest map is minor and can move upstream later if it grows.
closes #181
Summary
Adds
git pkgs replacefor redirecting a dependency to a local checkout, git ref or explicit registry version for downstream testing workflows.Changes
git pkgs replace <package> [version]--path,--git,--ref,--drop,--manager,--ecosystem,--dry-runand timeout/extra argsaddoperationgo mod edit[patch.crates-io], uv[tool.uv.sources]and BundlerGemfileNotes
npm-family
--dropis intentionally rejected because the original registry version constraint cannot be recovered safely. Users can restore a registry dependency with:Testing