« Building Code at Logos: Repository Layout | Main | Building Code at Logos: Sharing Code Across Projects »

16 November 2012

Building Code at Logos: Third-Party Repositories

Some of our repositories reference third-party code. In many cases, this can be managed using NuGet, but sometimes we need to make private modifications and build from source.

We accomplish this by creating a repository for the third-party code. In some cases, this repository is added as a submodule under ext in the repositories that need it; in other cases, the binaries created from the code are committed to another repository's lib folder. The decision depends on how complicated it is to build the code versus how useful it is for developers to have the source (and not just precompiled binaries).

In the third-party repository, the upstream branch contains the unmodified upstream code, while the master branch contains the Logos-specific modifications.

When cloning the repository locally, the origin remote refers to our repository containing the third-party code. If the original third-party code is available via git, then we add an upstream remote that references the original maintainer's code.

Example: Creating a ThirdParty repo from source on GitHub

# clone a local copy of the remote third-party repository
git clone https://github.com/user/ExampleProject.git
cd ExampleProject

# rename the "origin" remote (created by clone) to "upstream"
git remote rename origin upstream

# add Logos' repo as the "origin" remote
git remote add origin git@git:ThirdParty/ExampleProject.git

# use this code as the "upstream" branch
git checkout -b upstream
git push origin upstream

# work on Logos-specific modifications
git checkout master

** make modifications

git commit -am "Some important changes."

# push the changes to our repo
git push origin master

Example: Creating a ThirdParty repo from source in Subversion

# create the git repo
mkdir ExampleProject
cd ExampleProject
git init

# add Logos' repo as the "origin" remote
git remote add origin git@git:ThirdParty/ExampleProject.git

# seed it with the upstream code
svn export --force http://source.example.org/repos/example/tags/1.0 .

# add all the code
git add -A
git commit -m "Add Example 1.0"

# use this code as the "upstream" branch
git checkout -b upstream
git push origin upstream

# work on Logos-specific modifications
git checkout master

** make modifications

git commit -am "Some important changes."

# push the changes to our repo
git push origin master

Once the repository is created, we will want to update it with new versions of the third-party code when they are released (then merge in our changes).

The new code gets committed to the upstream branch, then that gets merged into master. If necessary, conflicts are resolved, or our changes are edited/removed to reflect changes in the upstream code.

Example: Updating a ThirdParty repository from source on GitHub

# switch to the "upstream" branch, which contains the latest external code
git checkout upstream

# get the latest code from the "master" branch in the "upstream" repo
git pull upstream master

# switch to our local "master" branch, which contains Logos changes
git checkout master

# merge in the latest upstream code
git merge upstream

** fix any conflicts, and commit if necessary

# push the latest merged code to our repo
git push origin master

Example: Updating a ThirdParty repository from source in Subversion

# switch to the "upstream" branch, which contains the latest external code
git checkout upstream

** delete all files in the working copy, except the '.git' directory

# get the latest version of the third-party code
svn export --force http://source.example.org/repos/example/tags/1.1 .

# add all files in the working copy, then commit them
git add -A
git commit -m "Update to Example 1.1."

# switch to our local "master" branch, which contains Logos changes
git checkout master

# merge in the latest upstream code
git merge upstream

** fix any conflicts, and commit if necessary

# push the latest merged code to our repo
git push origin master

Posts in the “Building Code at Logos” series:

Posted by Bradley Grainger at November 16, 2012 09:50 AM