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

Add vendor/.git exists check in SafeWriter.Write #464

Merged
merged 2 commits into from
Apr 27, 2017

Conversation

darkowlzz
Copy link
Collaborator

@darkowlzz darkowlzz commented Apr 26, 2017

Fixes #460

@darkowlzz
Copy link
Collaborator Author

@sdboyer should we handle cross-device rename errors here, as in Masterminds/glide#699 ?

Added a unit test for hasDotGit().

Didn't add integration test for init command. Found out that creating .git in vendor/ and using vendor-final in testcase.json would not work due to length check in GetVendorPath() . Should I modify that to work here?

Need help in adding integration test for vendor/.git file.

Copy link
Collaborator

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! 💖 I have only a few small changes

txn_writer.go Outdated
@@ -294,6 +294,14 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager) error {
}
}

// Ensure vendor/.git is preserved if present
if hasDotGit(vpath) {
err = os.Rename(filepath.Join(vpath, ".git"), filepath.Join(td, "vendor/.git"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dep.renameWithFallback does what you have here, plus a bunch more error handling, let's use that instead of os.Rename directly.

txn_writer.go Outdated
func hasDotGit(path string) bool {
gitfilepath := filepath.Join(path, ".git")
_, err := os.Stat(gitfilepath)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to return err == nil.

@@ -522,3 +524,17 @@ func TestSafeWriter_DiffLocks(t *testing.T) {
t.Fatal(err)
}
}

func TestHasDotGit(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add one more test that populates vendor/.git, and then writes out vendor using SafeWriter, verifying that this feature is plumbed in properly. You can look at https://github.com/golang/dep/blob/master/txn_writer_test.go#L215 for an example of how to call the safewriter and force vendor to be rewritten.

@carolynvs
Copy link
Collaborator

See my review comments for how to deal with cross device rename problems, and how to test your changes.

- Adds TestSafeWriter_VendorDotGitPreservedWithForceVendor test.
- Replaces os.Rename with renameWithFallback
@darkowlzz
Copy link
Collaborator Author

@carolynvs thanks for the review :)

Made the changes and tests are passing. Lemme know if anything else is required and if I should squash the commits.

@sdboyer
Copy link
Member

sdboyer commented Apr 27, 2017

LGTM - thanks for this, @darkowlzz!

@sdboyer sdboyer merged commit 1e41a25 into golang:master Apr 27, 2017
ibrasho pushed a commit to ibrasho-forks/dep that referenced this pull request May 10, 2017
Add vendor/.git exists check in SafeWriter.Write
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants