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

Commit

Permalink
Fixing an edge case in lockdiff where all the projects may be removed…
Browse files Browse the repository at this point in the history
… from the lock file.
  • Loading branch information
tariq1890 committed Jul 30, 2018
1 parent 224a564 commit 9533895
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
41 changes: 23 additions & 18 deletions gps/verify/lockdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,31 @@ func DiffLocks(l1, l2 gps.Lock) LockDelta {
Name: pr1,
}

for i2 := i2next; i2 < len(p2); i2++ {
lp2 := p2[i2]
pr2 := lp2.Ident().ProjectRoot

switch strings.Compare(string(pr1), string(pr2)) {
case 0: // Found a matching project
lpd.LockedProjectPropertiesDelta = DiffLockedProjectProperties(lp1, lp2)
i2next = i2 + 1 // Don't visit this project again
case +1: // Found a new project
diff.ProjectDeltas[pr2] = LockedProjectDelta{
Name: pr2,
ProjectAdded: true,
// 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
} else {
for i2 := i2next; i2 < len(p2); i2++ {
lp2 := p2[i2]
pr2 := lp2.Ident().ProjectRoot

switch strings.Compare(string(pr1), string(pr2)) {
case 0: // Found a matching project
lpd.LockedProjectPropertiesDelta = DiffLockedProjectProperties(lp1, lp2)
i2next = i2 + 1 // Don't visit this project again
case +1: // Found a new project
diff.ProjectDeltas[pr2] = LockedProjectDelta{
Name: pr2,
ProjectAdded: true,
}
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
}
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
break // Done evaluating this project, move onto the next
}
}

diff.ProjectDeltas[pr1] = lpd
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 @@ -118,6 +118,10 @@ func TestLockDelta(t *testing.T) {
lt: dup.addII("other.org").rmII("baz.com/qux").addDumbProject("zebrafun.org").rmProject("foo.com/bar"),
delta: InputImportsChanged | ProjectRemoved | ProjectAdded,
},
"remove all projects and imports": {
lt: dup.rmII("baz.com/qux").rmII("foo.com/bar").rmProject("baz.com/qux").rmProject("foo.com/bar").rmProject("transitive.com/dependency"),
delta: InputImportsChanged | ProjectRemoved,
},
}

for name, fix := range tt {
Expand Down

0 comments on commit 9533895

Please sign in to comment.