Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t7418-submodule-sparse-gitmodules.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t7418-submodule-sparse-gitmodules.sh` 127 lines ยท 3969 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (C) 2018 Antonio Ospite 4 # 5 6 test_description='Test reading/writing .gitmodules when not in the working tree 7 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. 10 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. 13 ' 14 15 . ./test-lib.sh 16 17 test_expect_success 'setup' ' 18 git config --global protocol.file.allow always 19 ' 20 21 test_expect_success 'sparse checkout setup which hides .gitmodules' ' 22 git init upstream && 23 git init submodule && 24 (cd submodule && 25 echo file >file && 26 git add file && 27 test_tick && 28 git commit -m "Add file" 29 ) && 30 (cd upstream && 31 git submodule add ../submodule && 32 test_tick && 33 git commit -m "Add submodule" 34 ) && 35 git clone --template= upstream super && 36 (cd super && 37 mkdir .git/info && 38 cat >.git/info/sparse-checkout <<-\EOF && 39 /* 40 !/.gitmodules 41 EOF 42 git config core.sparsecheckout true && 43 git read-tree -m -u HEAD && 44 test_path_is_missing .gitmodules 45 ) 46 ' 47 48 test_expect_success 'reading gitmodules config file when it is not checked out' ' 49 echo "../submodule" >expect && 50 test-tool -C super submodule config-list submodule.submodule.url >actual && 51 test_cmp expect actual 52 ' 53 54 test_expect_success 'not writing gitmodules config file when it is not checked out' ' 55 test_must_fail test-tool -C super submodule config-set submodule.submodule.url newurl && 56 test_path_is_missing super/.gitmodules 57 ' 58 59 test_expect_success 'initialising submodule when the gitmodules config is not checked out' ' 60 test_must_fail git -C super config submodule.submodule.url && 61 git -C super submodule init && 62 git -C super config submodule.submodule.url >actual && 63 echo "$(pwd)/submodule" >expect && 64 test_cmp expect actual 65 ' 66 67 test_expect_success 'updating submodule when the gitmodules config is not checked out' ' 68 test_path_is_missing super/submodule/file && 69 git -C super submodule update && 70 test_cmp submodule/file super/submodule/file 71 ' 72 73 ORIG_SUBMODULE=$(git -C submodule rev-parse HEAD) 74 ORIG_UPSTREAM=$(git -C upstream rev-parse HEAD) 75 ORIG_SUPER=$(git -C super rev-parse HEAD) 76 77 test_expect_success 're-updating submodule when the gitmodules config is not checked out' ' 78 test_when_finished "git -C submodule reset --hard $ORIG_SUBMODULE; 79 git -C upstream reset --hard $ORIG_UPSTREAM; 80 git -C super reset --hard $ORIG_SUPER; 81 git -C upstream submodule update --remote; 82 git -C super pull; 83 git -C super submodule update --remote" && 84 (cd submodule && 85 echo file2 >file2 && 86 git add file2 && 87 test_tick && 88 git commit -m "Add file2 to submodule" 89 ) && 90 (cd upstream && 91 git submodule update --remote && 92 git add submodule && 93 test_tick && 94 git commit -m "Update submodule" 95 ) && 96 git -C super pull && 97 # The --for-status options reads the gitmodules config 98 git -C super submodule summary --for-status >actual && 99 rev1=$(git -C submodule rev-parse --short HEAD) && 100 rev2=$(git -C submodule rev-parse --short HEAD^) && 101 cat >expect <<-EOF && 102 * submodule ${rev1}...${rev2} (1): 103 < Add file2 to submodule 104 105 EOF 106 test_cmp expect actual && 107 # Test that the update actually succeeds 108 test_path_is_missing super/submodule/file2 && 109 git -C super submodule update && 110 test_cmp submodule/file2 super/submodule/file2 && 111 git -C super status --short >output && 112 test_must_be_empty output 113 ' 114 115 test_expect_success 'not adding submodules when the gitmodules config is not checked out' ' 116 git clone submodule new_submodule && 117 test_must_fail git -C super submodule add ../new_submodule && 118 test_path_is_missing .gitmodules 119 ' 120 121 # This test checks that the previous "git submodule add" did not leave the 122 # repository in a spurious state when it failed. 123 test_expect_success 'init submodule still works even after the previous add failed' ' 124 git -C super submodule init 125 ' 126 127 test_done