These notes apply to all VCS, even if Git is used frequently. (FIXME)
I'm beginning to suspect that this is a fundamental pattern that is not known enough by most developers.
See, for example,
It should be made part of every VCS, even if several other VCS do mention it:
git subtree is a first attempt in that directionA VCS should provide support to import sibling as well as alien repository artifacts (entire directories as well as single files).
This is not the same as the initial import/conversion procedures that various VCS offer.
When working with vendor branches, you will need to choose a tag to define the vendor versions.
v1.0, start off itvendor/[<vendor name>/]<vendor project name>/<vendor tag>.If the remote imports your project with git subtree --no-squash, you can add that project as a remote that will fuse with your tree. I didn't go deeper, but it might become confusing when you start pushing their tags and branches to your public repo. But it is possible.
An issue that will then appear is that git tags will get mixed.
Therefore, I recommend to prefix (group) your own tags with e.g. your product name:
git tag <your project>/v/<SEMVER...> <branch>
This will separate your tags from imported tags. In fact you should always use a separate group for your project tags, in case someone else imports your tags.
In at least one VCS client (Sourcetree), the slashes are use to build a nice tree.
Also, I'm not sure future implementations of Git will off that same nice tree that you can find under .git/refs/heads, .git/refs/remotes, ... (look in .git/packed-refs for the tag hierarchy).
Suggested vendor branch naming:
vendor/[<vendor name>/]<vendor project>/source
The "vendor/" prefixes are meant to draw the attention to the use of vendor branching and will also help in organise and deconflict refnames.
The /source suffix allows to also add conttributions branches (see next paragraph).
If there are chances that your branches end up in other repos, consider prefixing with your project name (see tags above).
A similar approach could be used for the vendor directory, but is not essential.
As similar naming schema is recommended when you import several remotes.
Suggested vendor contribution branch naming:
vendor/[<vendor name>/]<vendor project>/contrib/<contribution name>
VENDOR.md file to the merged vendor directory that contains relevant metadata
git subtree!) that can easily be pasted in a terminal to update the vendor.Some artefacts are not available as text but in binary formats. Examples:
Remember to also include the documentation:
This needs to be further worked out: how to ingest HTML? As txt? Full HTML can often be ok?
Other example: XML schema Sometimes a format is accompanied by a metadata section describing the format of the data. This metadata is an important artefact to commit to an vendor branch. Changes to the schema will be readily identified as diffs in the vendor branch. That's why such files must be ingested too.
Sometimes, conversion routines need to be written or updated so that external data fits the project; maybe the data oitself is not needed, but only the generated data? These routines do not belong in the vendor branch, but in your project.
If your patch adds/changes binary files, then supply those separately.
TO CONFIRM: edit the patch file, remove the references to binaries(?), and mention this to the vendor.
In some circumstances you want to also contribute to the vendor's project.
If the vendor uses a Git repo that you can access, create a pull request and skip the remainder of this section on patching.
Otherwise you need to send a patch, because your vendor directory contains totally different SHA-1 commits (that you created during the vendor drop), so the vendor's Git won't know how to apply your PR/patch.
There are a few ways to handle this situation.
git diff)If your changes don't contain binary files, run a diff and send that to the vendor. Remember to generate a diff relative to the vendor directory.
git diff --relative=<vendor path> <branch base>..<branch head>
It might be good to review the generated text file, you never know... For example, to detect if the patch did touch binary files.
The vendor will apply your patch (probably via a branch) using the classical patch program
patch -p1 < patchfile
Sometimes git bundle can be helpful.
If your patch adds/changes binary files, then supply those separately.
TO CONFIRM: edit the patch file, remove the references to binaries(?), and mention this to the vendor.
git archive)The easiest way (also to avoid the binaries issue) is to send an entire archive of the vendor directory of your branch. The vendor will then ingest that in a branch (actually they are doing a kind of vendor drop...) and run their diff/merge/etc.
git archive --format=tgz --output=<tarfile>.tgz <head>:<path to vendor directory> [path]
This creates a tgz file (run git archive --list for the formats) of the commit <head> relative to the vendor directory dirname.
Note that this even works for a single vendor file, should you have chosen not to use a directory for the vendor artefact.
Sometimes, it might be preferrable to convert a Git repo to a git archive in order to perform the vendor drop.
Explain?
Sometimes, artefacts are not available as ready to ingest source code. E.g. a paper can explain an algorithm, contain (symbolic) code, etc.
Such artefacts cannot magically be turned into source code.
The idea is to store the original artefact (PDF, binary file, ...) in a separate folder in the vendor directory, then painfully (yes...) extract the code into another separate folder. (And/or maybe ask the author to provide a git repo, a file, archive, ...)
If there is no tarball to explode, do not empty the vendor directory, but manually update what changed. Often this can be accomplished via scripts. (??)
And then only merge to main/master/... where you applied your changes.
Example with two vendors:
.
├── src/
└── vendors/
├── .../
├── rejig/
│ ├── rejig/
│ └── VENDOR.txt
└── TK-paper/
├── original/
│ └── paper.pdf
├── rewritten/
│ └── paper.txt
└── VENDOR.txt
If the artifact is not usable without extensive rewriting (e.g. Fortran code in a C++ project), it might still make sense to vendor the original file; it will serve as an excellent reference.
This also applies for cases where explanatory/example (pseudo) sourcecode is offered; this code is essential documentation that the vendor might update occasionally.
In such a case, there is no need to rewrite the artefacts (see previous item).
Sometimes, packages deflate to directories/files with path names containing version information. An example is the FAQ file of this landscape.
This is a bad practice, sometimes done by developers that do not have access to a good VCS. (Note also the CR/LF issue in that example.)
In such cases, the version information should be removed before committing the vendor drop so that the history of changes can be tracked. This is a delicate step, as the "pristine copy" requirement is no longer fulfilled. If filename information is part of the correct functioning of the imported artifacts (e.g. it is also referenced in vendor scripts, in linked data, etc), then you are facing a difficult problem. In such a case (for now), it might be better to not rename the vendor file paths at all and accept that file history must be discovered by other means (e.g. a manual diff). TODO find a better way here. Note that Git might be able to find out what changed in renamed files.
When modifying vendor code, stick to the vendor coding style/conventions. Rewriting for readbility etc. will likely lead to massive conflicts at the next vendor drop.
an interesting question to deal with: how to deal with major/minor vendor or maintenance releases (eg the chronological sequence is v1 - v2 - v3 - and then v1.1 - v4 - v2.1 - ...). Probably to use "vendor sub branches"!
git subtree merging (which is not the same as the git subtree command), applies to vendors using Git only ("sibling vendors").
how to convert existing (modified or not) code to a vendor branch`
a rebasing vendor branch workflow
how to deal with huge repos,
remember to check whether the license may or may not allow vendor branching
https://blog.palantir.com/renaming-and-deep-directory-hierarchies-in-git-f8e96d5e39a9