MWT EDITS
gost is like a vendoring go get
that uses Git subtrees. It is useful for
producing repeatable builds and for making coordinated changes across multiple
Go packages hosted on GitHub.
When you gost get
, any packages that are hosted on GitHub will be sucked in as
subrepositories and any other packages will be included in source form.
Unlike most vendoring mechanisms, gost is not meant to be used within a subfolder of an existing repo. Rather, to use gost, set up a new project (which we call a "gost repo") in order to do your vendoring in there.
A gost repo is a self-contained, versioned Go workspace, with its own src, pkg and bin folders. In fact, you can think of gost as nothing more than a way of versioning Go workspaces.
Let's say that we want to make a change to github.com/getlantern/flashlight that requires changes to various libraries in github.com/getlantern that are used by flashlight.
go get github.com/getlantern/gost
Do this outside of your existing Go workspace(s).
mkdir flashlight-build
cd flashlight-build
gost init
gost init creates a setenv.bash that sets your GOPATH and PATH to point at your gost repo.
source ./setenv.bash
gost get github.com/getlantern/flashlight master
Note that you always have to specify the branch from which you're getting code.
At this point, we have a gost repo that incorporates flashlight and all of its dependencies (including test dependencies). We may want to go ahead and push upstream now.
git remote add origin https://github.com/getlantern/flashlight-build.git
git push -u origin master
git checkout -b mybranch master
Now we make our changes.
Let's say that there's an existing package on GitHub that we need to add to our
GOPATH in order to make this change. We can just gost get
it.
gost get github.com/getlantern/newneededpackage master
If updates have been made upstream, we can pull these in using gost get -u
.
It works just like go get -u
and updates the target package and dependencies.
gost get -u github.com/getlantern/flashlight
If you want to update only the named package and leave depedencies as-is, use
the up
flag.
gost get -up github.com/getlantern/flashlight
git push --set-upstream origin mybranch
At this point, we can submit a pull request on GitHub, which will show all changes to all projects in our gost repo (i.e. our GOPATH). Once the PR has been merged to master, we can pull using git as usual.
git checkout master
git pull
gost push -u github.com/getlantern/flashlight master
Unlike gost get
which fetches dependencies, gost push
only pushes the
specific package indicated in the command.
Note again that you have to specify the branch to which you want to push.
The -u
flag tells gost to first pull from upstream before pushing. You can
omit it if you don't want to do this, but if you have upstream changes that
aren't in your local repo, the push will fail.
You can also push to multiple repos in one step. For example, to push all packages in github.com/getlantern:
gost push github.com/getlantern master