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

Commit

Permalink
Display diff of lock file during dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs committed Mar 9, 2017
1 parent d02eb69 commit 02635cc
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 35 deletions.
3 changes: 2 additions & 1 deletion cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
manifest = p.Manifest
}

sw.Prepare(manifest, p.Lock, solution, writeV)
newLock := dep.LockFromInterface(solution)
sw.Prepare(manifest, p.Lock, newLock, writeV)
if cmd.dryRun {
return sw.PrintPreparedActions()
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/dep/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
}

var sw dep.SafeWriter
sw.Prepare(p.Manifest, p.Lock, soln, false)
newLock := dep.LockFromInterface(soln)
sw.Prepare(p.Manifest, p.Lock, newLock, false)
if err := sw.Write(p.AbsRoot, sm); err != nil {
return errors.Wrap(err, "grouped write of manifest, lock and vendor")
}
Expand Down
11 changes: 0 additions & 11 deletions lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,3 @@ func (s SortedLockedProjects) Less(i, j int) bool {

return l.Source < r.Source
}

// locksAreEquivalent compares two locks to see if they differ. If EITHER lock
// is nil, or their memos do not match, or any projects differ, then false is
// returned.
func locksAreEquivalent(l, r *Lock) bool {
if l == nil || r == nil {
return false
}

return gps.LocksAreEq(l, r, true)
}
9 changes: 4 additions & 5 deletions test_project_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ func (pc *TestProjectContext) getVendorPath() string {
// Updates the golden file when -UpdateGolden flag is present.
func (pc *TestProjectContext) LockShouldMatchGolden(goldenLockPath string) error {
got := pc.h.ReadLock()
want := pc.h.GetTestFileString(goldenLockPath)
return pc.shouldMatchGolden(goldenLockPath, want, got)
return pc.ShouldMatchGolden(goldenLockPath, got)
}

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

// ManifestShouldNotExist returns an error when the lock exists.
Expand All @@ -122,7 +120,8 @@ func (pc *TestProjectContext) ManifestShouldNotExist() error {
// ShouldMatchGolden returns an error when a file does not match the golden file.
// goldenFile is the path to the golden file, relative to the testdata directory
// Updates the golden file when -UpdateGolden flag is present
func (pc *TestProjectContext) shouldMatchGolden(goldenFile string, want string, got string) error {
func (pc *TestProjectContext) ShouldMatchGolden(goldenFile string, got string) error {
want := pc.h.GetTestFileString(goldenFile)
if want != got {
if *test.UpdateGolden {
if err := pc.h.WriteTestFile(goldenFile, got); err != nil {
Expand Down
26 changes: 26 additions & 0 deletions testdata/txn_writer/expected_diff_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Add: [
{
"name": "github.com/stuff/realthing",
"version": "2.0.0",
"revision": "1f02e52d6bac308da54ab84a234c58a98ca82347",
"packages": [
"."
]
}
]
Remove: [
"github.com/stuff/placeholder"
]
Modify: [
{
"name": "github.com/foo/bar",
"repo": "+ http://github.example.com/foo/bar",
"version": "+ 1.2.0",
"branch": "- master",
"revision": "f24338400f072ef18125ae0fbe6b06fe6d1783e7 -> 2a3a211e171803acb82d1d5d42ceb53228f51751",
"packages": [
"- placeholder",
"+ thing"
]
}
]
22 changes: 22 additions & 0 deletions testdata/txn_writer/original_lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"memo": "595716d270828e763c811ef79c9c41f85b1d1bfbdfe85280036405c03772206c",
"projects": [
{
"name": "github.com/foo/bar",
"branch": "master",
"revision": "f24338400f072ef18125ae0fbe6b06fe6d1783e7",
"packages": [
"placeholder",
"util"
]
},
{
"name": "github.com/stuff/placeholder",
"version": "2.0.0",
"revision": "6694017eeb4e20fd277b049bf29dba4895c97234",
"packages": [
"."
]
}
]
}
23 changes: 23 additions & 0 deletions testdata/txn_writer/updated_lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"memo": "2252a285ab27944a4d7adcba8dbd03980f59ba652f12db39fa93b927c345593e",
"projects": [
{
"name": "github.com/foo/bar",
"repo": "http://github.example.com/foo/bar",
"version": "1.2.0",
"revision": "2a3a211e171803acb82d1d5d42ceb53228f51751",
"packages": [
"thing",
"util"
]
},
{
"name": "github.com/stuff/realthing",
"version": "2.0.0",
"revision": "1f02e52d6bac308da54ab84a234c58a98ca82347",
"packages": [
"."
]
}
]
}
Loading

0 comments on commit 02635cc

Please sign in to comment.