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

Commit ee9843c

Browse files
committed
Added comment on top of lock file
This will warn people to not edit lock file manually. Resolves #615 Changes
1 parent 8bdd9e5 commit ee9843c

File tree

23 files changed

+57
-24
lines changed

23 files changed

+57
-24
lines changed

cmd/dep/testdata/harness_tests/ensure/empty/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/empty/case2/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/empty/case3/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/override/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/pkg-errors/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/update/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/update/case2/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/ensure/update/case2/initial/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/init/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/init/case2/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/init/case3/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/init/skip-hidden/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/remove/force/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/remove/specific/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/remove/specific/case2/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/remove/unused/case1/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/status/case1/dot/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/status/case1/json/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/status/case1/table/final/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/init_path_tests/relative_path/final/project_dir/Gopkg.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fs.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"syscall"
1414

1515
"github.com/golang/dep/internal"
16-
"github.com/pelletier/go-toml"
1716
"github.com/pkg/errors"
1817
)
1918

@@ -61,22 +60,6 @@ func IsNonEmptyDir(name string) (bool, error) {
6160
}
6261
}
6362

64-
func writeFile(path string, in toml.Marshaler) error {
65-
f, err := os.Create(path)
66-
if err != nil {
67-
return err
68-
}
69-
defer f.Close()
70-
71-
s, err := in.MarshalTOML()
72-
if err != nil {
73-
return err
74-
}
75-
76-
_, err = f.Write(s)
77-
return err
78-
}
79-
8063
// modifyWithString modifies a given file with a new string input.
8164
// This is used to write arbitrary string data to a file, such as
8265
// updating the `Gopkg.toml` file with example data if no deps found

testdata/txn_writer/expected_lock.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2+
13
memo = "595716d270828e763c811ef79c9c41f85b1d1bfbdfe85280036405c03772206c"
24

35
[[projects]]

txn_writer.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// Example string to be written to the manifest file
2323
// if no dependencies are found in the project
2424
// during `dep init`
25-
const exampleTOML = `
25+
var exampleTOML = []byte(`
2626
## Gopkg.toml example (these lines may be deleted)
2727
2828
## "required" lists a set of packages (not projects) that must be included in
@@ -74,7 +74,12 @@ const exampleTOML = `
7474
# source = "https://github.com/myfork/package.git"
7575
7676
77-
`
77+
`)
78+
79+
// String added on top of lock file
80+
var lockFileComment = []byte(`# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
81+
82+
`)
7883

7984
// SafeWriter transactionalizes writes of manifest, lock, and vendor dir, both
8085
// individually and in any combination, into a pseudo-atomic action with
@@ -307,22 +312,25 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager, noExamples bool)
307312
return errors.Wrap(err, "failed to marshal manifest to TOML")
308313
}
309314

310-
var initOutput string
315+
var initOutput []byte
311316

312317
// If examples are NOT disabled, use the example text
313318
if !noExamples {
314319
initOutput = exampleTOML
315320
}
316321

317-
// 0666 is before umask; mirrors behavior of os.Create (used by
318-
// writeFile())
319-
if err = ioutil.WriteFile(filepath.Join(td, ManifestName), append([]byte(initOutput), tb...), 0666); err != nil {
322+
if err = ioutil.WriteFile(filepath.Join(td, ManifestName), append(initOutput, tb...), 0666); err != nil {
320323
return errors.Wrap(err, "failed to write manifest file to temp dir")
321324
}
322325
}
323326

324327
if sw.HasLock() {
325-
if err := writeFile(filepath.Join(td, LockName), sw.lock); err != nil {
328+
l, err := sw.lock.MarshalTOML()
329+
if err != nil {
330+
return errors.Wrap(err, "failed to marshal lock to TOML")
331+
}
332+
333+
if err = ioutil.WriteFile(filepath.Join(td, LockName), append(lockFileComment, l...), 0666); err != nil {
326334
return errors.Wrap(err, "failed to write lock file to temp dir")
327335
}
328336
}

0 commit comments

Comments
 (0)