Skip to content

Commit e6622a8

Browse files
committed
Bring README up to date after golang#489
1 parent 5dd0593 commit e6622a8

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

README.md

+38-16
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Dep is a prototype dependency management tool. It requires Go 1.7 or newer to co
1111
`dep` is safe for production use. That means two things:
1212

1313
* Any valid metadata file (`Gopkg.toml` and `Gopkg.lock`) will be readable and considered valid by any future version of `dep`.
14+
* The CLI UI is mostly stable. `dep init` and `dep ensure` are mostly set; `dep status` is likely to change a fair bit, and `dep prune` is [going to be absorbed into `dep ensure`](https://github.com/golang/dep/issues/944).
1415
* Generally speaking, it has comparable or fewer bugs than other tools out there.
1516

1617
That said, keep in mind the following:
1718

1819
* `dep` is still changing rapidly. If you need stability (e.g. for CI), it's best to rely on a released version, not tip.
19-
* [Some changes](https://github.com/golang/dep/pull/489) are pending to the CLI interface. Scripting on dep before they land is unwise.
2020
* `dep`'s exported API interface will continue to change in unpredictable, backwards-incompatible ways until we tag a v1.0.0 release.
2121

2222
## Context
@@ -44,7 +44,7 @@ $ brew install dep
4444
$ brew upgrade dep
4545
```
4646

47-
To start managing dependencies using dep, run the following from your project root directory:
47+
To start managing dependencies using dep, run the following from your project's root directory:
4848

4949
```sh
5050
$ dep init
@@ -63,10 +63,15 @@ This does the following:
6363

6464
## Usage
6565

66-
There is one main subcommand you will use: `dep ensure`. `ensure` first makes
67-
sure `Gopkg.lock` is consistent with your `import`s and `Gopkg.toml`. If any
68-
changes are detected, it then populates `vendor/` with exactly what's described
69-
in `Gopkg.lock`.
66+
There is one main subcommand you will use: `dep ensure`. `ensure` first checks that `Gopkg.lock` is consistent with `Gopkg.toml` and the `import`s in your code. If any
67+
changes are detected, `dep`'s solver works out a new `Gopkg.lock`. Then, `dep` checks if the contents of `vendor/` are what `Gopkg.lock` (the new one if applicable, else the existing one) says it should be, and rewrites `vendor/` as needed to bring it into line.
68+
69+
In essence, `dep ensure` [works in two phases to keep four buckets of state in sync](https://youtu.be/5LtMb090AZI?t=20m4s):
70+
71+
<img width="463" alt="states-flow" src="https://user-images.githubusercontent.com/21599/29223886-22dd2578-7e96-11e7-8b51-3637b9ddc715.png">
72+
73+
74+
_Note: until we ship [vendor verification](https://github.com/golang/dep/issues/121), we can't efficiently perform the `Gopkg.lock` <-> `vendor/` comparison, so `dep ensure` unconditionally regenerates all of `vendor/` to be safe._
7075

7176
`dep ensure` is safe to run early and often. See the help text for more detailed
7277
usage instructions.
@@ -91,12 +96,19 @@ matches the constraints from the manifest. If the dependency is missing from
9196

9297
### Adding a dependency
9398

94-
1. `import` the package in your `*.go` source code file(s).
95-
1. Run the following command to update your `Gopkg.lock` and populate `vendor/` with the new dependency.
99+
Adding a project as a dependency has three essential steps:
96100

97-
```sh
98-
$ dep ensure
99-
```
101+
1. `import` a package from the project in one of your `*.go` source files
102+
2. Add a version constraint on the project to `Gopkg.toml` (Optional, but recommended)
103+
3. Run `dep ensure`
104+
105+
`dep ensure -add` provides some CLI sugar to ease this process:
106+
107+
```sh
108+
$ dep ensure -add github.com/some/project github.com/other/project/[email protected]
109+
```
110+
111+
`dep ensure -add`'s behavior varies slightly depending on whether there are already rules in `Gopkg.toml` for the named project(s), as well as whether you already import packages from the named project(s). See `dep ensure -examples` for more sample combinations.
100112

101113
### Changing dependencies
102114

@@ -107,7 +119,7 @@ If you want to:
107119

108120
for one or more dependencies, do the following:
109121

110-
1. Modify your `Gopkg.toml`.
122+
1. Manually edit your `Gopkg.toml`.
111123
1. Run
112124

113125
```sh
@@ -126,7 +138,7 @@ github.com/Masterminds/vcs ^1.11.0 v1.11.1 3084677 3084
126138
github.com/armon/go-radix * branch master 4239b77 4239b77
127139
```
128140

129-
On top of that, if you have added new imports to your project or modified the manifest file without running `dep ensure` again, `dep status` will tell you there is a mismatch between the lock file and the current status of the project.
141+
On top of that, if you have added new imports to your project or modified `Gopkg.toml` without running `dep ensure` again, `dep status` will tell you there is a mismatch between `Gopkg.lock` and the current status of the project.
130142

131143
```sh
132144
$ dep status
@@ -142,23 +154,33 @@ As `dep status` suggests, run `dep ensure` to update your lockfile. Then run `de
142154

143155
### Updating dependencies
144156

145-
(to the latest version allowed by the manifest)
157+
Updating brings the version of a dependency in `Gopkg.lock` and `vendor/` to the latest version allowed by the constraints in `Gopkg.toml`.
158+
159+
You can update just a targeted subset of dependencies (recommended):
160+
161+
```sh
162+
$ dep ensure -update github.com/some/project github.com/other/project
163+
$ dep ensure -update github.com/another/project
164+
```
165+
166+
Or you can update all your dependencies at once:
146167

147168
```sh
148169
$ dep ensure -update
149170
```
150171

172+
"Latest" means different things depending on the type of constraint in use. If you're depending on a `branch`, `dep` will update to the latest tip of that branch. If you're depending on a `version` using [a semver range](#semantic-versioning), it will update to the latest version in that range.
173+
151174
### Removing dependencies
152175

153176
1. Remove the `import`s and all usage from your code.
177+
1. Remove `[[constraint]]` rules from `Gopkg.toml` (if any).
154178
1. Run
155179

156180
```sh
157181
$ dep ensure
158182
```
159183

160-
1. Remove from `Gopkg.toml`, if it was in there.
161-
162184
### Testing changes to a dependency
163185

164186
Making changes in your `vendor/` directory directly is not recommended, as dep

0 commit comments

Comments
 (0)