gopkg.in/tools/godep.v61@v61.0.0-20160406162537-35ee059b4e6c/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 modifies the state of packages in your `$GOPATH`.
    72  
    73  ### Edit-test Cycle
    74  
    75  1. Edit code
    76  1. Run `godep go test`
    77  1. (repeat)
    78  
    79  ### Add a Dependency
    80  
    81  To add a new package foo/bar, do this:
    82  
    83  1. Run `go get foo/bar`
    84  1. Edit your code to import foo/bar.
    85  1. Run `godep save` (or `godep save ./...`).
    86  
    87  ### Update a Dependency
    88  
    89  To update a package from your `$GOPATH`, do this:
    90  
    91  1. Run `go get -u foo/bar`
    92  1. Run `godep update foo/bar`. (You can use the `...` wildcard, for example
    93  `godep update foo/...`).
    94  
    95  Before comitting the change, you'll probably want to inspect the changes to
    96  Godeps, for example with `git diff`, and make sure it looks reasonable.
    97  
    98  ## Multiple Packages
    99  
   100  If your repository has more than one package, you're probably accustomed to
   101  running commands like `go test ./...`, `go install ./...`, and `go fmt ./...`.
   102  Similarly, you should run `godep save ./...` to capture the dependencies of all
   103  packages in your application.
   104  
   105  
   106  ## File Format
   107  
   108  Godeps is a json file with the following structure:
   109  
   110  ```go
   111  type Godeps struct {
   112  	ImportPath   string
   113  	GoVersion    string   // Abridged output of 'go version'.
   114  	GodepVersion string   // Abridged output of 'godep version'
   115  	Packages     []string // Arguments to godep save, if any.
   116  	Deps         []struct {
   117  		ImportPath string
   118  		Comment    string // Description of commit, if present.
   119  		Rev        string // VCS-specific commit ID.
   120  	}
   121  }
   122  ```
   123  
   124  Example Godeps:
   125  
   126  ```json
   127  {
   128  	"ImportPath": "github.com/kr/hk",
   129  	"GoVersion": "go1.6",
   130  	"Deps": [
   131  		{
   132  			"ImportPath": "code.google.com/p/go-netrc/netrc",
   133  			"Rev": "28676070ab99"
   134  		},
   135  		{
   136  			"ImportPath": "github.com/kr/binarydist",
   137  			"Rev": "3380ade90f8b0dfa3e363fd7d7e941fa857d0d13"
   138  		}
   139  	]
   140  }
   141  ```
   142  
   143  ## Migrating to vendor/
   144  
   145  Godep supports the Go 1.5+ vendor/
   146  [experiment](https://github.com/golang/go/commit/183cc0cd41f06f83cb7a2490a499e3f9101befff)
   147  utilizing the same environment variable that the go tooling itself supports 
   148  (`GO15VENDOREXPERIMENT`).
   149  
   150  godep mostly works the same way as the `go` command line tool. If you have go 
   151  1.5.X and set `GO15VENDOREXPERIMENT=1` or have go1.6.X (or devel) `vendor/` 
   152  is enabled. **Unless** you already have a `Godeps/_workspace`. This is a safety
   153  feature and godep warns you about this. 
   154  
   155  When `vendor/` is enabled godep will write the vendored code into the top level
   156  `./vendor/` directory. A `./Godeps/Godeps.json` file is created to track 
   157  the dependencies and revisions. `vendor/` is not compatible with rewrites.
   158  
   159  There is currently no automated migration between the old Godeps workspace and
   160  the vendor directory, but the following steps should work:
   161  
   162  ```term
   163  # just to be safe
   164  $ unset GO15VENDOREXPERIMENT
   165  
   166  # restore currently vendored deps to the $GOPATH
   167  $ godep restore
   168  
   169  # The next line is only needed to automatically undo rewritten imports that were
   170  # created with godep save -r.
   171  $ godep save -r=false <pkg spec>
   172  
   173  # Remove the old Godeps folder
   174  $ rm -rf Godeps
   175  
   176  # If on go1.5.X to enable `vendor/`
   177  $ export GO15VENDOREXPERIMENT=1
   178  
   179  # re-analyze deps and save to `vendor/`. 
   180  $ godep save <pkg spec>
   181  
   182  # Add the changes to your VCS
   183  $ git add -A . ; git commit -am "Godep workspace -> vendor/"
   184  
   185  # You should see your Godeps/_workspace/src files "moved" to vendor/.
   186  ```
   187  
   188  ## Releasing
   189  
   190  1. Increment the version in `version.go`.
   191  1. Tag the commit with the same version number.
   192  1. Update `Changelog.md`.