Stripping Vendor VCS Data While Using Glide

Many developers want to use Glide with Go and store external packages in their version control system in the vendor/ directory. Glide handles updates when the version control system data is present or absent. But, it doesn't strip VCS data from repos. In a first step, of several that are coming, to improve support for vendoring we have a new tool that strips VCS data.

Why A New Tool?

When considering where to land this feature a few things came up:

  1. There a numerous use cases for stripping VCS data. From vendoring external packages to cloning a repo, building a website, stripping VCS data, and deploying. There are more use cases of a tool like this than just vendoring.
  2. We're a fan of the Unix Philosophy of "combining 'small, sharp tools' to accomplish larger tasks". Since this tool has multiple purposes and can be used alongside multiple vendor management tools it makes sense to release it separately.
  3. There are a lot of features, not part of the core of package management, that people have asked for in Glide. If we add them all there it will quickly become bloatware with lots of flags. We don't want that.

With that in mind, we have a new tool called rmvcsdir.

How It Works

Glide will update vendored packages, checked into a parents project version control, when the --update-vendored flag is passed in. But, how do you strip the VCS data in the first place? Especially in a cross platform manner. Or, how do new packages of packages that may be pulled down get the VCS data stripped?

You could write a shell script that would do it. But, how does that work cross platform (Go supports POSIX and Windows after all)?

First, install rmvcsdir (e.g. go get -u github.com/Masterminds/rmvcsdir).

rmvcsdir takes a list of one or more directories to strip the VCS data from. It recurses through the directory tree deleting VCS directories. For example, run rmvcsdir from the root of a Go project:

$ rmvcsdir vendor
Deleting: /Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/semver/.git
Deleting: /Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs/.git
Deleting: /Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/codegangsta/cli/.git
Deleting: /Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/gopkg.in/yaml.v2/.git

Because this is a destructive operation there is a -dryrun flag that will tell you what would be deleted without performing the delete operation. Sometimes it's reassuring to see it without doing it.

Next, pair it with Glide. For example,

$ glide up --update-vendored && rmvcsdir vendor

This will update the dependencies, generate a glide.lock file, and make sure any VCS data is stripped from packages pulled down.

Making It Easier

This is just the first step is making the situation better for vendoring. We have some other plans that will be coming in more utilities and core features of Glide.