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

Commit fd77463

Browse files
committed
Be verbose and don't update files during dry-run
1 parent 8ac86c2 commit fd77463

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

cmd/dep/ensure.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
119119
defer sm.Release()
120120

121121
params := p.MakeParams()
122-
if *verbose {
122+
if *verbose || cmd.dryRun {
123123
params.Trace = true
124124
params.TraceLogger = log.New(os.Stderr, "", 0)
125125
}
@@ -165,6 +165,10 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
165165
}
166166
writeV := !vendorExists && solution != nil
167167

168+
if cmd.dryRun {
169+
return nil
170+
}
171+
168172
return errors.Wrap(sw.WriteAllSafe(writeV), "grouped write of manifest, lock and vendor")
169173
}
170174

cmd/dep/ensure_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/golang/dep/test"
1111
"github.com/sdboyer/gps"
12+
"path/filepath"
1213
)
1314

1415
func TestEnsureOverrides(t *testing.T) {
@@ -166,3 +167,38 @@ func TestEnsureUpdate(t *testing.T) {
166167
}
167168
}
168169
}
170+
171+
func TestEnsureDryRun(t *testing.T) {
172+
test.NeedsExternalNetwork(t)
173+
test.NeedsGit(t)
174+
175+
h := test.NewHelper(t)
176+
defer h.Cleanup()
177+
178+
// Setup up a test project
179+
h.TempDir("src")
180+
h.Setenv("GOPATH", h.Path("."))
181+
h.TempCopy("src/thing/main.go", "ensure/update_main.go")
182+
origManifest := "ensure/update_manifest.json"
183+
h.TempCopy("src/thing/manifest.json", origManifest)
184+
origLock := "ensure/update_lock.json"
185+
h.TempCopy("src/thing/lock.json", origLock)
186+
h.Cd(h.Path("src/thing"))
187+
188+
h.Run("ensure", "-n", "-update", "github.com/carolynvs/go-dep-test")
189+
190+
// Verify that nothing was modified during the dry-run
191+
wantManifest := h.GetTestFileString(origManifest)
192+
gotManifest := h.ReadManifest()
193+
if gotManifest != wantManifest {
194+
t.Fatalf("The manifest should not be modified during a dry-run. Expected %s, got %s", origManifest, gotManifest)
195+
}
196+
197+
wantLock := h.GetTestFileString(origLock)
198+
gotLock := h.ReadLock()
199+
if gotLock != wantLock {
200+
t.Fatalf("The lock should not be modified during a dry-run. Expected %s, got %s", origLock, gotLock)
201+
}
202+
203+
h.MustNotExist(filepath.Join(h.Path("src/thing"), "vendor"))
204+
}

0 commit comments

Comments
 (0)