diff --git a/internal/git/localrepo/tree.go b/internal/git/localrepo/tree.go index b56e172d31880d54359dff122cdb516e4ca636c2..39ac60d3d7946912c1b27963370a136098cc7599 100644 --- a/internal/git/localrepo/tree.go +++ b/internal/git/localrepo/tree.go @@ -688,6 +688,9 @@ func (repo *Repo) ReadTree(ctx context.Context, treeish git.Revision, options .. treeOID, err := repo.ResolveRevision(ctx, rev) if err != nil { + if errors.Is(err, git.ErrReferenceNotFound) { + return nil, structerr.NewInvalidArgument("revision not found").WithMetadata("revision", treeish) + } return nil, fmt.Errorf("getting revision: %w", err) } diff --git a/internal/git/localrepo/tree_test.go b/internal/git/localrepo/tree_test.go index d17400f236cdd86dc256f9f6a9652ee02ee657b5..36d4327f642bf3b9eaa04fa06eb58e2edea8d9f8 100644 --- a/internal/git/localrepo/tree_test.go +++ b/internal/git/localrepo/tree_test.go @@ -569,7 +569,7 @@ func TestReadTree(t *testing.T) { // We get a NotExist error here because it's invalid to suffix an object ID // which resolves to a blob with a colon (":") given that it's not possible // to resolve a subpath. - expectedErr: git.ErrReferenceNotFound, + expectedErr: structerr.NewInvalidArgument("revision not found").WithMetadata("revision", blobID.Revision()), }, { desc: "valid revision with invalid path", @@ -577,7 +577,7 @@ func TestReadTree(t *testing.T) { options: []ReadTreeOption{ WithRelativePath("does-not-exist"), }, - expectedErr: git.ErrReferenceNotFound, + expectedErr: structerr.NewInvalidArgument("revision not found").WithMetadata("revision", treeWithSubtree.Revision()), }, { desc: "valid revision with path pointing to blob", @@ -590,7 +590,7 @@ func TestReadTree(t *testing.T) { { desc: "listing nonexistent object fails", treeish: "does-not-exist", - expectedErr: git.ErrReferenceNotFound, + expectedErr: structerr.NewInvalidArgument("revision not found").WithMetadata("revision", "does-not-exist"), }, { desc: "path to submodule", @@ -606,7 +606,7 @@ func TestReadTree(t *testing.T) { options: []ReadTreeOption{ WithRelativePath("submodule/foo"), }, - expectedErr: git.ErrReferenceNotFound, + expectedErr: structerr.NewInvalidArgument("revision not found").WithMetadata("revision", treeWithSubmodule.Revision()), }, } { t.Run(tc.desc, func(t *testing.T) { diff --git a/internal/gitaly/service/conflicts/resolve_conflicts.go b/internal/gitaly/service/conflicts/resolve_conflicts.go index c412efd902351488d1a8065d5a7a22f0f460c8a0..2c6a3c1df1a70452f735a2d203ffe604bcd9f713 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts.go @@ -402,6 +402,9 @@ func (s *server) repoWithBranchCommit(ctx context.Context, sourceRepo *localrepo oid, err := targetRepo.ResolveRevision(ctx, targetRevision) if err != nil { + if errors.Is(err, git.ErrReferenceNotFound) { + return structerr.NewInvalidArgument("target branch %q not found", targetBranch).WithMetadata("revision", targetRevision) + } return fmt.Errorf("could not resolve target revision %q: %w", targetRevision, err) } diff --git a/internal/gitaly/service/operations/apply_patch.go b/internal/gitaly/service/operations/apply_patch.go index 2bd3886a517bd1bd1d9f9576315cb2cebfacc008..38e25de430ca1b7ca0b181d68ab3c3c552a47ebd 100644 --- a/internal/gitaly/service/operations/apply_patch.go +++ b/internal/gitaly/service/operations/apply_patch.go @@ -199,6 +199,9 @@ func (s *Server) userApplyPatch(ctx context.Context, header *gitalypb.UserApplyP ctx, git.Revision(fmt.Sprintf("%s^{object}", currentCommit)), ) if err != nil { + if errors.Is(err, git.ErrReferenceNotFound) { + return structerr.NewInvalidArgument("expected old object not found").WithMetadata("expected_old_oid", expectedOldOID) + } return fmt.Errorf("expected old object cannot be resolved: %w", err) } } diff --git a/internal/gitaly/service/operations/apply_patch_test.go b/internal/gitaly/service/operations/apply_patch_test.go index d31d145c277f727ad41d01449fa7d559e253d563..f082f055d66b8b3ba9321a719457d03d224fb091 100644 --- a/internal/gitaly/service/operations/apply_patch_test.go +++ b/internal/gitaly/service/operations/apply_patch_test.go @@ -402,7 +402,7 @@ func TestUserApplyPatch(t *testing.T) { expected: func(t *testing.T, repoPath string) expected { return expected{ oldOID: gittest.DefaultObjectHash.ZeroOID.String(), - err: structerr.NewInternal("expected old object cannot be resolved: reference not found"), + err: structerr.NewInvalidArgument("expected old object not found").WithMetadata("expected_old_oid", gittest.DefaultObjectHash.ZeroOID.String()), } }, }, diff --git a/internal/gitaly/service/operations/cherry_pick.go b/internal/gitaly/service/operations/cherry_pick.go index dbd12c8116b1b4b05fb7e525a82686e40f8f722e..71950c908f8518fe1941ce743bd0d37533c0648a 100644 --- a/internal/gitaly/service/operations/cherry_pick.go +++ b/internal/gitaly/service/operations/cherry_pick.go @@ -92,6 +92,9 @@ func (s *Server) UserCherryPick(ctx context.Context, req *gitalypb.UserCherryPic git.Revision(fmt.Sprintf("%s^{tree}", startRevision.String())), ) if err != nil { + if errors.Is(err, git.ErrReferenceNotFound) { + return nil, structerr.NewInvalidArgument("resolve old tree: %w", err) + } return nil, fmt.Errorf("resolve old tree: %w", err) } if oldTree == treeOID { diff --git a/internal/gitaly/service/operations/commit_files.go b/internal/gitaly/service/operations/commit_files.go index eff9487dacad64ceb28a77037fe2372e66ea59e2..38907fd76bbdc2621a87a02bc28ca2d61cfce0f6 100644 --- a/internal/gitaly/service/operations/commit_files.go +++ b/internal/gitaly/service/operations/commit_files.go @@ -431,6 +431,9 @@ func (s *Server) userCommitFilesGit( git.Revision(fmt.Sprintf("%s^{tree}", parentCommitOID)), ) if err != nil { + if errors.Is(err, git.ErrReferenceNotFound) { + return "", structerr.NewInvalidArgument("getting tree id: %w", err) + } return "", fmt.Errorf("getting tree id: %w", err) } } diff --git a/internal/gitaly/service/operations/submodules.go b/internal/gitaly/service/operations/submodules.go index cdf9cfce2646f39ec3ed1178a9b4cd94a05c2141..aaaa1c77121d98154decb3c017fd4e8047c34337 100644 --- a/internal/gitaly/service/operations/submodules.go +++ b/internal/gitaly/service/operations/submodules.go @@ -241,6 +241,9 @@ func (s *Server) updateSubmodule(ctx context.Context, quarantineRepo *localrepo. treeID = fullTree.OID currentBranchCommit, err := quarantineRepo.ResolveRevision(ctx, git.Revision(req.GetBranch())) if err != nil { + if errors.Is(err, git.ErrReferenceNotFound) { + return "", structerr.NewInvalidArgument("resolving submodule branch: %w", err) + } return "", fmt.Errorf("resolving submodule branch: %w", err) }