3 # Copyright (c) 2020 Jiang Xin
6 test_description
='Test proc-receive hook'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 .
"$TEST_DIRECTORY"/t5411
/common-functions.sh
16 setup_upstream_and_workbench
() {
17 # Refs of upstream : main(A)
18 # Refs of workbench: main(A) tags/v123
19 test_expect_success
"setup upstream and workbench" '
20 rm -rf upstream.git &&
22 git init --bare upstream.git &&
24 create_commits_in workbench A B &&
27 # Try to make a stable fixed width for abbreviated commit ID,
28 # this fixed-width oid will be replaced with "<OID>".
29 git config core.abbrev 7 &&
30 git tag -m "v123" v123 $A &&
31 git remote add origin ../upstream.git &&
32 git push origin main &&
33 git update-ref refs/heads/main $A $B &&
34 git -C ../upstream.git update-ref \
37 TAG=$(git -C workbench rev-parse v123) &&
39 # setup pre-receive hook
40 test_hook --setup -C upstream.git pre-receive <<-\EOF &&
42 echo "# pre-receive hook"
43 while read old new ref
45 echo "pre-receive< $old $new $ref"
49 # setup post-receive hook
50 test_hook --setup -C upstream.git post-receive <<-\EOF &&
52 echo "# post-receive hook"
53 while read old new ref
55 echo "post-receive< $old $new $ref"
63 run_proc_receive_hook_test
() {
66 PROTOCOL
="HTTP protocol"
67 URL_PREFIX
="http://.*"
70 PROTOCOL
="builtin protocol"
75 # Include test cases for both file and HTTP protocol
76 for t
in "$TEST_DIRECTORY"/t5411
/test-
*.sh
82 # Initialize the upstream repository and local workbench.
83 setup_upstream_and_workbench
85 # Load test cases that only need to be executed once.
86 for t
in "$TEST_DIRECTORY"/t5411
/once-
*.sh
91 # Initialize the upstream repository and local workbench.
92 setup_upstream_and_workbench
94 # Run test cases for 'proc-receive' hook on local file protocol.
95 run_proc_receive_hook_test
local
98 .
"$TEST_DIRECTORY"/lib-gpg.sh
99 .
"$TEST_DIRECTORY"/lib-httpd.sh
100 .
"$TEST_DIRECTORY"/lib-terminal.sh
103 # Re-initialize the upstream repository and local workbench.
104 setup_upstream_and_workbench
106 # Refs of upstream : main(A)
107 # Refs of workbench: main(A) tags/v123
108 test_expect_success
"setup for HTTP protocol" '
109 git -C upstream.git config http.receivepack true &&
110 upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
111 mv upstream.git "$upstream" &&
112 git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" &&
113 set_askpass user@host pass@host
118 # Run test cases for 'proc-receive' hook on HTTP protocol.
119 run_proc_receive_hook_test http