3 # Copyright (C) 2018 Antonio Ospite <ao2@ao2.it>
6 test_description
='Test reading/writing .gitmodules when not in the working tree
8 This test verifies that, when .gitmodules is in the current branch but is not
9 in the working tree reading from it still works but writing to it does not.
11 The test setup uses a sparse checkout, however the same scenario can be set up
12 also by committing .gitmodules and then just removing it from the filesystem.
15 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
=1
16 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
20 test_expect_success
'sparse checkout setup which hides .gitmodules' '
27 git commit -m "Add file"
30 git submodule add ../submodule &&
32 git commit -m "Add submodule"
34 git clone upstream super &&
36 cat >.git/info/sparse-checkout <<-\EOF &&
40 git config core.sparsecheckout true &&
41 git read-tree -m -u HEAD &&
42 test_path_is_missing .gitmodules
46 test_expect_success
'reading gitmodules config file when it is not checked out' '
47 echo "../submodule" >expect &&
48 git -C super submodule--helper config submodule.submodule.url >actual &&
49 test_cmp expect actual
52 test_expect_success
'not writing gitmodules config file when it is not checked out' '
53 test_must_fail git -C super submodule--helper config submodule.submodule.url newurl &&
54 test_path_is_missing super/.gitmodules
57 test_expect_success
'initialising submodule when the gitmodules config is not checked out' '
58 test_must_fail git -C super config submodule.submodule.url &&
59 git -C super submodule init &&
60 git -C super config submodule.submodule.url >actual &&
61 echo "$(pwd)/submodule" >expect &&
62 test_cmp expect actual
65 test_expect_success
'updating submodule when the gitmodules config is not checked out' '
66 test_path_is_missing super/submodule/file &&
67 git -C super submodule update &&
68 test_cmp submodule/file super/submodule/file
71 ORIG_SUBMODULE
=$
(git
-C submodule rev-parse HEAD
)
72 ORIG_UPSTREAM
=$
(git
-C upstream rev-parse HEAD
)
73 ORIG_SUPER
=$
(git
-C super rev-parse HEAD
)
75 test_expect_success
're-updating submodule when the gitmodules config is not checked out' '
76 test_when_finished "git -C submodule reset --hard $ORIG_SUBMODULE;
77 git -C upstream reset --hard $ORIG_UPSTREAM;
78 git -C super reset --hard $ORIG_SUPER;
79 git -C upstream submodule update --remote;
81 git -C super submodule update --remote" &&
86 git commit -m "Add file2 to submodule"
89 git submodule update --remote &&
92 git commit -m "Update submodule"
95 # The --for-status options reads the gitmodules config
96 git -C super submodule summary --for-status >actual &&
97 rev1=$(git -C submodule rev-parse --short HEAD) &&
98 rev2=$(git -C submodule rev-parse --short HEAD^) &&
100 * submodule ${rev1}...${rev2} (1):
101 < Add file2 to submodule
104 test_cmp expect actual &&
105 # Test that the update actually succeeds
106 test_path_is_missing super/submodule/file2 &&
107 git -C super submodule update &&
108 test_cmp submodule/file2 super/submodule/file2 &&
109 git -C super status --short >output &&
110 test_must_be_empty output
113 test_expect_success
'not adding submodules when the gitmodules config is not checked out' '
114 git clone submodule new_submodule &&
115 test_must_fail git -C super submodule add ../new_submodule &&
116 test_path_is_missing .gitmodules
119 # This test checks that the previous "git submodule add" did not leave the
120 # repository in a spurious state when it failed.
121 test_expect_success
'init submodule still works even after the previous add failed' '
122 git -C super submodule init