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

Commit

Permalink
gps: Handle case with fewer projects on RHS
Browse files Browse the repository at this point in the history
This is a more generalized version of the fix from #1972.

By virtue of being more general, it also fixes #1945.
  • Loading branch information
sdboyer committed Aug 4, 2018
1 parent 38b77a1 commit 6b79ccc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# (next version)
# v0.5.1

BUG FIXES:

* Correctly handle certain cases where `dep ensure` removed projects from Gopkg.lock. ([#1945](https://github.com/golang/dep/issue/1945)).

# v0.5.0

Expand Down
18 changes: 8 additions & 10 deletions gps/verify/lockdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ func DiffLocks(l1, l2 gps.Lock) LockDelta {

lpd := LockedProjectDelta{
Name: pr1,
}

// Edge case: If there are no lockedProjects on the RHS, they have most probably been removed from the lock file.
if len(p2) == 0 {
lpd.ProjectRemoved = true
diff.ProjectDeltas[pr1] = lpd
continue
// Default to assuming a project was removed, as it will handle both
// the obvious removal case (where there's a visible hole in p2),
// and the non-obvious case, where p2 is shorter than p1.
ProjectRemoved: true,
}

for i2 := i2next; i2 < len(p2); i2++ {
Expand All @@ -108,7 +105,10 @@ func DiffLocks(l1, l2 gps.Lock) LockDelta {

switch strings.Compare(string(pr1), string(pr2)) {
case 0: // Found a matching project
lpd.LockedProjectPropertiesDelta = DiffLockedProjectProperties(lp1, lp2)
lpd = LockedProjectDelta{
Name: pr1,
LockedProjectPropertiesDelta: DiffLockedProjectProperties(lp1, lp2),
}
i2next = i2 + 1 // Don't visit this project again
case +1: // Found a new project
diff.ProjectDeltas[pr2] = LockedProjectDelta{
Expand All @@ -117,8 +117,6 @@ func DiffLocks(l1, l2 gps.Lock) LockDelta {
}
i2next = i2 + 1 // Don't visit this project again
continue // Keep looking for a matching project
case -1: // Project has been removed, handled below
lpd.ProjectRemoved = true
}

break // Done evaluating this project, move onto the next
Expand Down
4 changes: 4 additions & 0 deletions gps/verify/lockdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func TestLockDelta(t *testing.T) {
lt: dup.rmProject("foo.com/bar"),
delta: ProjectRemoved,
},
"remove last project": {
lt: dup.rmProject("transitive.com/dependency"),
delta: ProjectRemoved,
},
"all": {
lt: dup.addII("other.org").rmII("baz.com/qux").addDumbProject("zebrafun.org").rmProject("foo.com/bar"),
delta: InputImportsChanged | ProjectRemoved | ProjectAdded,
Expand Down

0 comments on commit 6b79ccc

Please sign in to comment.