@@ -18,6 +18,20 @@ import (
18
18
"github.com/sdboyer/gps"
19
19
)
20
20
21
+ // Example string to be written to the manifest file
22
+ // if no dependencies are found in the project
23
+ // during `dep init`
24
+ const exampleToml = `
25
+ # Example:
26
+ # [[dependencies]]
27
+ # source = "https://github.com/myfork/package.git"
28
+ # branch = "master"
29
+ # name = "github.com/vendor/package"
30
+ # Note: revision will depend on your repository type, i.e git, svc, bzr etc...
31
+ # revision = "abc123"
32
+ # version = "1.0.0"
33
+ `
34
+
21
35
// SafeWriter transactionalizes writes of manifest, lock, and vendor dir, both
22
36
// individually and in any combination, into a pseudo-atomic action with
23
37
// transactional rollback.
@@ -175,6 +189,7 @@ const (
175
189
// - If oldLock is provided without newLock, error.
176
190
// - If vendor is VendorAlways without a newLock, error.
177
191
func (sw * SafeWriter ) Prepare (manifest * Manifest , oldLock , newLock * Lock , vendor VendorBehavior ) error {
192
+
178
193
sw .Payload = & SafeWriterPayload {
179
194
Manifest : manifest ,
180
195
Lock : newLock ,
@@ -230,6 +245,7 @@ func (payload SafeWriterPayload) validate(root string, sm gps.SourceManager) err
230
245
// This mostly guarantees that dep cannot exit with a partial write that would
231
246
// leave an undefined state on disk.
232
247
func (sw * SafeWriter ) Write (root string , sm gps.SourceManager ) error {
248
+
233
249
if sw .Payload == nil {
234
250
return errors .New ("Cannot call SafeWriter.Write before SafeWriter.Prepare" )
235
251
}
@@ -255,7 +271,12 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager) error {
255
271
defer os .RemoveAll (td )
256
272
257
273
if sw .Payload .HasManifest () {
258
- if err := writeFile (filepath .Join (td , ManifestName ), sw .Payload .Manifest ); err != nil {
274
+ if sw .Payload .Manifest .IsEmpty () {
275
+ err := modifyWithString (filepath .Join (td , ManifestName ), exampleToml )
276
+ if err != nil {
277
+ return errors .Wrap (err , "failed to generate example text" )
278
+ }
279
+ } else if err := writeFile (filepath .Join (td , ManifestName ), sw .Payload .Manifest ); err != nil {
259
280
return errors .Wrap (err , "failed to write manifest file to temp dir" )
260
281
}
261
282
}
0 commit comments