Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 24302a3

Browse files
committed
Display diff of lock file during dry-run
1 parent a99564c commit 24302a3

File tree

10 files changed

+436
-40
lines changed

10 files changed

+436
-40
lines changed

cmd/dep/ensure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
161161
manifest = p.Manifest
162162
}
163163

164-
sw.Prepare(manifest, p.Lock, solution, writeV)
164+
newLock := dep.LockFromInterface(solution)
165+
sw.Prepare(manifest, p.Lock, newLock, writeV)
165166
if cmd.dryRun {
166167
return sw.PrintPreparedActions()
167168
}

cmd/dep/ensure_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/golang/dep/test"
1212
"github.com/sdboyer/gps"
13-
"path/filepath"
1413
)
1514

1615
func TestDeduceConstraint(t *testing.T) {
@@ -156,14 +155,14 @@ func TestEnsureDryRun(t *testing.T) {
156155
// Setup up a test project
157156
h.TempDir("src")
158157
h.Setenv("GOPATH", h.Path("."))
159-
h.TempCopy("src/thing/main.go", "ensure/update_main.go")
160-
origManifest := "ensure/update_manifest.json"
158+
h.TempCopy("src/thing/main.go", "ensure/update/main.go")
159+
origManifest := "ensure/update/manifest.json"
161160
h.TempCopy("src/thing/manifest.json", origManifest)
162-
origLock := "ensure/update_lock.json"
161+
origLock := "ensure/update/lock.json"
163162
h.TempCopy("src/thing/lock.json", origLock)
164163
h.Cd(h.Path("src/thing"))
165164

166-
h.Run("ensure", "-n", "-update", "github.com/carolynvs/go-dep-test")
165+
h.Run("ensure", "-n", "-update", "github.com/sdboyer/deptest")
167166

168167
// Verify that nothing was modified during the dry-run
169168
wantManifest := h.GetTestFileString(origManifest)

cmd/dep/remove.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
180180
}
181181

182182
var sw dep.SafeWriter
183-
sw.Prepare(p.Manifest, p.Lock, soln, false)
183+
newLock := dep.LockFromInterface(soln)
184+
sw.Prepare(p.Manifest, p.Lock, newLock, false)
184185
if err := sw.Write(p.AbsRoot, sm); err != nil {
185186
return errors.Wrap(err, "grouped write of manifest, lock and vendor")
186187
}

lock.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,3 @@ func (s SortedLockedProjects) Less(i, j int) bool {
184184

185185
return l.Source < r.Source
186186
}
187-
188-
// locksAreEquivalent compares two locks to see if they differ. If EITHER lock
189-
// is nil, or their memos do not match, or any projects differ, then false is
190-
// returned.
191-
func locksAreEquivalent(l, r *Lock) bool {
192-
if l == nil || r == nil {
193-
return false
194-
}
195-
196-
return gps.LocksAreEq(l, r, true)
197-
}

test_project_context_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func (pc *TestProjectContext) getVendorPath() string {
9696
// Updates the golden file when -UpdateGolden flag is present.
9797
func (pc *TestProjectContext) LockShouldMatchGolden(goldenLockPath string) error {
9898
got := pc.h.ReadLock()
99-
want := pc.h.GetTestFileString(goldenLockPath)
100-
return pc.shouldMatchGolden(goldenLockPath, want, got)
99+
return pc.ShouldMatchGolden(goldenLockPath, got)
101100
}
102101

103102
// LockShouldNotExist returns an error when the lock exists.
@@ -110,8 +109,7 @@ func (pc *TestProjectContext) LockShouldNotExist() error {
110109
// Updates the golden file when -UpdateGolden flag is present
111110
func (pc *TestProjectContext) ManifestShouldMatchGolden(goldenManifestPath string) error {
112111
got := pc.h.ReadManifest()
113-
want := pc.h.GetTestFileString(goldenManifestPath)
114-
return pc.shouldMatchGolden(goldenManifestPath, want, got)
112+
return pc.ShouldMatchGolden(goldenManifestPath, got)
115113
}
116114

117115
// ManifestShouldNotExist returns an error when the lock exists.
@@ -122,7 +120,8 @@ func (pc *TestProjectContext) ManifestShouldNotExist() error {
122120
// ShouldMatchGolden returns an error when a file does not match the golden file.
123121
// goldenFile is the path to the golden file, relative to the testdata directory
124122
// Updates the golden file when -UpdateGolden flag is present
125-
func (pc *TestProjectContext) shouldMatchGolden(goldenFile string, want string, got string) error {
123+
func (pc *TestProjectContext) ShouldMatchGolden(goldenFile string, got string) error {
124+
want := pc.h.GetTestFileString(goldenFile)
126125
if want != got {
127126
if *test.UpdateGolden {
128127
if err := pc.h.WriteTestFile(goldenFile, got); err != nil {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Add: [
2+
{
3+
"name": "github.com/stuff/realthing",
4+
"version": "2.0.0",
5+
"revision": "1f02e52d6bac308da54ab84a234c58a98ca82347",
6+
"packages": [
7+
"."
8+
]
9+
}
10+
]
11+
Remove: [
12+
"github.com/stuff/placeholder"
13+
]
14+
Modify: [
15+
{
16+
"name": "github.com/foo/bar",
17+
"repo": "+ http://github.example.com/foo/bar",
18+
"version": "+ 1.2.0",
19+
"branch": "- master",
20+
"revision": "f24338400f072ef18125ae0fbe6b06fe6d1783e7 -> 2a3a211e171803acb82d1d5d42ceb53228f51751",
21+
"packages": [
22+
"- placeholder",
23+
"+ thing"
24+
]
25+
}
26+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"memo": "595716d270828e763c811ef79c9c41f85b1d1bfbdfe85280036405c03772206c",
3+
"projects": [
4+
{
5+
"name": "github.com/foo/bar",
6+
"branch": "master",
7+
"revision": "f24338400f072ef18125ae0fbe6b06fe6d1783e7",
8+
"packages": [
9+
"placeholder",
10+
"util"
11+
]
12+
},
13+
{
14+
"name": "github.com/stuff/placeholder",
15+
"version": "2.0.0",
16+
"revision": "6694017eeb4e20fd277b049bf29dba4895c97234",
17+
"packages": [
18+
"."
19+
]
20+
}
21+
]
22+
}

testdata/txn_writer/updated_lock.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"memo": "2252a285ab27944a4d7adcba8dbd03980f59ba652f12db39fa93b927c345593e",
3+
"projects": [
4+
{
5+
"name": "github.com/foo/bar",
6+
"repo": "http://github.example.com/foo/bar",
7+
"version": "1.2.0",
8+
"revision": "2a3a211e171803acb82d1d5d42ceb53228f51751",
9+
"packages": [
10+
"thing",
11+
"util"
12+
]
13+
},
14+
{
15+
"name": "github.com/stuff/realthing",
16+
"version": "2.0.0",
17+
"revision": "1f02e52d6bac308da54ab84a234c58a98ca82347",
18+
"packages": [
19+
"."
20+
]
21+
}
22+
]
23+
}

0 commit comments

Comments
 (0)