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

Commit 8652142

Browse files
committed
Sort manifest sections before writing to disk
1 parent cabd1a9 commit 8652142

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

manifest.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package dep
66

77
import (
88
"io"
9+
"sort"
910

1011
"github.com/pelletier/go-toml"
1112
"github.com/pkg/errors"
@@ -128,12 +129,34 @@ func (m *Manifest) toRaw() rawManifest {
128129
for n, prj := range m.Dependencies {
129130
raw.Dependencies = append(raw.Dependencies, toRawProject(n, prj))
130131
}
132+
sort.Sort(sortedRawProjects(raw.Dependencies))
133+
131134
for n, prj := range m.Ovr {
132135
raw.Overrides = append(raw.Overrides, toRawProject(n, prj))
133136
}
137+
sort.Sort(sortedRawProjects(raw.Overrides))
138+
134139
return raw
135140
}
136141

142+
// TODO(carolynvs) when gps is moved, we can use the unexported gps.sortedConstraints
143+
type sortedRawProjects []rawProject
144+
145+
func (s sortedRawProjects) Len() int { return len(s) }
146+
func (s sortedRawProjects) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
147+
func (s sortedRawProjects) Less(i, j int) bool {
148+
l, r := s[i], s[j]
149+
150+
if l.Name < r.Name {
151+
return true
152+
}
153+
if r.Name < l.Name {
154+
return false
155+
}
156+
157+
return l.Source < r.Source
158+
}
159+
137160
func (m *Manifest) MarshalTOML() (string, error) {
138161
raw := m.toRaw()
139162

testdata/manifest/golden.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ignores = ["github.com/foo/bar"]
22

3-
[[dependencies]]
4-
name = "github.com/sdboyer/gps"
5-
version = ">=0.12.0, <1.0.0"
6-
73
[[dependencies]]
84
name = "github.com/babble/brook"
95
revision = "d05d5aca9f895d19e9265839bffeadd74a2d2ecb"
106

7+
[[dependencies]]
8+
name = "github.com/sdboyer/gps"
9+
version = ">=0.12.0, <1.0.0"
10+
1111
[[overrides]]
1212
branch = "master"
1313
name = "github.com/sdboyer/gps"

0 commit comments

Comments
 (0)