Skip to content

Commit 9bfc4aa

Browse files
Merge pull request #88 from stellarwp/64-absorb-history-doc
Keep the standalone's git history when its files are absorbed
2 parents 6a85394 + 8465e72 commit 9bfc4aa

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎cspell.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"fataled",
1919
"fataling",
2020
"fatals",
21+
"givewp",
2122
"invokable",
2223
"kadence",
2324
"kses",

‎docs/configuration.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,86 @@ load pass first; a site created afterwards never gets it. Per-site work is yours
105105
a later site yours to catch on `wp_initialize_site`: see
106106
[Do per-site work on multisite](recipes.md#do-per-site-work-on-multisite).
107107

108+
## Bringing the standalone's git history with it
109+
110+
Copying the standalone's files into your repository loses its git history. The commit messages, the
111+
blame, and with them the reason any given line is written the way it is, all stay behind in the old
112+
repository — so a developer or an agent working on the bundled copy later has nothing to go on, and
113+
`git blame` answers every question with the single commit that copied the files in.
114+
115+
A submodule would keep that history, but it is the wrong shape here: a bundled copy usually needs
116+
small host-only edits that have no business in the standalone's repository, which is normally
117+
archived soon afterwards anyway.
118+
119+
Merge the standalone in as an unrelated history instead, nesting its whole tree under the sub-plugin
120+
directory first so that the two share no path and the merge has nothing to conflict over:
121+
122+
```bash
123+
# On a branch of the host plugin's repo.
124+
git switch -c absorb-give-recurring
125+
126+
# Pull the standalone's commits in as a second, unrelated history.
127+
git remote add old-repo git@github.com:givewp/give-recurring.git
128+
git fetch --no-tags old-repo
129+
130+
# Nest every top-level entry it tracks, in a scratch worktree so that this checkout
131+
# is never switched away from.
132+
git worktree add -b old-repo-import ../absorb-worktree old-repo/main
133+
cd ../absorb-worktree
134+
mkdir __absorb-import
135+
git ls-tree --name-only -z HEAD | xargs -0 -I{} git mv {} __absorb-import/
136+
mkdir -p sub-plugins
137+
git mv __absorb-import sub-plugins/give-recurring
138+
git commit -m "Move Give Recurring under sub-plugins/give-recurring"
139+
cd -
140+
141+
# Nothing overlaps now, so this merge has nothing to conflict over.
142+
git merge --allow-unrelated-histories old-repo-import
143+
144+
# The history is part of your branch now; the rest can be deleted.
145+
git worktree remove ../absorb-worktree
146+
git remote remove old-repo
147+
git branch -d old-repo-import
148+
```
149+
150+
**Move everything, so the merge only ever touches the sub-plugin directory.** The standalone's
151+
`README.md`, `LICENSE` and `.gitignore` sit at *its* top level: leave them there and they merge into
152+
*your* repository root, conflicting with the files of the same name and adding the ones with no
153+
counterpart. `git ls-tree` moves whatever the standalone tracks, which a hand-written list of paths
154+
will not.
155+
156+
**The staging directory keeps the destination out of the tree being moved.** That move runs against
157+
the standalone's own checkout, so a destination like `includes/notifications` lands under an
158+
`includes/` the standalone tracks itself, and git will not move a directory into itself. Only that
159+
one entry fails while every other one succeeds, so the error scrolls past in a screen of moves that
160+
worked. Setting the whole tree aside under a name nothing uses, then renaming it into place once,
161+
does not care where the destination sits.
162+
163+
**The scratch worktree is what stops this deleting your build output.** Checking the standalone's
164+
tree out over your own means git writing a tree that knows nothing about your repository, and git
165+
does not protect ignored files: one that collides is overwritten in place, and switching back then
166+
removes any directory left holding nothing but ignored files. A `dist/` or `assets/` the standalone
167+
also tracks takes your untracked build artifacts with it, silently, and a `.gitignore`d database dump
168+
under one goes the same way. A worktree is a second checkout of the same repository in another
169+
directory, so the branch work happens there and yours is only ever merged into.
170+
171+
**`--no-tags`.** A plain fetch also takes any tag reachable from what it downloads. The standalone's
172+
`1.1.0` then sits among your own releases, while a `1.0.0` you already have silently does not import
173+
at all, since git will not move an existing tag.
174+
175+
**The move commit moves and nothing else.** `git mv` alone leaves every blob identical, so rename
176+
detection ties each file to its past. Rewrite a file in that same commit and it drops below the
177+
similarity threshold, taking its history with it — blame stops at the move. Host-only edits belong in
178+
commits after the merge.
179+
180+
**Merge the PR with a merge commit.** Squash flattens the imported commits into one and rebase
181+
replays them onto your trunk; either discards what this was for.
182+
183+
Afterwards `git blame` and `git log --follow` cross the move with no extra flags, attributing each
184+
line to the author who wrote it in the standalone. Path-filtered
185+
`git log -- sub-plugins/give-recurring` is the exception and stops at the move, since that is where
186+
the directory begins.
187+
108188
## What changes for the bundled plugin
109189

110190
This library includes bundled plugins from inside a method, not at global scope, so variables

0 commit comments

Comments
 (0)