Git fork
1#!/bin/sh
2
3test_description='check that local clone does not fetch from promisor remotes'
4
5. ./test-lib.sh
6
7test_expect_success 'create evil repo' '
8 git init tmp &&
9 test_commit -C tmp a &&
10 git -C tmp config uploadpack.allowfilter 1 &&
11 git clone --filter=blob:none --no-local --no-checkout tmp evil &&
12 rm -rf tmp &&
13
14 git -C evil config remote.origin.uploadpack \"\$TRASH_DIRECTORY/fake-upload-pack\" &&
15 write_script fake-upload-pack <<-\EOF &&
16 echo >&2 "fake-upload-pack running"
17 >"$TRASH_DIRECTORY/script-executed"
18 exit 1
19 EOF
20 export TRASH_DIRECTORY &&
21
22 # empty shallow file disables local clone optimization
23 >evil/.git/shallow
24'
25
26test_expect_success 'local clone must not fetch from promisor remote and execute script' '
27 rm -f script-executed &&
28 test_must_fail git clone \
29 --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
30 evil clone1 2>err &&
31 test_grep ! "fake-upload-pack running" err &&
32 test_path_is_missing script-executed
33'
34
35test_expect_success 'clone from file://... must not fetch from promisor remote and execute script' '
36 rm -f script-executed &&
37 test_must_fail git clone \
38 --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
39 "file://$(pwd)/evil" clone2 2>err &&
40 test_grep ! "fake-upload-pack running" err &&
41 test_path_is_missing script-executed
42'
43
44test_expect_success 'fetch from file://... must not fetch from promisor remote and execute script' '
45 rm -f script-executed &&
46 test_must_fail git fetch \
47 --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
48 "file://$(pwd)/evil" 2>err &&
49 test_grep ! "fake-upload-pack running" err &&
50 test_path_is_missing script-executed
51'
52
53test_expect_success 'pack-objects should fetch from promisor remote and execute script' '
54 rm -f script-executed &&
55 echo "HEAD" | test_must_fail git -C evil pack-objects --revs --stdout >/dev/null 2>err &&
56 test_grep "fake-upload-pack running" err &&
57 test_path_is_file script-executed
58'
59
60test_expect_success 'clone from promisor remote does not lazy-fetch by default' '
61 rm -f script-executed &&
62
63 # The --path-walk feature of "git pack-objects" is not
64 # compatible with this kind of fetch from an incomplete repo.
65 GIT_TEST_PACK_PATH_WALK=0 &&
66 export GIT_TEST_PACK_PATH_WALK &&
67
68 test_must_fail git clone evil no-lazy 2>err &&
69 test_grep "lazy fetching disabled" err &&
70 test_path_is_missing script-executed
71'
72
73test_expect_success 'promisor lazy-fetching can be re-enabled' '
74 rm -f script-executed &&
75 test_must_fail env GIT_NO_LAZY_FETCH=0 \
76 git clone evil lazy-ok 2>err &&
77 test_grep "fake-upload-pack running" err &&
78 test_path_is_file script-executed
79'
80
81test_done