]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t6020-bundle-misc.sh
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / t / t6020-bundle-misc.sh
index b13e8a52a93a4e96cde54c5076c19960a4d41a2c..833205125abf5a2673ae0cbede62653fbfd151c8 100755 (executable)
@@ -122,6 +122,8 @@ format_and_save_expect () {
        sed -e 's/Z$//' >expect
 }
 
+HASH_MESSAGE="The bundle uses this hash algorithm: $GIT_DEFAULT_HASH"
+
 #            (C)   (D, pull/1/head, topic/1)
 #             o --- o
 #            /       \                              (L)
@@ -194,11 +196,12 @@ test_expect_success 'create bundle from special rev: main^!' '
 
        git bundle verify special-rev.bdl |
                make_user_friendly_and_stable_output >actual &&
-       format_and_save_expect <<-\EOF &&
+       format_and_save_expect <<-EOF &&
        The bundle contains this ref:
        <COMMIT-P> refs/heads/main
        The bundle requires this ref:
        <COMMIT-O> Z
+       $HASH_MESSAGE
        EOF
        test_cmp expect actual &&
 
@@ -215,12 +218,13 @@ test_expect_success 'create bundle with --max-count option' '
 
        git bundle verify max-count.bdl |
                make_user_friendly_and_stable_output >actual &&
-       format_and_save_expect <<-\EOF &&
+       format_and_save_expect <<-EOF &&
        The bundle contains these 2 refs:
        <COMMIT-P> refs/heads/main
        <TAG-1> refs/tags/v1
        The bundle requires this ref:
        <COMMIT-O> Z
+       $HASH_MESSAGE
        EOF
        test_cmp expect actual &&
 
@@ -240,7 +244,7 @@ test_expect_success 'create bundle with --since option' '
 
        git bundle verify since.bdl |
                make_user_friendly_and_stable_output >actual &&
-       format_and_save_expect <<-\EOF &&
+       format_and_save_expect <<-EOF &&
        The bundle contains these 5 refs:
        <COMMIT-P> refs/heads/main
        <COMMIT-N> refs/heads/release
@@ -250,6 +254,7 @@ test_expect_success 'create bundle with --since option' '
        The bundle requires these 2 refs:
        <COMMIT-M> Z
        <COMMIT-K> Z
+       $HASH_MESSAGE
        EOF
        test_cmp expect actual &&
 
@@ -267,11 +272,12 @@ test_expect_success 'create bundle 1 - no prerequisites' '
        EOF
        git bundle create stdin-1.bdl --stdin <input &&
 
-       cat >expect <<-\EOF &&
+       format_and_save_expect <<-EOF &&
        The bundle contains these 2 refs:
        <COMMIT-D> refs/heads/topic/1
        <COMMIT-H> refs/heads/topic/2
        The bundle records a complete history.
+       $HASH_MESSAGE
        EOF
 
        # verify bundle, which has no prerequisites
@@ -308,13 +314,14 @@ test_expect_success 'create bundle 2 - has prerequisites' '
                --stdin \
                release <input &&
 
-       format_and_save_expect <<-\EOF &&
+       format_and_save_expect <<-EOF &&
        The bundle contains this ref:
        <COMMIT-N> refs/heads/release
        The bundle requires these 3 refs:
        <COMMIT-D> Z
        <COMMIT-E> Z
        <COMMIT-G> Z
+       $HASH_MESSAGE
        EOF
 
        git bundle verify 2.bdl |
@@ -367,13 +374,14 @@ test_expect_success 'create bundle 3 - two refs, same object' '
                --stdin \
                main HEAD <input &&
 
-       format_and_save_expect <<-\EOF &&
+       format_and_save_expect <<-EOF &&
        The bundle contains these 2 refs:
        <COMMIT-P> refs/heads/main
        <COMMIT-P> HEAD
        The bundle requires these 2 refs:
        <COMMIT-M> Z
        <COMMIT-K> Z
+       $HASH_MESSAGE
        EOF
 
        git bundle verify 3.bdl |
@@ -409,12 +417,13 @@ test_expect_success 'create bundle 4 - with tags' '
                --stdin \
                --all <input &&
 
-       cat >expect <<-\EOF &&
+       cat >expect <<-EOF &&
        The bundle contains these 3 refs:
        <TAG-1> refs/tags/v1
        <TAG-2> refs/tags/v2
        <TAG-3> refs/tags/v3
        The bundle records a complete history.
+       $HASH_MESSAGE
        EOF
 
        git bundle verify 4.bdl |
@@ -475,4 +484,79 @@ test_expect_success 'clone from bundle' '
        test_cmp expect actual
 '
 
+test_expect_success 'unfiltered bundle with --objects' '
+       git bundle create all-objects.bdl \
+               --all --objects &&
+       git bundle create all.bdl \
+               --all &&
+
+       # Compare the headers of these files.
+       sed -n -e "/^$/q" -e "p" all.bdl >expect &&
+       sed -n -e "/^$/q" -e "p" all-objects.bdl >actual &&
+       test_cmp expect actual
+'
+
+for filter in "blob:none" "tree:0" "tree:1" "blob:limit=100"
+do
+       test_expect_success "filtered bundle: $filter" '
+               test_when_finished rm -rf .git/objects/pack cloned unbundled &&
+               git bundle create partial.bdl \
+                       --all \
+                       --filter=$filter &&
+
+               git bundle verify partial.bdl >unfiltered &&
+               make_user_friendly_and_stable_output <unfiltered >actual &&
+
+               cat >expect <<-EOF &&
+               The bundle contains these 10 refs:
+               <COMMIT-P> refs/heads/main
+               <COMMIT-N> refs/heads/release
+               <COMMIT-D> refs/heads/topic/1
+               <COMMIT-H> refs/heads/topic/2
+               <COMMIT-D> refs/pull/1/head
+               <COMMIT-G> refs/pull/2/head
+               <TAG-1> refs/tags/v1
+               <TAG-2> refs/tags/v2
+               <TAG-3> refs/tags/v3
+               <COMMIT-P> HEAD
+               The bundle records a complete history.
+               $HASH_MESSAGE
+               The bundle uses this filter: $filter
+               EOF
+               test_cmp expect actual &&
+
+               test_config uploadpack.allowfilter 1 &&
+               test_config uploadpack.allowanysha1inwant 1 &&
+               git clone --no-local --filter=$filter --bare "file://$(pwd)" cloned &&
+
+               git init unbundled &&
+               git -C unbundled bundle unbundle ../partial.bdl >ref-list.txt &&
+               ls unbundled/.git/objects/pack/pack-*.promisor >promisor &&
+               test_line_count = 1 promisor &&
+
+               # Count the same number of reachable objects.
+               reflist=$(git for-each-ref --format="%(objectname)") &&
+               git rev-list --objects --filter=$filter --missing=allow-any \
+                       $reflist >expect &&
+               for repo in cloned unbundled
+               do
+                       git -C $repo rev-list --objects --missing=allow-any \
+                               $reflist >actual &&
+                       test_cmp expect actual || return 1
+               done
+       '
+done
+
+# NEEDSWORK: 'git clone --bare' should be able to clone from a filtered
+# bundle, but that requires a change to promisor/filter config options.
+# For now, we fail gracefully with a helpful error. This behavior can be
+# changed in the future to succeed as much as possible.
+test_expect_success 'cloning from filtered bundle has useful error' '
+       git bundle create partial.bdl \
+               --all \
+               --filter=blob:none &&
+       test_must_fail git clone --bare partial.bdl partial 2>err &&
+       grep "cannot clone from filtered bundle" err
+'
+
 test_done