| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test with test-tool submodule is-active |
| 4 | |
| 5 | This test verifies that `test-tool submodule is-active` correctly identifies |
| 6 | submodules which are "active" and interesting to the user. |
| 7 | |
| 8 | This is a unit test of the submodule.c is_submodule_active() function, |
| 9 | which is also indirectly tested elsewhere. |
| 10 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
| 14 | test_expect_success 'setup' ' |
| 15 | git config --global protocol.file.allow always && |
| 16 | git init sub && |
| 17 | test_commit -C sub initial && |
| 18 | git init super && |
| 19 | test_commit -C super initial && |
| 20 | git -C super submodule add ../sub sub1 && |
| 21 | git -C super submodule add ../sub sub2 && |
| 22 | |
| 23 | # Remove submodule.<name>.active entries in order to test in an |
| 24 | # environment where only URLs are present in the config |
| 25 | git -C super config --unset submodule.sub1.active && |
| 26 | git -C super config --unset submodule.sub2.active && |
| 27 | |
| 28 | git -C super commit -a -m "add 2 submodules at sub{1,2}" |
| 29 | ' |
| 30 | |
| 31 | test_expect_success 'is-active works with urls' ' |
| 32 | test-tool -C super submodule is-active sub1 && |
| 33 | test-tool -C super submodule is-active sub2 && |
| 34 | |
| 35 | git -C super config --unset submodule.sub1.URL && |
| 36 | test_must_fail test-tool -C super submodule is-active sub1 && |
| 37 | git -C super config submodule.sub1.URL ../sub && |
| 38 | test-tool -C super submodule is-active sub1 |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'is-active works with submodule.<name>.active config' ' |
| 42 | test_when_finished "git -C super config --unset submodule.sub1.active" && |
| 43 | test_when_finished "git -C super config submodule.sub1.URL ../sub" && |
| 44 | |
| 45 | git -C super config --bool submodule.sub1.active "false" && |
| 46 | test_must_fail test-tool -C super submodule is-active sub1 && |
| 47 | |
| 48 | git -C super config --bool submodule.sub1.active "true" && |
| 49 | git -C super config --unset submodule.sub1.URL && |
| 50 | test-tool -C super submodule is-active sub1 |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'is-active handles submodule.active config missing a value' ' |
| 54 | cp super/.git/config super/.git/config.orig && |
| 55 | test_when_finished mv super/.git/config.orig super/.git/config && |
| 56 | |
| 57 | cat >>super/.git/config <<-\EOF && |
| 58 | [submodule] |
| 59 | active |
| 60 | EOF |
| 61 | |
| 62 | cat >expect <<-\EOF && |
| 63 | error: missing value for '\''submodule.active'\'' |
| 64 | EOF |
| 65 | test-tool -C super submodule is-active sub1 2>actual && |
| 66 | test_cmp expect actual |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'is-active works with basic submodule.active config' ' |
| 70 | test_when_finished "git -C super config submodule.sub1.URL ../sub" && |
| 71 | test_when_finished "git -C super config --unset-all submodule.active" && |
| 72 | |
| 73 | git -C super config --add submodule.active "." && |
| 74 | git -C super config --unset submodule.sub1.URL && |
| 75 | |
| 76 | test-tool -C super submodule is-active sub1 && |
| 77 | test-tool -C super submodule is-active sub2 |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'is-active correctly works with paths that are not submodules' ' |
| 81 | test_when_finished "git -C super config --unset-all submodule.active" && |
| 82 | |
| 83 | test_must_fail test-tool -C super submodule is-active not-a-submodule && |
| 84 | |
| 85 | git -C super config --add submodule.active "." && |
| 86 | test_must_fail test-tool -C super submodule is-active not-a-submodule |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'is-active works with exclusions in submodule.active config' ' |
| 90 | test_when_finished "git -C super config --unset-all submodule.active" && |
| 91 | |
| 92 | git -C super config --add submodule.active "." && |
| 93 | git -C super config --add submodule.active ":(exclude)sub1" && |
| 94 | |
| 95 | test_must_fail test-tool -C super submodule is-active sub1 && |
| 96 | test-tool -C super submodule is-active sub2 |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'is-active with submodule.active and submodule.<name>.active' ' |
| 100 | test_when_finished "git -C super config --unset-all submodule.active" && |
| 101 | test_when_finished "git -C super config --unset submodule.sub1.active" && |
| 102 | test_when_finished "git -C super config --unset submodule.sub2.active" && |
| 103 | |
| 104 | git -C super config --add submodule.active "sub1" && |
| 105 | git -C super config --bool submodule.sub1.active "false" && |
| 106 | git -C super config --bool submodule.sub2.active "true" && |
| 107 | |
| 108 | test_must_fail test-tool -C super submodule is-active sub1 && |
| 109 | test-tool -C super submodule is-active sub2 |
| 110 | ' |
| 111 | |
| 112 | test_expect_success 'is-active, submodule.active and submodule add' ' |
| 113 | test_when_finished "rm -rf super2" && |
| 114 | git init super2 && |
| 115 | test_commit -C super2 initial && |
| 116 | git -C super2 config --add submodule.active "sub*" && |
| 117 | |
| 118 | # submodule add should only add submodule.<name>.active |
| 119 | # to the config if not matched by the pathspec |
| 120 | git -C super2 submodule add ../sub sub1 && |
| 121 | test_must_fail git -C super2 config --get submodule.sub1.active && |
| 122 | |
| 123 | git -C super2 submodule add ../sub mod && |
| 124 | git -C super2 config --get submodule.mod.active |
| 125 | ' |
| 126 | |
| 127 | test_expect_success 'submodule add skips redundant active entry' ' |
| 128 | git init repo && |
| 129 | ( |
| 130 | cd repo && |
| 131 | git config submodule.active "lib/*" && |
| 132 | git commit --allow-empty -m init && |
| 133 | |
| 134 | git init ../lib-origin && |
| 135 | git -C ../lib-origin commit --allow-empty -m init && |
| 136 | |
| 137 | git submodule add ../lib-origin lib/foo && |
| 138 | test_must_fail git config --get submodule.lib/foo.active |
| 139 | ) |
| 140 | ' |
| 141 | |
| 142 | test_done |