$npx -y skills add pulumi/agent-skills --skill upstream-patchesCreate, amend, remove, and rebase patches for Terraform provider submodules using ./scripts/upstream.sh. Use when upgrade-provider or manual patch work needs owning-patch lookup, patch conflict fixes, patch/hunk removal, or upstream rebase.
| 1 | # Upstream Patches |
| 2 | |
| 3 | `upstream/` is a git submodule pointing to the upstream Terraform provider. `patches/` contains patch files applied on top of it. Use `./scripts/upstream.sh` to manage patch state. |
| 4 | |
| 5 | ## Default Behavior |
| 6 | |
| 7 | - If fixing a regression introduced by an existing patch, amend the owning patch commit. |
| 8 | - Do not create a new patch unless the user explicitly asks. |
| 9 | |
| 10 | ## Commands Reference |
| 11 | |
| 12 | | Command | Description | |
| 13 | |---------|-------------| |
| 14 | | `./scripts/upstream.sh init` | Initialize upstream and apply patches to working directory | |
| 15 | | `./scripts/upstream.sh init -f` | Destructively discard checkout/rebase state and re-initialize upstream | |
| 16 | | `./scripts/upstream.sh checkout` | Create branch with patches as commits for editing | |
| 17 | | `./scripts/upstream.sh rebase -i` | Interactively edit patch commits | |
| 18 | | `./scripts/upstream.sh rebase -o <commit>` | Rebase patches onto a new upstream commit | |
| 19 | | `./scripts/upstream.sh check_in` | Write commits back to patches and exit checkout mode | |
| 20 | |
| 21 | ## Guardrails |
| 22 | |
| 23 | - Never commit directly to `upstream/` without `checkout/check_in`. |
| 24 | - Direct edits under `upstream/` outside checkout are ephemeral during `upgrade-provider`; the tool resets submodule state. |
| 25 | - Do not hand-edit `patches/*.patch` unless intentionally doing raw patch surgery. |
| 26 | - Prefer non-interactive rewrite flow over interactive rebase for agents. |
| 27 | |
| 28 | ## Find Owning Patch First |
| 29 | |
| 30 | Before editing patch content, identify the owning patch/commit. |
| 31 | |
| 32 | ```bash |
| 33 | ./scripts/upstream.sh checkout |
| 34 | |
| 35 | # Find candidate patch files by touched file path or unique hunk text |
| 36 | rg -n "path/to/file|unique_symbol" patches/*.patch |
| 37 | |
| 38 | # Optional: inspect candidate patch header/hunks |
| 39 | sed -n '1,120p' patches/00NN-Example.patch |
| 40 | |
| 41 | # Map patch file to commit in upstream checkout branch |
| 42 | patch=patches/00NN-Example.patch |
| 43 | subject=$(sed -n 's/^Subject: \[PATCH\] //p' "$patch" | head -n1) |
| 44 | cd upstream |
| 45 | git log --oneline pulumi/patch-checkout --grep "$subject" |
| 46 | |
| 47 | # If needed, disambiguate by touched path |
| 48 | git log --oneline pulumi/patch-checkout -- path/to/file |
| 49 | cd .. |
| 50 | ``` |
| 51 | |
| 52 | If `rg` is unavailable, use `grep -En` for the patch search. Set `target_sha` to the owning commit and edit that commit, not `HEAD`. |
| 53 | |
| 54 | ## Amend Existing Patch (Preferred, Non-Interactive) |
| 55 | |
| 56 | ```bash |
| 57 | ./scripts/upstream.sh checkout |
| 58 | cd upstream |
| 59 | |
| 60 | target_sha=<owning-commit-sha> |
| 61 | base_sha=$(git rev-parse "${target_sha}^") |
| 62 | tmp_branch="rewrite-${target_sha:0:8}" |
| 63 | |
| 64 | # Rebuild history from parent of target commit |
| 65 | git checkout -b "$tmp_branch" "$base_sha" |
| 66 | git cherry-pick "$target_sha" |
| 67 | |
| 68 | # Apply fix and amend target commit |
| 69 | # ...edit files... |
| 70 | git add <files> |
| 71 | git commit --amend --no-edit |
| 72 | |
| 73 | # Replay remaining commits |
| 74 | git cherry-pick "${target_sha}..pulumi/patch-checkout" |
| 75 | |
| 76 | # If cherry-pick conflicts occur: |
| 77 | # resolve files |
| 78 | # git add <resolved files> |
| 79 | # git cherry-pick --continue |
| 80 | |
| 81 | # Move checkout branch to rewritten history |
| 82 | git branch -f pulumi/patch-checkout HEAD |
| 83 | git checkout pulumi/patch-checkout |
| 84 | git branch -D "$tmp_branch" |
| 85 | cd .. |
| 86 | ``` |
| 87 | |
| 88 | Interactive fallback: |
| 89 | |
| 90 | ```bash |
| 91 | ./scripts/upstream.sh checkout |
| 92 | ./scripts/upstream.sh rebase -i |
| 93 | # mark target commit as edit, amend, then continue |
| 94 | ``` |
| 95 | |
| 96 | ## Remove Entire Patch |
| 97 | |
| 98 | Use when a patch should be deleted completely. |
| 99 | |
| 100 | ```bash |
| 101 | rm patches/00NN-Description.patch |
| 102 | ./scripts/upstream.sh checkout |
| 103 | ./scripts/upstream.sh check_in |
| 104 | ``` |
| 105 | |
| 106 | ## Remove Part of a Patch |
| 107 | |
| 108 | Use when only selected hunks/files should be removed from an existing patch. |
| 109 | |
| 110 | 1. Find owning patch/commit (`target_sha`) and use the amend workflow above. |
| 111 | 2. Revert only unwanted changes from the target commit, then amend. |
| 112 | |
| 113 | Example during amend step: |
| 114 | |
| 115 | ```bash |
| 116 | cd upstream |
| 117 | # Restore specific docs-only files from parent of amended commit |
| 118 | git checkout HEAD^ -- path/to/docs-only-file path/to/another-doc-file |
| 119 | git add path/to/docs-only-file path/to/another-doc-file |
| 120 | git commit --amend --no-edit |
| 121 | cd .. |
| 122 | ``` |
| 123 | |
| 124 | ## Create New Patch (Only If Requested) |
| 125 | |
| 126 | ```bash |
| 127 | ./scripts/upstream.sh checkout |
| 128 | cd upstream |
| 129 | # ...make changes... |
| 130 | git add <files> |
| 131 | git commit -m "Describe new patch" |
| 132 | cd .. |
| 133 | ./scripts/upstream.sh check_in |
| 134 | ``` |
| 135 | |
| 136 | ## Rebasing Patches to a New Upstream Version |
| 137 | |
| 138 | ```bash |
| 139 | ./scripts/upstream.sh checkout |
| 140 | |
| 141 | # Rebase onto the new upstream commit |
| 142 | ./scripts/upstream.sh rebase -o <new_commit_sha> |
| 143 | # Resolve any conflicts that arise |
| 144 | |
| 145 | # Write updated patch files |
| 146 | ./scripts/upstream.sh check_in |
| 147 | ``` |
| 148 | |
| 149 | ## Verification Checklist |
| 150 | |
| 151 | Before `check_in`: |
| 152 | |
| 153 | - Confirm expected patch count change (`0` by default; `-1` for full patch removal). |
| 154 | - Confirm whether target patch should remain present (default yes) or be removed (explicit deletion case). |
| 155 | - Confirm you are editing the owning commit, not adding a new commit by accident. |
| 156 | |
| 157 | After `check_in`: |
| 158 | |
| 159 | - Verify patch count matches expectation. |
| 160 | - Verify ta |