Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t7424-submodule-mixed-ref-formats.sh
blobb43ef2ba675b8d340ceed10ea12862817aeb1120
1 #!/bin/sh
3 test_description='submodules handle mixed ref storage formats'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_ref_format () {
9 echo "$2" >expect &&
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"
17 then
18 continue
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" &&
31 git init parent &&
33 cd parent &&
34 test_commit 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" &&
44 git init submodule &&
45 test_commit -C submodule submodule-initial &&
46 git init upstream &&
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" &&
55 git init submodule &&
56 test_commit -C submodule submodule-initial &&
57 git init upstream &&
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
62 # ref format.
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
68 # submodules.
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" &&
78 git init submodule &&
79 test_commit -C submodule submodule-initial &&
80 git init upstream &&
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" &&
93 git init submodule &&
94 test_commit -C submodule submodule-initial &&
95 git init main &&
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 &&
119 git init upstream &&
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
142 done
144 test_done