diff options
author | James Fargher <jfargher@gitlab.com> | 2022-10-19 02:55:09 +0300 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2022-12-08 05:45:55 +0300 |
commit | 8c37a047357d8781f1253ab4955c442511c6711d (patch) | |
tree | f1af7d9c1e889dc5981aab838eca8911fbe06e0f | |
parent | 9e4865ed67b5b80fe2f9010ef4d6db3419205207 (diff) |
repository: Add WriteRef test case for overwriting truncated refswrite_ref_trunc
This case was specifically covered by gitlab rails.
-rw-r--r-- | internal/gitaly/service/repository/write_ref_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/write_ref_test.go b/internal/gitaly/service/repository/write_ref_test.go index c6b38d713..7458ea953 100644 --- a/internal/gitaly/service/repository/write_ref_test.go +++ b/internal/gitaly/service/repository/write_ref_test.go @@ -4,6 +4,7 @@ package repository import ( "bytes" + "os" "path/filepath" "testing" @@ -245,3 +246,25 @@ func TestWriteRef_missingRevisions(t *testing.T) { }) } } + +func TestWriteRef_forceTruncatedRef(t *testing.T) { + t.Parallel() + + ctx := testhelper.Context(t) + cfg, client := setupRepositoryServiceWithoutRepo(t) + + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + commitID := gittest.WriteCommit(t, cfg, repoPath) + require.NoError(t, os.WriteFile(filepath.Join(repoPath, "refs", "heads", "main"), []byte{}, os.ModePerm)) + + _, err := client.WriteRef(ctx, &gitalypb.WriteRefRequest{ + Repository: repo, + Ref: []byte("refs/heads/main"), + Revision: []byte(commitID), + }) + testhelper.RequireGrpcError(t, testhelper.GitalyOrPraefect( + helper.ErrInternalf(`error when running update-ref command: state update to "commit" failed: EOF, stderr: "fatal: commit: cannot lock ref 'refs/heads/main': unable to resolve reference 'refs/heads/main': reference broken\n"`), + helper.ErrInternalf(`error when running update-ref command: git update-ref: exit status 128, stderr: "fatal: commit: cannot lock ref 'refs/heads/main': unable to resolve reference 'refs/heads/main': reference broken\n"`), + ), err) +} |