diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-08 13:09:22 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-15 16:15:30 +0300 |
commit | b7652e115a7b3ba95b500faa55d57d49c340e793 (patch) | |
tree | a7d210256cc4a3fe65cb8039e3f2f808b2a75852 | |
parent | 0920b15a01e1fb7ac54fd36ae29802b2855d9e4b (diff) |
repository: Demonstrate commit-graphs referencing pruned commits in PruneUnreachableObjects
Add a test to demonstrate a shortcoming we have with commit-graphs that
reference pruned commits: even though we're pruning commits, we don't
update the commit-graphs accordingly to drop references to any such
pruned commits.
-rw-r--r-- | internal/gitaly/service/repository/prune_unreachable_objects_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/prune_unreachable_objects_test.go b/internal/gitaly/service/repository/prune_unreachable_objects_test.go index 458682555..434be71d6 100644 --- a/internal/gitaly/service/repository/prune_unreachable_objects_test.go +++ b/internal/gitaly/service/repository/prune_unreachable_objects_test.go @@ -1,6 +1,8 @@ package repository import ( + "bytes" + "fmt" "os" "path/filepath" "testing" @@ -132,4 +134,36 @@ func TestPruneUnreachableObjects(t *testing.T) { require.Error(t, err) require.Equal(t, "fatal: Needed a single revision\n", string(output)) }) + + t.Run("repository with commit-graph", func(t *testing.T) { + repo, repoPath := gittest.CreateRepository(ctx, t, cfg) + + // Write two commits into the repository and create a commit-graph. The second + // commit will become unreachable and will be pruned, but will be contained in the + // commit-graph. + rootCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents()) + unreachableCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(rootCommitID), gittest.WithBranch("main")) + gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--reachable", "--split", "--changed-paths") + + // Reset the "main" branch back to the initial root commit ID and prune the now + // unreachable second commit. + gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/main", rootCommitID.String()) + + // Modify the modification time of the unreachable commit ID so that it will be + // pruned. + setObjectTime(t, repoPath, unreachableCommitID, time.Now().Add(-30*time.Minute)) + + _, err := client.PruneUnreachableObjects(ctx, &gitalypb.PruneUnreachableObjectsRequest{ + Repository: repo, + }) + require.NoError(t, err) + + // The commit-graph chain now refers to the pruned commit, and git-commit-graph(1) + // should complain about that. + var stderr bytes.Buffer + verifyCmd := gittest.NewCommand(t, cfg, "-C", repoPath, "commit-graph", "verify") + verifyCmd.Stderr = &stderr + require.EqualError(t, verifyCmd.Run(), "exit status 1") + require.Equal(t, stderr.String(), fmt.Sprintf("error: Could not read %[1]s\nfailed to parse commit %[1]s from object database for commit-graph\n", unreachableCommitID)) + }) } |