3 test_description
='submodules handle mixed ref storage formats'
5 TEST_PASSES_SANITIZE_LEAK
=true
10 git
-C "$1" rev-parse
--show-ref-format >actual
&&
11 test_cmp expect actual
14 for OTHER_FORMAT
in files reftable
16 if test "$OTHER_FORMAT" = "$GIT_DEFAULT_REF_FORMAT"
21 test_expect_success
'setup' '
22 git config set --global protocol.file.allow always &&
23 # Some tests migrate the ref storage format, which does not work with
24 # reflogs at the time of writing these tests.
25 git config set --global core.logAllRefUpdates false
28 test_expect_success
'add existing repository with different ref storage format' '
29 test_when_finished "rm -rf parent" &&
35 git init --ref-format=$OTHER_FORMAT submodule &&
36 test_commit -C submodule submodule &&
37 git submodule add ./submodule
41 test_expect_success
'add submodules with different ref storage format' '
42 test_when_finished "rm -rf submodule upstream" &&
45 test_commit -C submodule submodule-initial &&
47 test_ref_format upstream "$GIT_DEFAULT_REF_FORMAT" &&
48 git -C upstream submodule add --ref-format="$OTHER_FORMAT" "file://$(pwd)/submodule" &&
49 test_ref_format upstream/submodule "$OTHER_FORMAT"
52 test_expect_success
'recursive clone propagates ref storage format' '
53 test_when_finished "rm -rf submodule upstream downstream" &&
56 test_commit -C submodule submodule-initial &&
58 git -C upstream submodule add "file://$(pwd)/submodule" &&
59 git -C upstream commit -am "add submodule" &&
61 # The upstream repository and its submodule should be using the default
63 test_ref_format upstream "$GIT_DEFAULT_REF_FORMAT" &&
64 test_ref_format upstream/submodule "$GIT_DEFAULT_REF_FORMAT" &&
66 # The cloned repositories should use the other ref format that we have
67 # specified via `--ref-format`. The option should propagate to cloned
69 git clone --ref-format=$OTHER_FORMAT --recurse-submodules \
70 upstream downstream &&
71 test_ref_format downstream "$OTHER_FORMAT" &&
72 test_ref_format downstream/submodule "$OTHER_FORMAT"
75 test_expect_success
'clone submodules with different ref storage format' '
76 test_when_finished "rm -rf submodule upstream downstream" &&
79 test_commit -C submodule submodule-initial &&
81 git -C upstream submodule add "file://$(pwd)/submodule" &&
82 git -C upstream commit -m "upstream submodule" &&
84 git clone --no-recurse-submodules "file://$(pwd)/upstream" downstream &&
85 test_ref_format downstream "$GIT_DEFAULT_REF_FORMAT" &&
86 git -C downstream submodule update --init --ref-format=$OTHER_FORMAT &&
87 test_ref_format downstream/submodule "$OTHER_FORMAT"
90 test_expect_success
'status with mixed submodule ref storages' '
91 test_when_finished "rm -rf submodule main" &&
94 test_commit -C submodule submodule-initial &&
96 git -C main submodule add "file://$(pwd)/submodule" &&
97 git -C main commit -m "add submodule" &&
98 git -C main/submodule refs migrate --ref-format=$OTHER_FORMAT &&
100 # The main repository should use the default ref format now, whereas
101 # the submodule should use the other format.
102 test_ref_format main "$GIT_DEFAULT_REF_FORMAT" &&
103 test_ref_format main/submodule "$OTHER_FORMAT" &&
105 cat >expect <<-EOF &&
106 $(git -C main/submodule rev-parse HEAD) submodule (submodule-initial)
108 git -C main submodule status >actual &&
109 test_cmp expect actual
112 test_expect_success
'recursive pull with mixed formats' '
113 test_when_finished "rm -rf submodule upstream downstream" &&
115 # Set up the initial structure with an upstream repository that has a
116 # submodule, as well as a downstream clone of the upstream repository.
117 git init submodule &&
118 test_commit -C submodule submodule-initial &&
120 git -C upstream submodule add "file://$(pwd)/submodule" &&
121 git -C upstream commit -m "upstream submodule" &&
123 # Clone the upstream repository such that the main repo and its
124 # submodules have different formats.
125 git clone --no-recurse-submodules "file://$(pwd)/upstream" downstream &&
126 git -C downstream submodule update --init --ref-format=$OTHER_FORMAT &&
127 test_ref_format downstream "$GIT_DEFAULT_REF_FORMAT" &&
128 test_ref_format downstream/submodule "$OTHER_FORMAT" &&
130 # Update the upstream submodule as well as the owning repository such
131 # that we can do a recursive pull.
132 test_commit -C submodule submodule-update &&
133 git -C upstream/submodule pull &&
134 git -C upstream commit -am "update the submodule" &&
136 git -C downstream pull --recurse-submodules &&
137 git -C upstream/submodule rev-parse HEAD >expect &&
138 git -C downstream/submodule rev-parse HEAD >actual &&
139 test_cmp expect actual