diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-08 13:09:22 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-13 14:16:15 +0300 |
commit | 125b89182dd190c73951e77c79707533909b91c3 (patch) | |
tree | aa84d66e3e885bece3db8101a761b6c2a44fba77 | |
parent | 8468d8666ba052c7b379a260e776a1eeca34323a (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)) + }) } |