Skip to content

Commit 9090017

Browse files
pks-tgitster
authored andcommitted
t7700: add tests for --keep-unreachable
We don't have any tests for `git repack --keep-unreachable`. Add three tests that exercise its behaviour with different packed states for the unreachable object. Note that the last test is failing. This will be fixed in the next commit. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f93ff17 commit 9090017

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

t/t7700-repack.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,4 +826,77 @@ test_expect_success '-n overrides repack.updateServerInfo=true' '
826826
test_server_info_missing
827827
'
828828

829+
expect_object_count () {
830+
find .git/objects \( -type d \( -name pack -o -name info \) -prune \) -o -type f -print >objects &&
831+
test_line_count = "$1" objects
832+
}
833+
834+
expect_object_in_idx () {
835+
git verify-pack -v "$1" >objects &&
836+
test_grep "^$2" objects
837+
}
838+
839+
test_expect_success '--keep-unreachable appends unreachable packed objects to new pack' '
840+
test_when_finished "rm -rf repo" &&
841+
git init repo &&
842+
(
843+
cd repo &&
844+
git config set core.logAllRefUpdates false &&
845+
846+
# Set up the repo so that all objects, including the
847+
# unreachable one, are packed.
848+
test_commit --no-tag unreachable &&
849+
git repack -ad &&
850+
expect_object_count 0 &&
851+
unreachable_oid=$(git rev-parse --verify HEAD) &&
852+
git commit --amend --message rewritten &&
853+
854+
git repack -ad --keep-unreachable &&
855+
expect_object_count 0 &&
856+
expect_object_in_idx .git/objects/pack/*.idx "$unreachable_oid"
857+
)
858+
'
859+
860+
test_expect_success '--keep-unreachable packs unreachable loose object with existing packs' '
861+
test_when_finished "rm -rf repo" &&
862+
git init repo &&
863+
(
864+
cd repo &&
865+
git config set core.logAllRefUpdates false &&
866+
867+
# Set up the repo so that we have an existing packfile with
868+
# reachable objects, only. The unreachable object as well as
869+
# the rewritten commit are both loose.
870+
test_commit --no-tag initial &&
871+
git repack -ad &&
872+
git commit --amend --message unreachable &&
873+
unreachable_oid=$(git rev-parse --verify HEAD) &&
874+
git commit --amend --message rewritten &&
875+
expect_object_count 2 &&
876+
877+
git repack -ad --keep-unreachable &&
878+
expect_object_count 0 &&
879+
expect_object_in_idx .git/objects/pack/*.idx "$unreachable_oid"
880+
)
881+
'
882+
883+
test_expect_failure '--keep-unreachable packs unreachable loose object without existing packs' '
884+
test_when_finished "rm -rf repo" &&
885+
git init repo &&
886+
(
887+
cd repo &&
888+
git config set core.logAllRefUpdates false &&
889+
890+
# Set up the repo so that all objects are unpacked.
891+
test_commit --no-tag unreachable &&
892+
unreachable_oid=$(git rev-parse --verify HEAD) &&
893+
git commit --amend --message rewritten &&
894+
expect_object_count 4 &&
895+
896+
git repack -ad --keep-unreachable &&
897+
expect_object_count 0 &&
898+
expect_object_in_idx .git/objects/pack/*.idx "$unreachable_oid"
899+
)
900+
'
901+
829902
test_done

0 commit comments

Comments
 (0)