gopkg.in/tools/godep.v63@v63.0.0-20160503185544-51f9ea00dbee/Readme.md (about)

     1  ## Godep
     2  
     3  [![Build Status](https://travis-ci.org/tools/godep.svg)](https://travis-ci.org/tools/godep)
     4  
     5  [![GoDoc](https://godoc.org/github.com/tools/godep?status.svg)](https://godoc.org/github.com/tools/godep)
     6  
     7  godep helps build packages reproducibly by fixing their dependencies.
     8  
     9  This tool assumes you are working in a standard Go workspace, as described in
    10  http://golang.org/doc/code.html. We expect godep to build on Go 1.4* or newer,
    11  but you can use it on any project that works with Go 1 or newer.
    12  
    13  ## Install
    14  
    15  ```console
    16  $ go get github.com/tools/godep
    17  ```
    18  
    19  ## How to use godep with a new project
    20  
    21  Assuming you've got everything working already, so you can build your project
    22  with `go install` and test it with `go test`, it's one command to start using:
    23  
    24  ```console
    25  $ godep save
    26  ```
    27  
    28  This will save a list of dependencies to the file `Godeps/Godeps.json` and copy
    29  their source code into `vendor/` (or `Godeps/_workspace/` when using older
    30  versions of Go). Godep does **not copy**:
    31  
    32  - files from source repositories that are not tracked in version control.
    33  - `*_test.go` files.
    34  - `testdata` directories.
    35  - files outside of the go packages.
    36  
    37  Godep does not process the imports of `.go` files with either the `ignore`
    38  or `appengine` build tags.
    39  
    40  Test files and testdata directories can be saved by adding `-t`.
    41  
    42  Read over the contents of `vendor/` and make sure it looks reasonable. Then
    43  commit the `Godeps/` and `vendor/` directories to version control.
    44  
    45  ## The deprecated `-r` flag
    46  
    47  For older versions of Go, the `-r` flag tells save to automatically rewrite
    48  package import paths. This allows your code to refer directly to the copied
    49  dependencies in `Godeps/_workspace`. So, a package C that depends on package
    50  D will actually import `C/Godeps/_workspace/src/D`. This makes C's repo
    51  self-contained and causes `go get` to build C with the right version of all
    52  dependencies.
    53  
    54  If you don't use `-r`, when using older version of Go, then in order to use the
    55  fixed dependencies and get reproducible builds, you must make sure that **every
    56  time** you run a Go-related command, you wrap it in one of these two ways:
    57  
    58  - If the command you are running is just `go`, run it as `godep go ...`, e.g.
    59    `godep go install -v ./...`
    60  - When using a different command, set your `$GOPATH` using `godep path` as
    61    described below.
    62  
    63  `-r` isn't necessary with go1.6+ and isn't allowed.
    64  
    65  
    66  ## Additional Operations
    67  
    68  ### Restore
    69  
    70  The `godep restore` command is the opposite of `godep save`. It will install the
    71  package versions specified in `Godeps/Godeps.json` to your `$GOPATH`. This
    72  modifies the state of packages in your `$GOPATH`. NOTE: `godep restore` leaves
    73  git repositories in a detached state. `go1.6`+ no longer checks out the master
    74  branch when doing a `go get`, see [here](https://github.com/golang/go/commit/42206598671a44111c8f726ad33dc7b265bdf669).
    75  
    76  ### Edit-test Cycle
    77  
    78  1. Edit code
    79  1. Run `godep go test`
    80  1. (repeat)
    81  
    82  ### Add a Dependency
    83  
    84  To add a new package foo/bar, do this:
    85  
    86  1. Run `go get foo/bar`
    87  1. Edit your code to import foo/bar.
    88  1. Run `godep save` (or `godep save ./...`).
    89  
    90  ### Update a Dependency
    91  
    92  To update a package from your `$GOPATH`, do this:
    93  
    94  1. Run `go get -u foo/bar`
    95  1. Run `godep update foo/bar`. (You can use the `...` wildcard, for example
    96  `godep update foo/...`).
    97  
    98  Before comitting the change, you'll probably want to inspect the changes to
    99  Godeps, for example with `git diff`, and make sure it looks reasonable.
   100  
   101  ## Multiple Packages
   102  
   103  If your repository has more than one package, you're probably accustomed to
   104  running commands like `go test ./...`, `go install ./...`, and `go fmt ./...`.
   105  Similarly, you should run `godep save ./...` to capture the dependencies of all
   106  packages in your application.
   107  
   108  
   109  ## File Format
   110  
   111  Godeps is a json file with the following structure:
   112  
   113  ```go
   114  type Godeps struct {
   115  	ImportPath   string
   116  	GoVersion    string   // Abridged output of 'go version'.
   117  	GodepVersion string   // Abridged output of 'godep version'
   118  	Packages     []string // Arguments to godep save, if any.
   119  	Deps         []struct {
   120  		ImportPath string
   121  		Comment    string // Description of commit, if present.
   122  		Rev        string // VCS-specific commit ID.
   123  	}
   124  }
   125  ```
   126  
   127  Example Godeps:
   128  
   129  ```json
   130  {
   131  	"ImportPath": "github.com/kr/hk",
   132  	"GoVersion": "go1.6",
   133  	"Deps": [
   134  		{
   135  			"ImportPath": "code.google.com/p/go-netrc/netrc",
   136  			"Rev": "28676070ab99"
   137  		},
   138  		{
   139  			"ImportPath": "github.com/kr/binarydist",
   140  			"Rev": "3380ade90f8b0dfa3e363fd7d7e941fa857d0d13"
   141  		}
   142  	]
   143  }
   144  ```
   145  
   146  ## Migrating to vendor/
   147  
   148  Godep supports the Go 1.5+ vendor/
   149  [experiment](https://github.com/golang/go/commit/183cc0cd41f06f83cb7a2490a499e3f9101befff)
   150  utilizing the same environment variable that the go tooling itself supports
   151  (`GO15VENDOREXPERIMENT`).
   152  
   153  godep mostly works the same way as the `go` command line tool. If you have go
   154  1.5.X and set `GO15VENDOREXPERIMENT=1` or have go1.6.X (or devel) `vendor/`
   155  is enabled. **Unless** you already have a `Godeps/_workspace`. This is a safety
   156  feature and godep warns you about this.
   157  
   158  When `vendor/` is enabled godep will write the vendored code into the top level
   159  `./vendor/` directory. A `./Godeps/Godeps.json` file is created to track
   160  the dependencies and revisions. `vendor/` is not compatible with rewrites.
   161  
   162  There is currently no automated migration between the old Godeps workspace and
   163  the vendor directory, but the following steps should work:
   164  
   165  ```term
   166  # just to be safe
   167  $ unset GO15VENDOREXPERIMENT
   168  
   169  # restore currently vendored deps to the $GOPATH
   170  $ godep restore
   171  
   172  # The next line is only needed to automatically undo rewritten imports that were
   173  # created with godep save -r.
   174  $ godep save -r=false <pkg spec>
   175  
   176  # Remove the old Godeps folder
   177  $ rm -rf Godeps
   178  
   179  # If on go1.5.X to enable `vendor/`
   180  $ export GO15VENDOREXPERIMENT=1
   181  
   182  # re-analyze deps and save to `vendor/`.
   183  $ godep save <pkg spec>
   184  
   185  # Add the changes to your VCS
   186  $ git add -A . ; git commit -am "Godep workspace -> vendor/"
   187  
   188  # You should see your Godeps/_workspace/src files "moved" to vendor/.
   189  ```
   190  
   191  ## Releasing
   192  
   193  1. Increment the version in `version.go`.
   194  1. Tag the commit with the same version number.
   195  1. Update `Changelog.md`.