-
Notifications
You must be signed in to change notification settings - Fork 1k
Write vendor, regardless of lock, if force is true #325
Conversation
Fix misunderstanding about when lock and newlock should be set in the SafeWriter tests.
txn_writer.go
Outdated
} | ||
|
||
if newLock != nil { | ||
if lock == nil { | ||
sw.Payload.Lock = newLock | ||
sw.Payload.ForceWriteVendor = true | ||
sw.Payload.WriteVendor = true | ||
} else { | ||
diff := diffLocks(lock, newLock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running dep ensure -n
without a lock.json
file does not print a diff even though dep ensure
creates a new lock file. I don't think that's WAI?
With the other changes you made here this entire block in newLock != nil
could then be simplified to:
if newLock != nil {
sw.Payload.Lock = newLock
sw.Payload.LockDiff = diffLocks(lock, newLock)
sw.Payload.WriteVendor = true
} ...
which solves the problem. However, you'd probably have to fix the nil check in the diffLocks function for this to work when lock is nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll play with that simplification and add a test for a bare ensure without an existing lock file.
|
* Always write the manifest when provided. * Write the lock only when modified or when writing vendor/. * Clarify what should be passed for the two locks args: old lock and new lock. Updated `dep init` to match this expectation. * Add test case for writing a new lock
42f2cb1
to
e565a9f
Compare
This is ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I noticed while testing this was that the lock diff is not printed if LockDiff
only contains a HashDiff
. Probably not worth delaying this PR for since it fixes #323, but something to keep in mind.
Other than that LGTM.
txn_writer.go
Outdated
@@ -160,26 +157,23 @@ func (diff StringDiff) MarshalJSON() ([]byte, error) { | |||
// and the vendor directory in the same way | |||
// - If the forceVendor param is true, then vendor/ will be unconditionally | |||
// written out based on newLock if present, else lock, else error. | |||
func (sw *SafeWriter) Prepare(manifest *Manifest, lock *Lock, newLock *Lock, forceVendor bool) { | |||
func (sw *SafeWriter) Prepare(manifest *Manifest, oldLock *Lock, newLock *Lock, forceVendor bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The function comments still refer to lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, s/oldLock *Lock, newLock *Lock
/oldLock, newLock *Lock
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! 😊 Fixing...
This is looking pretty good! I want to do a more thorough pass a little later, but aside from that nit, it seems like this should be able to go in presently. Thanks! |
I'm reviewing the original doc on that function (from before I ever touched it) and am a bit unsure about this scenario: https://github.com/golang/dep/blob/0acfd38/txn_writer.go#L40 I believe the only usage of this function where the original lock is nil and the new lock is specified is during Based on my understanding, this is what I think the implementation (and doc) should be for
|
I've updated the lock diff to include the memo if it has changed, e.g. |
I think the case I was aiming for with that original doc was a bit of forward-thinking - that we'd want to We're not quite ready for that now, I think, but I'd like to see the safe writer preserve support for such a case when we get to it. |
Gotcha! I'll get that fixed tonight. |
* If manifest is provided, write it. * If newLock is provided, write it. * Explicit vendor behavior: VendorOnChanged, VendorAlways, VendorNever. * Write vendor/ using newLock.
Apologies for the delay. It was really bothering me how much logic was being "encoded" in the combination of function arguments and I wanted to make this more explicit/maintainable for the next person.
So for the future scenario of |
This looks to be in pretty good shape, so I'm gonna merge - thanks! |
Write vendor, regardless of lock, if force is true
I wasn't taking forcevendor into account properly when the diffs were the same (which is exactly what that flag was for...) 😞
This fixes my misunderstanding about when lock and newlock should be set in the SafeWriter tests. Previously, I thought I should only pass in newlock when the lock had changed, or was brand new, when actually it should be passed anytime there was an existing lock file. Due to the bad test, it was missing that a bare ensure with an existing lock file (and no vendor) should result in vendor being written.
This fixes #323.