Add auto-vendor support to git go-patch#506
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an “auto-vendor” workflow to git go-patch so vendor directory contents don’t need to be stored in patch files. It does this by stripping vendor diffs during extract, and regenerating/staging vendor trees via go mod vendor during apply, dramatically reducing patch size for vendored changes.
Changes:
- Introduces shared patch-command parsing and auto-vendor patch scanning in the
patchpackage. - Adds vendor-diff filtering during
extractand per-patch apply support (with post-apply callbacks) to enablego mod vendorbetween patches. - Updates
applyto detect auto-vendor patches and amend commits with regenerated vendor trees; bumps tool version tov1.1.0.
Show a summary per file
| File | Description |
|---|---|
| patch/vendor.go | Adds vendor-diff filtering plus go mod vendor execution/staging/amend support. |
| patch/vendor_test.go | Adds unit tests for vendor filtering and vendor-path detection logic. |
| patch/patch.go | Adds ApplyIndividually to apply patches one-by-one with an after-apply hook. |
| patch/commands.go | Adds shared command constants, patch command parsing, and auto-vendor patch scanning. |
| cmd/git-go-patch/extract.go | Uses shared command parsing; strips vendor diffs when auto-vendor is specified. |
| cmd/git-go-patch/apply.go | Pre-scans for auto-vendor patches and applies patches individually with vendor regeneration. |
| cmd/git-go-patch/git-go-patch.go | Bumps tool version to v1.1.0. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 4
5d08a3b to
6cff696
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
6cff696 to
8a69be6
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
8a69be6 to
81a6731
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
81a6731 to
a17ffb5
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
a17ffb5 to
2eed36b
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
2eed36b to
bf9c939
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
bf9c939 to
d2e134e
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
d2e134e to
508cb26
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
508cb26 to
049efd7
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
Add a new patch command 'auto vendor <dir1> [<dir2> ...]' that eliminates the need to store vendor directory contents in patch files. When a patch includes this command: - During 'extract': diff hunks for vendor directories (e.g. <dir>/vendor/) are stripped from the patch file, dramatically reducing patch size. - During 'apply': patches are applied individually, and after each auto-vendor patch, 'go mod vendor' is run in the specified module directories, then the commit is amended to include the vendor changes. This reduces the microsoft-go vendor patch (0001) from ~43,000 lines to ~240 lines, making patches easier to review, rebase, and maintain. New patch package exports: - CommandPrefix, PatchNumberCommand, AutoVendorPrefix constants - ReadPatchCommands, ScanAutoVendorPatches functions - FilterVendorContent, VendorPathsFromModDirs, RunGoModVendor functions - ApplyIndividually function for per-patch callbacks Bumps version to v1.1.0.
049efd7 to
70acb19
Compare
Replace the ~45,000-line vendor patch with a ~240-line patch that only tracks go.mod, go.sum, and related non-vendor files. Vendor directories are now regenerated automatically during 'git go-patch apply' and 'submodule-refresh' using 'go mod vendor'. Changes: - .git-go-patch: bump MinimumToolVersion to v1.1.0 - patches/0001: strip vendor diffs, add 'auto vendor src src/cmd' command - submodule-refresh.go: use ScanAutoVendorPatches + ApplyIndividually - eng/_util/go.mod: update go-infra dependency Depends on: microsoft/go-infra#506
After go mod vendor runs with lowered go directives, modules.txt records the lowered versions. When we restore the original go directives in go.mod files, modules.txt becomes stale. Post-build vendor checks then fail because re-running go mod vendor with the real Go version produces different modules.txt content. Add fixModulesTxtGoVersions to update modules.txt entries for local replace targets after restoring their go directives.
There was a problem hiding this comment.
After each such patch,
go mod vendoris run in the specified module directories
The go used to run go mod vendor has to match the source tree exactly (not just >), how is that handled?
Overall, I don't think this approach makes sense (at least I can't justify it in my head as a reviewer vs. what seems possible), it seems super complicated and has many performance implications.
(I know this is a draft, but it already has a release on merge label...)
Summary
Add a new
git go-patchcommand that eliminates the need to store vendor directory contents in patch files. This reduces the microsoft-go vendor patch (0001) from ~43,000 lines to ~240 lines.How it works
A patch commit message can include the command:
During
extractDiff hunks for vendor directories (
src/vendor/,src/cmd/vendor/) are automatically stripped from the patch file. Onlygo.mod,go.sum, and other non-vendor files are preserved.During
applyPatches with auto-vendor commands are applied individually. After each such patch,
go mod vendoris run in the specified module directories and the commit is amended to include the regenerated vendor tree.Example: new patch 0001
The current
0001-Vendor-external-dependencies.patchin microsoft-go is ~43,000 lines of vendored Go source. With auto-vendor, it becomes ~240 lines:Changes
New files
patch/commands.go— Shared command parsing (constants +ReadPatchCommands,ScanAutoVendorPatches)patch/vendor.go—FilterVendorContent(strips vendor diffs),VendorPathsFromModDirs,RunGoModVendorpatch/vendor_test.go— Tests for filtering and vendor path logicModified files
patch/patch.go— AddedApplyIndividually(per-patch apply with callback)cmd/git-go-patch/extract.go— Uses shared constants/functions frompatchpackage; filters vendor content during extractcmd/git-go-patch/apply.go— Pre-scans for auto-vendor patches; usesApplyIndividually+RunGoModVendorcmd/git-go-patch/git-go-patch.go— Version bump to v1.1.0Companion change
The microsoft-go repo will need a follow-up PR to:
.git-go-patchMinimumToolVersion to v1.1.00001-Vendor-external-dependencies.patchwith the ~240-line versioneng/_util/cmd/submodule-refresh/submodule-refresh.goto useScanAutoVendorPatches+ApplyIndividually