Raw
1 #!/bin/sh
2
3 test_description='git receive-pack'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 test_commit base &&
12 git clone -s --bare . fork &&
13 git checkout -b public/branch main &&
14 test_commit public &&
15 git checkout -b private/branch main &&
16 test_commit private
17 '
18
19 extract_haves () {
20 depacketize | sed -n 's/^\([^ ][^ ]*\) \.have/\1/p'
21 }
22
23 test_expect_success 'with core.alternateRefsCommand' '
24 write_script fork/alternate-refs <<-\EOF &&
25 git --git-dir="$1" for-each-ref \
26 --format="%(objectname)" \
27 refs/heads/public/
28 EOF
29 test_config -C fork core.alternateRefsCommand ./alternate-refs &&
30 git rev-parse public/branch >expect &&
31 printf "0000" | git receive-pack fork >actual &&
32 extract_haves <actual >actual.haves &&
33 test_cmp expect actual.haves
34 '
35
36 test_expect_success 'with core.alternateRefsPrefixes' '
37 test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
38 git rev-parse private/branch >expect &&
39 printf "0000" | git receive-pack fork >actual &&
40 extract_haves <actual >actual.haves &&
41 test_cmp expect actual.haves
42 '
43
44 # The `tee.exe` shipped in Git for Windows v2.49.0 is known to hang frequently
45 # when spawned from `git.exe` and piping its output to `git.exe`. This seems
46 # related to MSYS2 runtime bug fixes regarding the signal handling; Let's just
47 # skip the tests that need to exercise this when the faulty MSYS2 runtime is
48 # detected; The test cases are exercised enough in other matrix jobs of the CI
49 # runs.
50 test_lazy_prereq TEE_DOES_NOT_HANG '
51 test_have_prereq !MINGW &&
52 case "$(uname -a)" in *3.5.7-463ebcdc.x86_64*) false;; esac
53 '
54
55 test_expect_success TEE_DOES_NOT_HANG \
56 'receive-pack missing objects fails connectivity check' '
57 test_when_finished rm -rf repo remote.git setup.git &&
58
59 git init repo &&
60 git -C repo commit --allow-empty -m 1 &&
61 git clone --bare repo setup.git &&
62 git -C repo commit --allow-empty -m 2 &&
63
64 # Capture git-send-pack(1) output sent to git-receive-pack(1).
65 git -C repo send-pack ../setup.git --all \
66 --receive-pack="tee ${SQ}$(pwd)/out${SQ} | git-receive-pack" &&
67
68 # Replay captured git-send-pack(1) output on new empty repository.
69 git init --bare remote.git &&
70 git receive-pack remote.git <out >actual 2>err &&
71
72 test_grep "missing necessary objects" actual &&
73 test_grep "fatal: Failed to traverse parents" err &&
74 test_must_fail git -C remote.git cat-file -e $(git -C repo rev-parse HEAD)
75 '
76
77 test_expect_success TEE_DOES_NOT_HANG \
78 'receive-pack missing objects bypasses connectivity check' '
79 test_when_finished rm -rf repo remote.git setup.git &&
80
81 git init repo &&
82 git -C repo commit --allow-empty -m 1 &&
83 git clone --bare repo setup.git &&
84 git -C repo commit --allow-empty -m 2 &&
85
86 # Capture git-send-pack(1) output sent to git-receive-pack(1).
87 git -C repo send-pack ../setup.git --all \
88 --receive-pack="tee ${SQ}$(pwd)/out${SQ} | git-receive-pack" &&
89
90 # Replay captured git-send-pack(1) output on new empty repository.
91 git init --bare remote.git &&
92 git receive-pack --skip-connectivity-check remote.git <out >actual 2>err &&
93
94 test_grep ! "missing necessary objects" actual &&
95 test_must_be_empty err &&
96 git -C remote.git cat-file -e $(git -C repo rev-parse HEAD) &&
97 test_must_fail git -C remote.git rev-list $(git -C repo rev-parse HEAD)
98 '
99
100 test_done