Commit e60e2e94 authored by Kirill Smelkov's avatar Kirill Smelkov

pull: test: Fix thinko when pruning test backup.git

Pull test verifies that pulled tag objects become gone after becoming
represented via specially-crafted commits. The "gone" is verified by
removing all unreachable objects and asserting that looking up an object
by original tag sha1 results in error.

However there was a thinko in "removing all unreachable objects" - this
step was implemented via `git prune`, but as documented, `git prune`
removes only loose unreachable objects, while unreachable objects that
are already in packs remain intact. From `git prune --help`:

    Note that unreachable, packed objects will remain. If this is not desired, see git-repack(1).

So previously we were lucky that running the tests did not pull objects
from test repositories into packs and plain `git prune` was enough.
However starting from Git 2.31 fetching objects from test repositories
pulls some of them as packs and the test starts to fail because original
tag object remains alive:

    === RUN   TestPullRestore
    # creating root commit
    # building "already-have" index
    # git  b0       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/0/dir/empty repo.git
    # file b0       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/0/dir/empty repo.git/HEAD
    # file b0       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/0/dir/empty repo.git/config
    # file b0       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/0/dir/empty repo.git/description
    # file b0       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/0/dir/empty repo.git/info/exclude
    # file b0       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/0/dir/empty repo.git/refs/.keep
    # building "already-have" index
    # git  b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/HEAD
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/config
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/description
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/info/exclude
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/packed-refs
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/refs/tags/tag-to-blob
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/hello.git/refs/test/ref-to-tree
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir/world.txt
    # git  b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/empty repo.git
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/empty repo.git/HEAD
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/empty repo.git/config
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/empty repo.git/description
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/empty repo.git/info/exclude
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/empty repo.git/refs/.keep
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/file 2
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/nongit.git/latest
    # git  b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/repo with+fragile name %αβγ.git
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/repo with+fragile name %αβγ.git/HEAD
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/repo with+fragile name %αβγ.git/config
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/repo with+fragile name %αβγ.git/description
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/repo with+fragile name %αβγ.git/info/exclude
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/dir 2 + β/repo with+fragile name %αβγ.git/refs/heads/master
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/file
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/file with space + α
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/fileexec
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/symlink.dir
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/symlink.file
    # file b1       <- /home/kirr/src/neo/src/lab.nexedi.com/kirr/git-backup/testdata/1/symlink.missing
        git-backup_test.go:203: tag f735011c9fcece41219729a33f7876cd8791f659 still present in backup.git after git-prune
    --- FAIL: TestPullRestore (0.14s)

Bisecting shows that particular behaviour of pulling into packs from test
repositories starts to happen after https://git.kernel.org/pub/scm/git/git.git/commit/?id=5476e1efded571e374cd97c7d69f17962ba1c44f .
But as explained in the beginning it is not a Git bug as in the general case just `git prune` is not enough to remove all unreachable objects.

-> Fix it by accompanying `git prune` with `git repack -ad` that removes unreachable objects from the packs.

NOTE just `git repack -ad` is not enough as it puts in packs only reachable
objects, so any unreachable objects that were loose before repacking, will
remain alive.
parent c9db60e8
// Copyright (C) 2015-2021 Nexedi SA and Contributors. // Copyright (C) 2015-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -184,7 +184,8 @@ func TestPullRestore(t *testing.T) { ...@@ -184,7 +184,8 @@ func TestPullRestore(t *testing.T) {
} }
// prune all non-reachable objects (e.g. tags just pulled - they were encoded as commits) // prune all non-reachable objects (e.g. tags just pulled - they were encoded as commits)
xgit(ctx, "prune") xgit(ctx, "prune") // remove unreachable loose objects
xgit(ctx, "repack", "-ad") // remove unreachable objects in packs
// verify backup repo is all ok // verify backup repo is all ok
xgit(ctx, "fsck") xgit(ctx, "fsck")
...@@ -198,12 +199,12 @@ func TestPullRestore(t *testing.T) { ...@@ -198,12 +199,12 @@ func TestPullRestore(t *testing.T) {
} }
gerr, _, _ := ggit(ctx, "cat-file", "-p", nc.sha1) gerr, _, _ := ggit(ctx, "cat-file", "-p", nc.sha1)
if gerr == nil { if gerr == nil {
t.Fatalf("tag %s still present in backup.git after git-prune", nc.sha1) t.Fatalf("tag %s still present in backup.git after git-prune + `git-repack -ad`", nc.sha1)
} }
} }
// reopen backup repository - to avoid having stale cache with present // reopen backup repository - to avoid having stale cache with present
// objects we deleted above with `git prune` // objects we deleted above with `git prune` + `git repack -ad`
gb, err = git.OpenRepository(".") gb, err = git.OpenRepository(".")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment