Skip to content
fossil-examples Update of ”Vendor branches”
Login

Update of ”Vendor branches”

Overview

Artifact ID: 28e3caec3db0f1784a10b62fa29d1fb313d1523171cd346eb9e33c41d3596afe
Page Name:Vendor branches
Date: 2026-11-26 04:42:03
Original User: dmestas
Mimetype:text/x-markdown
Parent: c51ef2c4d9c62fa81fab54db5a64779f30c12af85adab5407519bd81b0d6ed1b (diff)
Next 06d28fb58758681f93d5a13b13a75224a2f2bd8e18a571ad45d03b46f419600c
Content

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

Upstream releases arrive on vendor-wrap exactly as shipped, and each one is merged down into trunk. From the moment A patches its copy of wrap, that change rides along trunk through every later release, including the one that renames the file.

vendor-wrap upstream, as shipped trunk project A wrap 1.0 wrap 1.1 off-by-one fix +wrap_test.c  −legacy.c wrap 2.0 wrap.c → textwrap.c empty first check-in notes starts merge 1.0 A patches wrap break at tabs merge 1.1 patch kept merge 2.0 patch follows the rename
scale = 0.9
fontscale = 1.0
thickness = 0.015
arrowht = 0.08; arrowwid = 0.06
$ink = 0x29333a; $muted = 0x53616c; $rule = 0x6b737b
$base = 0xe7eef2; $vend = 0xdde8f3; $accent = 0x9a3f08; $patch = 0xf6e2d2
$r = 0.09
$top = 1.25

# lane labels
text "vendor-wrap" italic rjust color $muted at (-0.25, $top)
text "upstream, as shipped" small rjust color $muted at (-0.25, $top - 0.17)
text "trunk" italic rjust color $muted at (-0.25, 0)
text "project A" small rjust color $muted at (-0.25, -0.17)

# check-ins
Root: circle rad $r fill none color $rule dashed at (0, 0)
Start: circle rad $r fill $base color $ink at (0.75, 0)
V10: circle rad $r fill $vend color $ink at (1.4, $top)
M10: circle rad $r fill $base color $ink at (2.05, 0)
Patch: circle rad $r*1.35 fill $patch color $accent thick at (2.85, 0)
V11: circle rad $r fill $vend color $ink at (3.6, $top)
M11: circle rad $r fill $base color $ink at (4.25, 0)
V20: circle rad $r fill $vend color $ink at (5.0, $top)
M20: circle rad $r fill $base color $ink at (5.65, 0)


# lanes
line from Root.e to Start.w color $ink
line from Start.e to M10.w color $ink
line from M10.e to Patch.w color $ink
# from the patch on, trunk carries A's change: drawn in the accent
line from Patch.e to M11.w color $accent thickness 0.04
line from M11.e to M20.w color $accent thickness 0.04
arrow from M20.e right 0.35 color $accent thickness 0.04
line from Root.n up $top - $r then right until even with V10.w then to V10.w rad 0.18 color $ink
line from V10.e to V11.w color $ink
line from V11.e to V20.w color $ink

# merges: each release flows down into trunk
arrow from V10.s to M10.n chop dashed color $muted
arrow from V11.s to M11.n chop dashed color $muted
arrow from V20.s to M20.n chop dashed color $muted

# upstream labels
text "wrap 1.0" bold at V10.n + (0, 0.17)
text "wrap 1.1" bold at V11.n + (0, 0.17)
text "off-by-one fix" small ljust color $muted at V11.s + (0.2, -0.16)
text "+wrap_test.c  −legacy.c" small ljust color $muted at V11.s + (0.27, -0.31)
text "wrap 2.0" bold at V20.n + (0, 0.17)
text "wrap.c → textwrap.c" small ljust color $muted at V20.s + (0.2, -0.16)

# trunk labels
text "empty first" small color $muted at Root.s - (0, 0.17)
text "check-in" small color $muted at Root.s - (0, 0.31)
text "notes starts" small at Start.s - (0, 0.17)
text "merge 1.0" small at M10.s - (0, 0.17)
text "A patches wrap" bold color $accent at Patch.s - (0, 0.19)
text "break at tabs" small color $accent at Patch.s - (0, 0.35)
text "merge 1.1" small at M11.s - (0, 0.17)
text "patch kept" small color $accent at M11.s - (0, 0.33)
text "merge 2.0" small at M20.s - (0, 0.17)
text "patch follows" small color $accent at M20.s - (0, 0.33)
text "the rename" small color $accent at M20.s - (0, 0.47)

Check-ins: notes starts · wrap 1.0 · merge 1.0 · A patches wrap · wrap 1.1 · merge 1.1 · wrap 2.0 · merge 2.0

What the merges of 1.1 and 2.0 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 the wrap 2.0 import 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:

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