vendor-branching

Vendor Branching using Git

The following sequence is almost identical for creating as well as updating a vendor.

. switch to vendor branch

git switch [--orphan=]<vendor branch> 
# if you used the orphan option tro create the branch, you will notice that at this point your project directory is now empty

# only for the first commit
git commit --allow-empty -m "create vendor XXX"

.. "sibling" vendor drop (vendor exposes Git repo)

git subtree add (when creating) / pull (when updating) --prefix=<path to vendor dir> <vendor URL> <vendor Git ref>

Note that git subtree does not remember the vendor information, so that must be recorded in the upcoming VENDOR file. Also, '.' cannot be used as prefix. Note about git subtree --squash:

.. "alien" vendor drop (vendor does not expose Git repo)

cd <vendor dir>
git ls-files -z | xargs -0 rm -f

tar -xzf vendor.tgz
git add -A

. commit & tag the vendor branch

# only if you didn't use `git subtree`:
git commit -m "import vendor XXX version YYY"

# tag
git tag <vendor tag> <vendor branch>

. switch to task branch

git switch taskbranch

. merge vendor branch

This is where merging can become ugly.

git merge --allow-unrelated-histories --no-ff <vendor tag>

--allow-unrelated-histories otherwise first vendor merge won't work. Use the vendor tag. It makes the vendor drop explicit.

Notice how the log shows how the orphan branch rejoined the main branch. This can best be seen in the network page of the GitLab fork.

. update VENDOR file

edit VENDOR.md

Remember to mention at the very least the vendor URL

Often, a script will better suit the future developer that will have to perform a new vendor drop. You can find an actual Git example in the GitLab fork on this page.

. tweak vendor code

hack away

. merge to main branch

switch main
merge task branch

Various Git notes

What about Git submodules?

Disclaimer: Personally I have never used them, and the Internet is not recomforting. But they do deserve a study.

Submodules are a bit hairy to deal with; the concept feels heavy.

To expand further.

Dealing with trailing whitespace

Git tips (TO CONFIRM and maybe to move out of this file):

	git config --get-all --show-origin core.whitespace

	# optionally:
	git config --global core.whitespace trailing-space,-space-before-tab,indent-with-non-tab,cr-at-eol

...and platform end of line issues

TODO: replace with .gitattributes ?

	git config --get-all --show-origin core.autocrlf # empty == 'false'
	git config --get-all --show-origin core.safecrlf # empty == 'false'
	git config --get-all --show-origin core.eol # empty = 'native'
	$ git config --global core.autocrlf true
	git config --global core.autocrlf input

See also

todo


https://sfconservancy.org/GiveUpGitHub/ https://giveupgithub.org/ https://en.wikipedia.org/wiki/Embrace,_extend,_and_extinguish