Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarthik Nayak <knayak@gitlab.com>2023-09-18 17:44:12 +0300
committerKarthik Nayak <knayak@gitlab.com>2023-09-18 17:49:28 +0300
commit0eab2fafab0cbc2163d1cf5f1c24d86c85310aa6 (patch)
treea206e86dbc6d026a5e28c5e4626b24f9e40c57a5
parent33b368ee3b09b757cd520e1a806d9bd2ebf80d7a (diff)
ref: Handle `git.ErrReferenceAmbiguous` in `FindBranch`
The `repo.GetReference` can throw a `git.ErrReferenceAmbiguous` error when the provided reference is ambiguous. We shouldn't treat these errors as internal errors as they would then be counted towards the error budget. So catch these errors and treat them as `NewInvalidArgument` errors.
-rw-r--r--internal/gitaly/service/ref/branches.go5
-rw-r--r--internal/gitaly/service/ref/branches_test.go9
2 files changed, 13 insertions, 1 deletions
diff --git a/internal/gitaly/service/ref/branches.go b/internal/gitaly/service/ref/branches.go
index d67b18cec..8bfa08e72 100644
--- a/internal/gitaly/service/ref/branches.go
+++ b/internal/gitaly/service/ref/branches.go
@@ -26,6 +26,11 @@ func (s *server) FindBranch(ctx context.Context, req *gitalypb.FindBranchRequest
if errors.Is(err, git.ErrReferenceNotFound) {
return &gitalypb.FindBranchResponse{}, nil
}
+
+ if errors.Is(err, git.ErrReferenceAmbiguous) {
+ return nil, structerr.NewInvalidArgument("target reference is ambiguous: %w", err)
+ }
+
return nil, err
}
commit, err := repo.ReadCommit(ctx, git.Revision(branchRef.Target))
diff --git a/internal/gitaly/service/ref/branches_test.go b/internal/gitaly/service/ref/branches_test.go
index 393e44552..318f27708 100644
--- a/internal/gitaly/service/ref/branches_test.go
+++ b/internal/gitaly/service/ref/branches_test.go
@@ -87,7 +87,8 @@ func TestFailedFindBranchRequest(t *testing.T) {
ctx := testhelper.Context(t)
cfg, client := setupRefService(t)
- repo, _ := gittest.CreateRepository(t, ctx, cfg)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("branch"), gittest.WithMessage("branch"))
testCases := []struct {
desc string
@@ -106,6 +107,12 @@ func TestFailedFindBranchRequest(t *testing.T) {
branchName: "",
expectedErr: status.Error(codes.InvalidArgument, "Branch name cannot be empty"),
},
+ {
+ desc: "ambiguous branch name",
+ repo: repo,
+ branchName: "b*",
+ expectedErr: structerr.NewInvalidArgument(`target reference is ambiguous: reference is ambiguous: conflicts with "refs/heads/branch"`),
+ },
}
for _, testCase := range testCases {