Git fork
at reftables-rust 143 lines 4.8 kB view raw
1#!/bin/sh 2 3test_description='submodules handle mixed ref storage formats' 4 5. ./test-lib.sh 6 7test_ref_format () { 8 echo "$2" >expect && 9 git -C "$1" rev-parse --show-ref-format >actual && 10 test_cmp expect actual 11} 12 13for OTHER_FORMAT in files reftable 14do 15 if test "$OTHER_FORMAT" = "$GIT_DEFAULT_REF_FORMAT" 16 then 17 continue 18 fi 19 20test_expect_success 'setup' ' 21 git config set --global protocol.file.allow always && 22 # Some tests migrate the ref storage format, which does not work with 23 # reflogs at the time of writing these tests. 24 git config set --global core.logAllRefUpdates false 25' 26 27test_expect_success 'add existing repository with different ref storage format' ' 28 test_when_finished "rm -rf parent" && 29 30 git init parent && 31 ( 32 cd parent && 33 test_commit parent && 34 git init --ref-format=$OTHER_FORMAT submodule && 35 test_commit -C submodule submodule && 36 git submodule add ./submodule 37 ) 38' 39 40test_expect_success 'add submodules with different ref storage format' ' 41 test_when_finished "rm -rf submodule upstream" && 42 43 git init submodule && 44 test_commit -C submodule submodule-initial && 45 git init upstream && 46 test_ref_format upstream "$GIT_DEFAULT_REF_FORMAT" && 47 git -C upstream submodule add --ref-format="$OTHER_FORMAT" "file://$(pwd)/submodule" && 48 test_ref_format upstream/submodule "$OTHER_FORMAT" 49' 50 51test_expect_success 'recursive clone propagates ref storage format' ' 52 test_when_finished "rm -rf submodule upstream downstream" && 53 54 git init submodule && 55 test_commit -C submodule submodule-initial && 56 git init upstream && 57 git -C upstream submodule add "file://$(pwd)/submodule" && 58 git -C upstream commit -am "add submodule" && 59 60 # The upstream repository and its submodule should be using the default 61 # ref format. 62 test_ref_format upstream "$GIT_DEFAULT_REF_FORMAT" && 63 test_ref_format upstream/submodule "$GIT_DEFAULT_REF_FORMAT" && 64 65 # The cloned repositories should use the other ref format that we have 66 # specified via `--ref-format`. The option should propagate to cloned 67 # submodules. 68 git clone --ref-format=$OTHER_FORMAT --recurse-submodules \ 69 upstream downstream && 70 test_ref_format downstream "$OTHER_FORMAT" && 71 test_ref_format downstream/submodule "$OTHER_FORMAT" 72' 73 74test_expect_success 'clone submodules with different ref storage format' ' 75 test_when_finished "rm -rf submodule upstream downstream" && 76 77 git init submodule && 78 test_commit -C submodule submodule-initial && 79 git init upstream && 80 git -C upstream submodule add "file://$(pwd)/submodule" && 81 git -C upstream commit -m "upstream submodule" && 82 83 git clone --no-recurse-submodules "file://$(pwd)/upstream" downstream && 84 test_ref_format downstream "$GIT_DEFAULT_REF_FORMAT" && 85 git -C downstream submodule update --init --ref-format=$OTHER_FORMAT && 86 test_ref_format downstream/submodule "$OTHER_FORMAT" 87' 88 89test_expect_success 'status with mixed submodule ref storages' ' 90 test_when_finished "rm -rf submodule main" && 91 92 git init submodule && 93 test_commit -C submodule submodule-initial && 94 git init main && 95 git -C main submodule add "file://$(pwd)/submodule" && 96 git -C main commit -m "add submodule" && 97 git -C main/submodule refs migrate --ref-format=$OTHER_FORMAT && 98 99 # The main repository should use the default ref format now, whereas 100 # the submodule should use the other format. 101 test_ref_format main "$GIT_DEFAULT_REF_FORMAT" && 102 test_ref_format main/submodule "$OTHER_FORMAT" && 103 104 cat >expect <<-EOF && 105 $(git -C main/submodule rev-parse HEAD) submodule (submodule-initial) 106 EOF 107 git -C main submodule status >actual && 108 test_cmp expect actual 109' 110 111test_expect_success 'recursive pull with mixed formats' ' 112 test_when_finished "rm -rf submodule upstream downstream" && 113 114 # Set up the initial structure with an upstream repository that has a 115 # submodule, as well as a downstream clone of the upstream repository. 116 git init submodule && 117 test_commit -C submodule submodule-initial && 118 git init upstream && 119 git -C upstream submodule add "file://$(pwd)/submodule" && 120 git -C upstream commit -m "upstream submodule" && 121 122 # Clone the upstream repository such that the main repo and its 123 # submodules have different formats. 124 git clone --no-recurse-submodules "file://$(pwd)/upstream" downstream && 125 git -C downstream submodule update --init --ref-format=$OTHER_FORMAT && 126 test_ref_format downstream "$GIT_DEFAULT_REF_FORMAT" && 127 test_ref_format downstream/submodule "$OTHER_FORMAT" && 128 129 # Update the upstream submodule as well as the owning repository such 130 # that we can do a recursive pull. 131 test_commit -C submodule submodule-update && 132 git -C upstream/submodule pull && 133 git -C upstream commit -am "update the submodule" && 134 135 git -C downstream pull --recurse-submodules && 136 git -C upstream/submodule rev-parse HEAD >expect && 137 git -C downstream/submodule rev-parse HEAD >actual && 138 test_cmp expect actual 139' 140 141done 142 143test_done