3 # Copyright (c) 2020 Jiang Xin
6 test_description
='Test proc-receive hook'
10 .
"$TEST_DIRECTORY"/t5411
/common-functions.sh
12 setup_upstream_and_workbench
() {
13 # Refs of upstream : master(A)
14 # Refs of workbench: master(A) tags/v123
15 test_expect_success
"setup upstream and workbench" '
16 rm -rf upstream.git &&
18 git init --bare upstream.git &&
20 create_commits_in workbench A B &&
23 # Try to make a stable fixed width for abbreviated commit ID,
24 # this fixed-width oid will be replaced with "<OID>".
25 git config core.abbrev 7 &&
26 git tag -m "v123" v123 $A &&
27 git remote add origin ../upstream.git &&
28 git push origin master &&
29 git update-ref refs/heads/master $A $B &&
30 git -C ../upstream.git update-ref \
31 refs/heads/master $A $B
33 TAG=$(git -C workbench rev-parse v123) &&
35 # setup pre-receive hook
36 write_script upstream.git/hooks/pre-receive <<-\EOF &&
38 echo "# pre-receive hook"
39 while read old new ref
41 echo "pre-receive< $old $new $ref"
45 # setup post-receive hook
46 write_script upstream.git/hooks/post-receive <<-\EOF &&
48 echo "# post-receive hook"
49 while read old new ref
51 echo "post-receive< $old $new $ref"
59 run_proc_receive_hook_test
() {
62 PROTOCOL
="HTTP protocol"
63 URL_PREFIX
="http://.*"
66 PROTOCOL
="builtin protocol"
71 # Include test cases for both file and HTTP protocol
72 for t
in "$TEST_DIRECTORY"/t5411
/test-
*.sh
78 # Initialize the upstream repository and local workbench.
79 setup_upstream_and_workbench
81 # Load test cases that only need to be executed once.
82 for t
in "$TEST_DIRECTORY"/t5411
/once-
*.sh
87 # Initialize the upstream repository and local workbench.
88 setup_upstream_and_workbench
90 # Run test cases for 'proc-receive' hook on local file protocol.
91 run_proc_receive_hook_test
local
94 .
"$TEST_DIRECTORY"/lib-gpg.sh
95 .
"$TEST_DIRECTORY"/lib-httpd.sh
96 .
"$TEST_DIRECTORY"/lib-terminal.sh
99 # Re-initialize the upstream repository and local workbench.
100 setup_upstream_and_workbench
102 # Refs of upstream : master(A)
103 # Refs of workbench: master(A) tags/v123
104 test_expect_success
"setup for HTTP protocol" '
105 git -C upstream.git config http.receivepack true &&
106 upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
107 mv upstream.git "$upstream" &&
108 git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" &&
109 set_askpass user@host pass@host
114 # Run test cases for 'proc-receive' hook on HTTP protocol.
115 run_proc_receive_hook_test http