diff options
author | Ahmad Sherif <ahmad@gitlab.com> | 2023-09-26 12:02:01 +0300 |
---|---|---|
committer | Ahmad Sherif <ahmad@gitlab.com> | 2023-09-26 12:13:51 +0300 |
commit | 086f03f68cad3560c7fd06a825999b0841dbe898 (patch) | |
tree | d623b816c23d7fd7dffc379d6746423bc21353a7 | |
parent | 0d02e2dfdd429b7c5cda79c8f2af1132566ade65 (diff) |
Fix blameLineCountErrorRegexp
Follow-up on https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6361
-rw-r--r-- | internal/gitaly/service/commit/raw_blame.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/commit/raw_blame_test.go | 11 |
2 files changed, 7 insertions, 6 deletions
diff --git a/internal/gitaly/service/commit/raw_blame.go b/internal/gitaly/service/commit/raw_blame.go index 09c1b8cc4..d4254bc50 100644 --- a/internal/gitaly/service/commit/raw_blame.go +++ b/internal/gitaly/service/commit/raw_blame.go @@ -16,7 +16,7 @@ import ( var ( validBlameRange = regexp.MustCompile(`\A\d+,\d+\z`) - blameLineCountErrorRegexp = regexp.MustCompile("^fatal: file .* has only (\\d) lines?\n$") + blameLineCountErrorRegexp = regexp.MustCompile("^fatal: file .* has only (\\d+) lines?\n$") ) func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitService_RawBlameServer) error { diff --git a/internal/gitaly/service/commit/raw_blame_test.go b/internal/gitaly/service/commit/raw_blame_test.go index cb0e5b76b..b3da3d99e 100644 --- a/internal/gitaly/service/commit/raw_blame_test.go +++ b/internal/gitaly/service/commit/raw_blame_test.go @@ -3,6 +3,7 @@ package commit import ( "fmt" "io" + "strings" "testing" "github.com/stretchr/testify/require" @@ -119,9 +120,9 @@ func TestRawBlame(t *testing.T) { setup: func(t *testing.T) setupData { repo, repoPath := gittest.CreateRepository(t, ctx, cfg) - // We write a file with three lines, only, but the request asks us to blame line 10. + // We write a file with 10 lines, only, but the request asks us to blame line 11. commit := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( - gittest.TreeEntry{Path: "path", Mode: "100644", Content: "a\nb\nc\n"}, + gittest.TreeEntry{Path: "path", Mode: "100644", Content: strings.Repeat("a\n", 10)}, )) return setupData{ @@ -129,17 +130,17 @@ func TestRawBlame(t *testing.T) { Repository: repo, Revision: []byte(commit), Path: []byte("path"), - Range: []byte("10,10"), + Range: []byte("11,11"), }, expectedErr: testhelper.ToInterceptedMetadata( structerr.NewInvalidArgument("range is outside of the file length"). WithMetadata("revision", commit.String()). WithMetadata("path", "path"). - WithMetadata("lines", 3). + WithMetadata("lines", 10). WithDetail(&gitalypb.RawBlameError{ Error: &gitalypb.RawBlameError_OutOfRange{ OutOfRange: &gitalypb.RawBlameError_OutOfRangeError{ - ActualLines: 3, + ActualLines: 10, }, }, }), |