|
| 1 | +# gsv |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +* [Introduction](#introduction) |
| 6 | +* [Dependencies](#dependencies) |
| 7 | +* [Installation](#installation) |
| 8 | +* [Usage](#usage) |
| 9 | +* [FAQ](#faq) |
| 10 | +* [TODO](#todo) |
| 11 | +* [Credits](#credits) |
| 12 | + |
| 13 | +## Introduction |
| 14 | + |
| 15 | +gsv is the **G**o **S**ubmodule **V**endoring tool. It does native |
| 16 | +Go vendoring using Git submodules. This approach makes configuration |
| 17 | +files redundant and doesn't require additional tooling to build a |
| 18 | +gsv-vendored Go project because Git (which you have installed anyway) |
| 19 | +is used to track the revisions of your vendored dependencies. |
| 20 | + |
| 21 | +Therefore, in order to fetch and install a Go package that has used |
| 22 | +`gsv` to vendor its dependencies a simple |
| 23 | + |
| 24 | +```sh |
| 25 | +go get $PACKAGE_URL |
| 26 | +``` |
| 27 | + |
| 28 | +will do the job. Go 1.5.X needs some additional steps (see FAQ). |
| 29 | + |
| 30 | +Compared to a copy-based vendoring approach gsv preserves the dependencies' |
| 31 | +histories and links them to the main project's history which facilitates |
| 32 | +the usage of the Git tool suite. Therefore, it's possible to go through |
| 33 | +each dependency's `git log` and analyze what changes have been done since |
| 34 | +the last update. Also, `git bisect` can be used to find a commit in a |
| 35 | +dependency's repository that for example caused the main project to break. |
| 36 | +And so on. |
| 37 | + |
| 38 | +## Dependencies |
| 39 | + |
| 40 | +[libgit2](https://github.com/libgit2/libgit2) needs to be installed. |
| 41 | +Packages exist for |
| 42 | + |
| 43 | +* [Ubuntu](http://packages.ubuntu.com/source/wily/libgit2) |
| 44 | +* [Fedora](https://admin.fedoraproject.org/pkgdb/package/rpms/libgit2/) |
| 45 | +* [Arch Linux](https://www.archlinux.org/packages/extra/x86_64/libgit2/) |
| 46 | +* [Homebrew](https://github.com/Homebrew/homebrew/blob/master/Library/Formula/libgit2.rb) |
| 47 | + |
| 48 | +If your distro does not package it then you need to install it from |
| 49 | +[source](https://github.com/libgit2/libgit2#building-libgit2---using-cmake). |
| 50 | + |
| 51 | +## Installation |
| 52 | + |
| 53 | +After installing the [dependencies](#dependencies) execute |
| 54 | + |
| 55 | +```sh |
| 56 | +go get github.com/toxeus/gsv |
| 57 | +``` |
| 58 | + |
| 59 | +and make sure that `$GOPATH/bin` is in your `$PATH`. |
| 60 | + |
| 61 | +## Usage |
| 62 | + |
| 63 | +Let's assume we want to vendor `go-etcd` and its recursive dependencies |
| 64 | +in our project |
| 65 | + |
| 66 | +```sh |
| 67 | +cd $GOPATH/$OUR_PROJECT |
| 68 | +gsv github.com/coreos/go-etcd/etcd |
| 69 | +git commit -m "vendor: added go-etcd and its dependencies" |
| 70 | +``` |
| 71 | + |
| 72 | +Done. |
| 73 | + |
| 74 | +## FAQ |
| 75 | + |
| 76 | +### I have a problem. What next? |
| 77 | + |
| 78 | +Please open an [issue](https://github.com/toxeus/gsv/issues/new) |
| 79 | +and try to give reproducible examples ;) |
| 80 | + |
| 81 | +### I want to contribute. What next? |
| 82 | + |
| 83 | +If you want to contribute a bigger change then |
| 84 | +please open an [issue](https://github.com/toxeus/gsv/issues/new) |
| 85 | +such that we can discuss what the best way is to proceed. |
| 86 | + |
| 87 | +If you want to fix something minor then feel free to open |
| 88 | +a pull request straightaway. |
| 89 | + |
| 90 | +### How do I update all my dependencies? |
| 91 | + |
| 92 | +As of now using |
| 93 | + |
| 94 | +```sh |
| 95 | +git submodule foreach 'git fetch && git rebase master@{u}' |
| 96 | +``` |
| 97 | + |
| 98 | +will do the trick. Some day it'll be integrated into `gsv`. |
| 99 | + |
| 100 | +### Do you know about git2go? |
| 101 | + |
| 102 | +Yes! Last time I checked the support for submodules in |
| 103 | +[`git2go`](https://github.com/libgit2/git2go) was not sufficient |
| 104 | +for this project's requirements. That's why the Git code |
| 105 | +ended up being written in Cgo. |
| 106 | + |
| 107 | +### How do I get and build a gsv project using Go 1.5? |
| 108 | + |
| 109 | +Like this |
| 110 | + |
| 111 | +```sh |
| 112 | +export GO15VENDOREXPERIMENT=1 |
| 113 | +go get -d $PROJECT_URL |
| 114 | +cd $GOPATH/$PROJECT_PATH |
| 115 | +git submodule update --init |
| 116 | +go install ./... |
| 117 | +``` |
| 118 | + |
| 119 | +### How do I build gsv using Go 1.5? |
| 120 | + |
| 121 | +See [here](#how-do-i-get-and-build-a-gsv-project-using-go-15) |
| 122 | + |
| 123 | +### `go build ./...` or `go test ./...` fails |
| 124 | + |
| 125 | +`gsv` only vendors dependencies which are needed to |
| 126 | +satisfy the building and testing of **your** project. |
| 127 | +Dependencies that are needed to build and test |
| 128 | +the vendored dependencies are **not** pulled in. |
| 129 | + |
| 130 | +As a consequence `go build ./...` and/or `go test ./...` |
| 131 | +*might* break when run from the project's *root folder*. |
| 132 | +To fix this the following commands should be used |
| 133 | + |
| 134 | +```sh |
| 135 | +go build $(go list ./... | grep -v vendor) |
| 136 | +go test $(go list ./... | grep -v vendor) |
| 137 | +``` |
| 138 | + |
| 139 | +This is not a joke but the |
| 140 | +[official recommendation](https://github.com/golang/go/issues/11659#issuecomment-171678025) |
| 141 | +by the golang team. |
| 142 | + |
| 143 | +Note that pulling in the build- and test-dependencies of your |
| 144 | +dependencies is unlikely to fix `go build ./...` and `go test ./...` |
| 145 | +because the pulled in packages will then have unsatisfied |
| 146 | +dependencies. And going all the way down in the recursion doesn't |
| 147 | +seem to be the right solution for managing your build- and |
| 148 | +test-dependencies. |
| 149 | + |
| 150 | +## TODO |
| 151 | + |
| 152 | +In order of priority. Might not be implemented exactly as |
| 153 | +suggested here. |
| 154 | + |
| 155 | +1. Add a `-purge` flag such that unused vendored submodules will |
| 156 | + be detected and removed. |
| 157 | +1. Use code from Go's stdlib instead from gb-vendor |
| 158 | +1. Add a `-updateall` flag such that all dependencies are |
| 159 | + updated to their current `origin/master`. |
| 160 | +1. Take a look at `git2go` and see if there is progress in |
| 161 | + submodules support. |
| 162 | +1. Look for alternatives for `libgit2`. This dependency reduces |
| 163 | + portability and makes installation a bit harder. |
| 164 | + |
| 165 | +## Credits |
| 166 | + |
| 167 | +This project could bootstrap on the work done for |
| 168 | +[gb-vendor](https://github.com/constabulary/gb/tree/master/cmd/gb-vendor). |
0 commit comments