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
13 .
"$TEST_DIRECTORY"/t5411
/common-functions.sh
15 setup_upstream_and_workbench
() {
16 # Refs of upstream : main(A)
17 # Refs of workbench: main(A) tags/v123
18 test_expect_success
"setup upstream and workbench" '
19 rm -rf upstream.git &&
21 git init --bare upstream.git &&
23 create_commits_in workbench A B &&
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 &&
31 git push origin main &&
32 git update-ref refs/heads/main $A $B &&
33 git -C ../upstream.git update-ref \
36 TAG=$(git -C workbench rev-parse v123) &&
38 # setup pre-receive hook
39 test_hook --setup -C upstream.git pre-receive <<-\EOF &&
41 echo "# pre-receive hook"
42 while read old new ref
44 echo "pre-receive< $old $new $ref"
48 # setup post-receive hook
49 test_hook --setup -C upstream.git post-receive <<-\EOF &&
51 echo "# post-receive hook"
52 while read old new ref
54 echo "post-receive< $old $new $ref"
62 run_proc_receive_hook_test
() {
65 PROTOCOL
="HTTP protocol"
66 URL_PREFIX
="http://.*"
69 PROTOCOL
="builtin protocol"
74 # Include test cases for both file and HTTP protocol
75 for t
in "$TEST_DIRECTORY"/t5411
/test-
*.sh
81 # Initialize the upstream repository and local workbench.
82 setup_upstream_and_workbench
84 # Load test cases that only need to be executed once.
85 for t
in "$TEST_DIRECTORY"/t5411
/once-
*.sh
90 # Initialize the upstream repository and local workbench.
91 setup_upstream_and_workbench
93 # Run test cases for 'proc-receive' hook on local file protocol.
94 run_proc_receive_hook_test
local
97 .
"$TEST_DIRECTORY"/lib-gpg.sh
98 .
"$TEST_DIRECTORY"/lib-httpd.sh
99 .
"$TEST_DIRECTORY"/lib-terminal.sh
102 # Re-initialize the upstream repository and local workbench.
103 setup_upstream_and_workbench
105 # Refs of upstream : main(A)
106 # Refs of workbench: main(A) tags/v123
107 test_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
117 # Run test cases for 'proc-receive' hook on HTTP protocol.
118 run_proc_receive_hook_test http