Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote: Push, add atomic to push options #406

Merged
merged 2 commits into from Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions options.go
Expand Up @@ -232,6 +232,8 @@ type PushOptions struct {
ForceWithLease *ForceWithLease
// PushOptions sets options to be transferred to the server during push.
Options map[string]string
// Atomic sets option to be an atomic push
Atomic bool
}

// ForceWithLease sets fields on the lease
Expand Down
19 changes: 19 additions & 0 deletions plumbing/protocol/packp/updreq_encode_test.go
Expand Up @@ -170,3 +170,22 @@ func (s *UpdReqEncodeSuite) TestPushOptions(c *C) {

s.testEncode(c, r, expected)
}

func (s *UpdReqEncodeSuite) TestPushAtomic(c *C) {
hash1 := plumbing.NewHash("1ecf0ef2c2dffb796033e5a02219af86ec6584e5")
hash2 := plumbing.NewHash("2ecf0ef2c2dffb796033e5a02219af86ec6584e5")
name := plumbing.ReferenceName("myref")

r := NewReferenceUpdateRequest()
r.Capabilities.Set(capability.Atomic)
r.Commands = []*Command{
{Name: name, Old: hash1, New: hash2},
}

expected := pktlines(c,
"1ecf0ef2c2dffb796033e5a02219af86ec6584e5 2ecf0ef2c2dffb796033e5a02219af86ec6584e5 myref\x00atomic",
pktline.FlushString,
)

s.testEncode(c, r, expected)
}
5 changes: 5 additions & 0 deletions remote.go
Expand Up @@ -326,7 +326,12 @@ func (r *Remote) newReferenceUpdateRequest(
}
}

if o.Atomic && ar.Capabilities.Supports(capability.Atomic) {
_ = req.Capabilities.Set(capability.Atomic)
}

if err := r.addReferencesToUpdate(o.RefSpecs, localRefs, remoteRefs, req, o.Prune, o.ForceWithLease); err != nil {

return nil, err
}

Expand Down