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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-08 13:09:22 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-15 16:15:28 +0300
commite877b1dff41f3f26400578dbd6a3382748e1e0da (patch)
treeade5de811fbfe6f0b4b596236ccd02d9694353ea
parentfebffcccaaecab983fd5fcac31f9114f04474b0e (diff)
repository: Demonstrate commit-graphs referencing pruned commits in GC
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/gc_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go
index 5d303ba73..df9f425de 100644
--- a/internal/gitaly/service/repository/gc_test.go
+++ b/internal/gitaly/service/repository/gc_test.go
@@ -1,6 +1,7 @@
package repository
import (
+ "bytes"
"fmt"
"os"
"path/filepath"
@@ -539,3 +540,47 @@ func TestGarbageCollectDeltaIslands(t *testing.T) {
return err
})
}
+
+func TestGarbageCollect_commitGraphsWithPrunedObjects(t *testing.T) {
+ t.Parallel()
+
+ ctx := testhelper.Context(t)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
+
+ // Write a first commit-graph that contains the root commit, only.
+ rootCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(), gittest.WithBranch("main"))
+ gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--reachable", "--split", "--changed-paths")
+
+ // Write a second, incremental commit-graph that contains a commit we're about to
+ // make unreachable and then prune.
+ unreachableCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(rootCommitID), gittest.WithBranch("main"))
+ gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--reachable", "--split=no-merge", "--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())
+ gittest.Exec(t, cfg, "-C", repoPath, "prune", "--expire", "now")
+
+ // 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))
+
+ // Given that GarbageCollect is an RPC that prunes objects it should know to fix up commit
+ // graphs...
+ //nolint:staticcheck
+ _, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: repoProto})
+ require.NoError(t, err)
+
+ // ... but as it turns out it doesn't.
+ stderr.Reset()
+ 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))
+}