]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5411-proc-receive-hook.sh
Sync with 2.35.8
[thirdparty/git.git] / t / t5411-proc-receive-hook.sh
CommitLineData
38b9197a
JX
1#!/bin/sh
2#
3# Copyright (c) 2020 Jiang Xin
4#
5
6test_description='Test proc-receive hook'
7
5d5f4ea3 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
f3384e77
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
38b9197a
JX
11. ./test-lib.sh
12
13. "$TEST_DIRECTORY"/t5411/common-functions.sh
14
15setup_upstream_and_workbench () {
f3384e77
JS
16 # Refs of upstream : main(A)
17 # Refs of workbench: main(A) tags/v123
38b9197a
JX
18 test_expect_success "setup upstream and workbench" '
19 rm -rf upstream.git &&
20 rm -rf workbench &&
21 git init --bare upstream.git &&
22 git init workbench &&
23 create_commits_in workbench A B &&
24 (
25 cd workbench &&
26 # Try to make a stable fixed width for abbreviated commit ID,
27 # this fixed-width oid will be replaced with "<OID>".
28 git config core.abbrev 7 &&
29 git tag -m "v123" v123 $A &&
30 git remote add origin ../upstream.git &&
f3384e77
JS
31 git push origin main &&
32 git update-ref refs/heads/main $A $B &&
38b9197a 33 git -C ../upstream.git update-ref \
f3384e77 34 refs/heads/main $A $B
38b9197a
JX
35 ) &&
36 TAG=$(git -C workbench rev-parse v123) &&
37
38 # setup pre-receive hook
7da7f63c 39 test_hook --setup -C upstream.git pre-receive <<-\EOF &&
38b9197a
JX
40 exec >&2
41 echo "# pre-receive hook"
42 while read old new ref
43 do
44 echo "pre-receive< $old $new $ref"
45 done
46 EOF
47
48 # setup post-receive hook
7da7f63c 49 test_hook --setup -C upstream.git post-receive <<-\EOF &&
38b9197a
JX
50 exec >&2
51 echo "# post-receive hook"
52 while read old new ref
53 do
54 echo "post-receive< $old $new $ref"
55 done
56 EOF
57
58 upstream=upstream.git
59 '
60}
61
62run_proc_receive_hook_test() {
63 case $1 in
64 http)
65 PROTOCOL="HTTP protocol"
66 URL_PREFIX="http://.*"
67 ;;
68 local)
69 PROTOCOL="builtin protocol"
70 URL_PREFIX="\.\."
71 ;;
72 esac
73
74 # Include test cases for both file and HTTP protocol
75 for t in "$TEST_DIRECTORY"/t5411/test-*.sh
76 do
77 . "$t"
78 done
79}
80
81# Initialize the upstream repository and local workbench.
82setup_upstream_and_workbench
83
63518a57
JX
84# Load test cases that only need to be executed once.
85for t in "$TEST_DIRECTORY"/t5411/once-*.sh
86do
87 . "$t"
88done
89
90# Initialize the upstream repository and local workbench.
91setup_upstream_and_workbench
92
38b9197a
JX
93# Run test cases for 'proc-receive' hook on local file protocol.
94run_proc_receive_hook_test local
95
96ROOT_PATH="$PWD"
97. "$TEST_DIRECTORY"/lib-gpg.sh
98. "$TEST_DIRECTORY"/lib-httpd.sh
99. "$TEST_DIRECTORY"/lib-terminal.sh
100start_httpd
101
102# Re-initialize the upstream repository and local workbench.
103setup_upstream_and_workbench
104
f3384e77
JS
105# Refs of upstream : main(A)
106# Refs of workbench: main(A) tags/v123
38b9197a
JX
107test_expect_success "setup for HTTP protocol" '
108 git -C upstream.git config http.receivepack true &&
109 upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
110 mv upstream.git "$upstream" &&
111 git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" &&
112 set_askpass user@host pass@host
113'
114
115setup_askpass_helper
116
117# Run test cases for 'proc-receive' hook on HTTP protocol.
118run_proc_receive_hook_test http
119
120test_done