| Artifact ID: | 9da506b65cadf13ba5043f532a95d5b4ca005b9970de6adf4d97053e9308eba6 |
|---|---|
| Page Name: | Vendor branches |
| Date: | 2026-11-26 04:33:08 |
| Original User: | dmestas |
| Mimetype: | text/x-markdown |
| Next | c51ef2c4d9c62fa81fab54db5a64779f30c12af85adab5407519bd81b0d6ed1b |
Vendor branches
The problem. Your project (A) needs someone else's code (B). You copy B into your tree, and then two things happen: you change a few lines of B for your own needs, and B keeps putting out new releases. Copying each new release over your copy throws your changes away.
The fix. Keep B's releases, exactly as shipped, on a branch of their own, and merge that branch into your project. Fossil then works out what changed upstream since the last release you took, and merges only that into your copy, so your own changes stay.
This repository does exactly that. Its trunk is project A, notes, a small tool
that prints text wrapped to a width. The vendor-wrap branch holds B, a tiny
library called wrap, through three releases.
See it all at once on the timeline.
Where the vendor branch starts
The vendor branch starts from the repository's first check-in, the
"initial empty check-in" that fossil new makes. It has no
files, so the vendor branch carries none of A's files, only B. But trunk
descends from it, so the two branches share an ancestor and merge normally.
A truly separate root (made with fossil open --empty and a first commit)
doesn't work for this: fossil merge refuses it with "cannot find a common
ancestor". Branching from your latest code does work, but it puts all of A's
files on the vendor branch too.
The history, step by step
| Step | Branch | Check-in | What happens |
|---|---|---|---|
| 1 | trunk | cd2c8ca84b | Project A starts, with no wrap library yet. |
| 2 | vendor-wrap | ab245b7902 | wrap 1.0 is imported into vendor/wrap/, exactly as upstream ships it. |
| 3 | trunk | e8cd137bb0 | Merging vendor-wrap adds wrap 1.0 to A. |
| 4 | trunk | 5781ae8096 | A starts using wrap. |
| 5 | trunk | b9eed52216 | A patches its copy of wrap to break lines at tabs too. Upstream doesn't have this. |
| 6 | vendor-wrap | 6e37e4e613 | wrap 1.1: upstream fixes an off-by-one, adds wrap_test.c and removes legacy.c. |
| 7 | trunk | c977a16fd1 | Merging 1.1: the fix comes in, wrap_test.c is added, legacy.c is deleted, and A's tab patch stays. |
| 8 | vendor-wrap | b6163fde93 | wrap 2.0: upstream renames wrap.c to textwrap.c. |
| 9 | trunk | e305905700 | Merging 2.0: the rename comes in, A's tab patch moves with the file, and A's Makefile is updated for the new name. |
What the merges in steps 7 and 9 printed:
fossil merge vendor-wrap (wrap 1.1)
UPDATE vendor/wrap/README.md
UPDATE vendor/wrap/wrap.h
MERGE vendor/wrap/wrap.c
DELETE vendor/wrap/legacy.c
ADDED vendor/wrap/wrap_test.c
fossil merge vendor-wrap (wrap 2.0)
UPDATE vendor/wrap/README.md
UPDATE vendor/wrap/wrap.h
MERGE vendor/wrap/wrap.c
RENAME vendor/wrap/wrap.c -> vendor/wrap/textwrap.c
Doing it yourself
Once, to set up. Use a second folder for the vendor branch, so your project's checkout is never emptied:
mkdir ../vendor && cd ../vendor
fossil open ../project.fossil start:trunk
# copy B's release into vendor/b/
fossil addremove
fossil commit --branch vendor-b -m "Import B 1.0 exactly as upstream ships it."
cd ../project
fossil merge vendor-b
fossil commit -m "Merge B 1.0 from vendor-b."
start:trunk names the first check-in on trunk. Fossil versions before 2.19
don't know that name: use the hash of the "initial empty check-in" from the
bottom of the timeline instead.
For each new release of B:
cd ../vendor
fossil update vendor-b
rm -rf vendor/b && mkdir vendor/b
# copy the new release into vendor/b/
fossil addremove
fossil commit -m "Import B 1.1 exactly as upstream ships it."
cd ../project
fossil merge vendor-b
# build and test, then:
fossil commit -m "Merge B 1.1 from vendor-b."
If a release renames a file, record it with fossil mv OLD NEW before
addremove, as step 8 does, and the merge carries your
changes to the new name. Without fossil mv, Fossil sees a deleted file and a
new one, and your changes to it don't follow.
Seeing your own changes to B
The vendor branch always holds B exactly as upstream shipped it, so comparing it with trunk shows exactly what your project has changed in B and nothing else:
fossil diff --from vendor-b --to trunk vendor/b
Here, that's the one-line tab patch:
- the diff between vendor-wrap and trunk
- who changed what in textwrap.c
- textwrap.c's history, through the rename
If B is already pasted into your project
If A already has a copy of B, perhaps with changes, the first merge from the vendor branch conflicts, because both branches added the same files. Resolve it once by keeping A's version of each file, then commit:
fossil merge vendor-b
fossil cat vendor/b/FILE -r trunk > vendor/b/FILE # for each conflicting file
fossil commit -m "Merge B from vendor-b, keeping our copy."
After that, each new release merges as above. (This repository's history doesn't show this case. It was tested separately.)
When not to use it
- If you never change B, a plain copy is simpler: replace the folder with each new release.
- If your changes to B could go upstream, send them there, and you won't have to carry them at all.
- If your changes are large, or B moves files around a lot, three-way merges struggle. Dan Shearer's Not-forking is built for that case.