Skip to content

Commit 056459e

Browse files
committed
Add version tiebreaker to remaining sort calls
Same issue as the diff driver: tree, licenses, and integrity commands sorted dependencies by name only, giving nondeterministic output when the same package appears at multiple versions.
1 parent d5a7337 commit 056459e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

cmd/integrity.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ func runIntegrity(cmd *cobra.Command, args []string) error {
169169
if entries[i].Name != entries[j].Name {
170170
return entries[i].Name < entries[j].Name
171171
}
172+
if entries[i].Version != entries[j].Version {
173+
return entries[i].Version < entries[j].Version
174+
}
172175
return entries[i].ManifestPath < entries[j].ManifestPath
173176
})
174177

cmd/licenses.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ func runLicenses(cmd *cobra.Command, args []string) error {
227227

228228
// Sort by name
229229
sort.Slice(licenseInfos, func(i, j int) bool {
230-
return licenseInfos[i].Name < licenseInfos[j].Name
230+
if licenseInfos[i].Name != licenseInfos[j].Name {
231+
return licenseInfos[i].Name < licenseInfos[j].Name
232+
}
233+
return licenseInfos[i].Version < licenseInfos[j].Version
231234
})
232235

233236
switch format {

cmd/tree.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ func buildTree(deps []database.Dependency) []*TreeNode {
131131

132132
// Sort dependencies
133133
sort.Slice(typeDeps, func(i, j int) bool {
134-
return typeDeps[i].Name < typeDeps[j].Name
134+
if typeDeps[i].Name != typeDeps[j].Name {
135+
return typeDeps[i].Name < typeDeps[j].Name
136+
}
137+
return typeDeps[i].Requirement < typeDeps[j].Requirement
135138
})
136139

137140
for _, d := range typeDeps {

0 commit comments

Comments
 (0)