diff options
-rw-r--r-- | remote.go | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -168,7 +168,17 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) { } } - rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar)) + if len(hashesToPush) == 0 { + allDelete = true + for _, command := range req.Commands { + if command.Action() != packp.Delete { + allDelete = false + break + } + } + } + + rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar), allDelete) if err != nil { return err } @@ -1033,10 +1043,11 @@ func pushHashes( req *packp.ReferenceUpdateRequest, hs []plumbing.Hash, useRefDeltas bool, + allDelete bool, ) (*packp.ReportStatus, error) { rd, wr := io.Pipe() - req.Packfile = rd + config, err := s.Config() if err != nil { return nil, err @@ -1047,15 +1058,20 @@ func pushHashes( // to the channel. done := make(chan error, 1) - go func() { - e := packfile.NewEncoder(wr, s, useRefDeltas) - if _, err := e.Encode(hs, config.Pack.Window); err != nil { - done <- wr.CloseWithError(err) - return - } + if !allDelete { + req.Packfile = rd + go func() { + e := packfile.NewEncoder(wr, s, useRefDeltas) + if _, err := e.Encode(hs, config.Pack.Window); err != nil { + done <- wr.CloseWithError(err) + return + } - done <- wr.Close() - }() + done <- wr.Close() + }() + } else { + close(done) + } rs, err := sess.ReceivePack(ctx, req) if err != nil { |