| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test the `scalar clone` subcommand' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "${TEST_DIRECTORY}/lib-terminal.sh" |
| 7 | |
| 8 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true" |
| 9 | export GIT_TEST_MAINT_SCHEDULER |
| 10 | |
| 11 | # index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are |
| 12 | # incompatible: the shared index gets a null OID and fails to |
| 13 | # load on re-read. Every test here uses scalar clone. |
| 14 | sane_unset GIT_TEST_SPLIT_INDEX |
| 15 | |
| 16 | test_expect_success 'set up repository to clone' ' |
| 17 | rm -rf .git && |
| 18 | git init to-clone && |
| 19 | ( |
| 20 | cd to-clone && |
| 21 | git branch -m base && |
| 22 | |
| 23 | test_commit first && |
| 24 | test_commit second && |
| 25 | test_commit third && |
| 26 | |
| 27 | git switch -c parallel first && |
| 28 | mkdir -p 1/2 && |
| 29 | test_commit 1/2/3 && |
| 30 | |
| 31 | git switch base && |
| 32 | |
| 33 | # By default, permit |
| 34 | git config uploadpack.allowfilter true && |
| 35 | git config uploadpack.allowanysha1inwant true |
| 36 | ) |
| 37 | ' |
| 38 | |
| 39 | cleanup_clone() { |
| 40 | rm -rf "$1" |
| 41 | } |
| 42 | |
| 43 | test_expect_success 'creates content in enlistment root' ' |
| 44 | enlistment=cloned && |
| 45 | |
| 46 | scalar clone "file://$(pwd)/to-clone" $enlistment && |
| 47 | ls -A $enlistment >enlistment-root && |
| 48 | test_line_count = 1 enlistment-root && |
| 49 | test_path_is_dir $enlistment/src && |
| 50 | test_path_is_dir $enlistment/src/.git && |
| 51 | |
| 52 | cleanup_clone $enlistment |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'with spaces' ' |
| 56 | enlistment="cloned with space" && |
| 57 | |
| 58 | scalar clone "file://$(pwd)/to-clone" "$enlistment" && |
| 59 | test_path_is_dir "$enlistment" && |
| 60 | test_path_is_dir "$enlistment/src" && |
| 61 | test_path_is_dir "$enlistment/src/.git" && |
| 62 | |
| 63 | cleanup_clone "$enlistment" |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'partial clone if supported by server' ' |
| 67 | enlistment=partial-clone && |
| 68 | |
| 69 | scalar clone "file://$(pwd)/to-clone" $enlistment && |
| 70 | |
| 71 | ( |
| 72 | cd $enlistment/src && |
| 73 | |
| 74 | # Two promisor packs: one for refs, the other for blobs |
| 75 | ls .git/objects/pack/pack-*.promisor >promisorlist && |
| 76 | test_line_count = 2 promisorlist |
| 77 | ) && |
| 78 | |
| 79 | cleanup_clone $enlistment |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'fall back on full clone if partial unsupported' ' |
| 83 | enlistment=no-partial-support && |
| 84 | |
| 85 | test_config -C to-clone uploadpack.allowfilter false && |
| 86 | test_config -C to-clone uploadpack.allowanysha1inwant false && |
| 87 | |
| 88 | scalar clone "file://$(pwd)/to-clone" $enlistment 2>err && |
| 89 | test_grep "filtering not recognized by server, ignoring" err && |
| 90 | |
| 91 | ( |
| 92 | cd $enlistment/src && |
| 93 | |
| 94 | # Still get a refs promisor file, but none for blobs |
| 95 | ls .git/objects/pack/pack-*.promisor >promisorlist && |
| 96 | test_line_count = 1 promisorlist |
| 97 | ) && |
| 98 | |
| 99 | cleanup_clone $enlistment |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'initializes sparse-checkout by default' ' |
| 103 | enlistment=sparse && |
| 104 | |
| 105 | scalar clone "file://$(pwd)/to-clone" $enlistment && |
| 106 | ( |
| 107 | cd $enlistment/src && |
| 108 | test_cmp_config true core.sparseCheckout && |
| 109 | test_cmp_config true core.sparseCheckoutCone |
| 110 | ) && |
| 111 | |
| 112 | cleanup_clone $enlistment |
| 113 | ' |
| 114 | |
| 115 | test_expect_success '--full-clone does not create sparse-checkout' ' |
| 116 | enlistment=full-clone && |
| 117 | |
| 118 | scalar clone --full-clone "file://$(pwd)/to-clone" $enlistment && |
| 119 | ( |
| 120 | cd $enlistment/src && |
| 121 | test_cmp_config "" --default "" core.sparseCheckout && |
| 122 | test_cmp_config "" --default "" core.sparseCheckoutCone |
| 123 | ) && |
| 124 | |
| 125 | cleanup_clone $enlistment |
| 126 | ' |
| 127 | |
| 128 | test_expect_success '--single-branch clones HEAD only' ' |
| 129 | enlistment=single-branch && |
| 130 | |
| 131 | scalar clone --single-branch "file://$(pwd)/to-clone" $enlistment && |
| 132 | ( |
| 133 | cd $enlistment/src && |
| 134 | git for-each-ref refs/remotes/origin >out && |
| 135 | test_line_count = 2 out && |
| 136 | test_grep "refs/remotes/origin/base" out |
| 137 | ) && |
| 138 | |
| 139 | cleanup_clone $enlistment |
| 140 | ' |
| 141 | |
| 142 | test_expect_success '--no-single-branch clones all branches' ' |
| 143 | enlistment=no-single-branch && |
| 144 | |
| 145 | scalar clone --no-single-branch "file://$(pwd)/to-clone" $enlistment && |
| 146 | ( |
| 147 | cd $enlistment/src && |
| 148 | git for-each-ref refs/remotes/origin >out && |
| 149 | test_line_count = 3 out && |
| 150 | test_grep "refs/remotes/origin/base" out && |
| 151 | test_grep "refs/remotes/origin/parallel" out |
| 152 | ) && |
| 153 | |
| 154 | cleanup_clone $enlistment |
| 155 | ' |
| 156 | |
| 157 | test_expect_success TTY 'progress with tty' ' |
| 158 | enlistment=progress1 && |
| 159 | |
| 160 | test_config -C to-clone uploadpack.allowfilter true && |
| 161 | test_config -C to-clone uploadpack.allowanysha1inwant true && |
| 162 | |
| 163 | test_terminal env GIT_PROGRESS_DELAY=0 \ |
| 164 | scalar clone "file://$(pwd)/to-clone" "$enlistment" 2>stderr && |
| 165 | grep "Enumerating objects" stderr >actual && |
| 166 | test_line_count = 2 actual && |
| 167 | cleanup_clone $enlistment |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'progress without tty' ' |
| 171 | enlistment=progress2 && |
| 172 | |
| 173 | test_config -C to-clone uploadpack.allowfilter true && |
| 174 | test_config -C to-clone uploadpack.allowanysha1inwant true && |
| 175 | |
| 176 | GIT_PROGRESS_DELAY=0 scalar clone "file://$(pwd)/to-clone" "$enlistment" 2>stderr && |
| 177 | test_grep ! "Enumerating objects" stderr && |
| 178 | test_grep ! "Updating files" stderr && |
| 179 | cleanup_clone $enlistment |
| 180 | ' |
| 181 | |
| 182 | test_expect_success 'scalar clone warns when background maintenance fails' ' |
| 183 | GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ |
| 184 | scalar clone "file://$(pwd)/to-clone" maint-fail 2>err && |
| 185 | test_grep "could not toggle maintenance" err |
| 186 | ' |
| 187 | |
| 188 | test_expect_success 'scalar clone --no-maintenance' ' |
| 189 | GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \ |
| 190 | GIT_TRACE2_EVENT="$(pwd)/no-maint.event" \ |
| 191 | GIT_TRACE2_EVENT_DEPTH=100 \ |
| 192 | scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err && |
| 193 | test_grep ! "could not toggle maintenance" err && |
| 194 | test_subcommand ! git maintenance unregister --force <no-maint.event |
| 195 | ' |
| 196 | |
| 197 | test_expect_success '`scalar clone --no-src`' ' |
| 198 | scalar clone --src "file://$(pwd)/to-clone" with-src && |
| 199 | scalar clone --no-src "file://$(pwd)/to-clone" without-src && |
| 200 | |
| 201 | test_path_is_dir with-src/src && |
| 202 | test_path_is_missing without-src/src && |
| 203 | |
| 204 | (cd with-src/src && ls ?*) >with && |
| 205 | (cd without-src && ls ?*) >without && |
| 206 | test_cmp with without |
| 207 | ' |
| 208 | |
| 209 | test_done |