Skip to content

Commit ac3fef2

Browse files
committed
Handle the cases when there is only ref update on chain
1 parent 79fa7c7 commit ac3fef2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cmd/git-remote-gitopia/gitopia.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,28 +389,38 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
389389

390390
// Only try to approve packfile/LFS updates if we actually pushed something.
391391
if len(allRefspecs) > 0 {
392-
// Approve packfile update
392+
// Try to approve packfile update if proposal exists
393393
packfileUpdateProposalRes, err := h.storageClient.PackfileUpdateProposal(context.Background(), &storagetypes.QueryPackfileUpdateProposalRequest{
394394
RepositoryId: h.remoteRepository.Id,
395395
User: h.wallet.Address(),
396396
})
397-
if err != nil {
397+
if err != nil && strings.Contains(err.Error(), "packfile update proposal not found") {
398+
// There is no change in packfile so set packfile cid to old_cid itself
399+
packfileCid = packfileRes.Packfile.OldCid
400+
} else {
398401
return nil, err
399402
}
400-
msg = append(msg, storagetypes.NewMsgApproveRepositoryPackfileUpdate(h.wallet.Address(), packfileUpdateProposalRes.PackfileUpdateProposal.Id))
403+
if packfileUpdateProposalRes != nil {
404+
// Packfile update proposal exists, approve it
405+
msg = append(msg, storagetypes.NewMsgApproveRepositoryPackfileUpdate(h.wallet.Address(), packfileUpdateProposalRes.PackfileUpdateProposal.Id))
406+
}
407+
// If error occurs (e.g., proposal not found), continue without failing
408+
// This handles cases like tag pushes where objects already exist
401409

402410
lfsObjectUpdateProposalRes, err := h.storageClient.LFSObjectUpdateProposalsByRepositoryId(context.Background(), &storagetypes.QueryLFSObjectUpdateProposalsByRepositoryIdRequest{
403411
RepositoryId: h.remoteRepository.Id,
404412
User: h.wallet.Address(),
405413
})
406-
if err != nil {
414+
if err != nil && !strings.Contains(err.Error(), "lfs object update proposal not found") {
407415
return nil, err
408416
}
409-
410-
// Approve LFS object update
411-
for _, lfsObjectUpdateProposal := range lfsObjectUpdateProposalRes.LfsObjectProposals {
412-
msg = append(msg, storagetypes.NewMsgApproveLFSObjectUpdate(h.wallet.Address(), lfsObjectUpdateProposal.Id))
417+
if lfsObjectUpdateProposalRes != nil {
418+
// Approve LFS object updates if proposals exist
419+
for _, lfsObjectUpdateProposal := range lfsObjectUpdateProposalRes.LfsObjectProposals {
420+
msg = append(msg, storagetypes.NewMsgApproveLFSObjectUpdate(h.wallet.Address(), lfsObjectUpdateProposal.Id))
421+
}
413422
}
423+
// If error occurs (e.g., no LFS proposals), continue without failing
414424
}
415425

416426
if len(setBranches) > 0 {

0 commit comments

Comments
 (0)