3 # Copyright (c) 2020 Jiang Xin
6 test_description='Test proc-receive hook'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 test_have_prereq PREPARE_FOR_MAIN_BRANCH || {
14 test_skip="In transit for the default branch name 'main'"
18 . "$TEST_DIRECTORY"/t5411/common-functions.sh
20 setup_upstream_and_workbench () {
21 # Refs of upstream : main(A)
22 # Refs of workbench: main(A) tags/v123
23 test_expect_success "setup upstream and workbench" '
24 rm -rf upstream.git &&
26 git init --bare upstream.git &&
28 create_commits_in workbench A B &&
31 # Try to make a stable fixed width for abbreviated commit ID,
32 # this fixed-width oid will be replaced with "<OID>".
33 git config core.abbrev 7 &&
34 git tag -m "v123" v123 $A &&
35 git remote add origin ../upstream.git &&
36 git push origin main &&
37 git update-ref refs/heads/main $A $B &&
38 git -C ../upstream.git update-ref \
41 TAG=$(git -C workbench rev-parse v123) &&
43 # setup pre-receive hook
44 write_script upstream.git/hooks/pre-receive <<-\EOF &&
46 echo "# pre-receive hook"
47 while read old new ref
49 echo "pre-receive< $old $new $ref"
53 # setup post-receive hook
54 write_script upstream.git/hooks/post-receive <<-\EOF &&
56 echo "# post-receive hook"
57 while read old new ref
59 echo "post-receive< $old $new $ref"
67 run_proc_receive_hook_test() {
70 PROTOCOL="HTTP protocol"
71 URL_PREFIX="http://.*"
74 PROTOCOL="builtin protocol"
79 # Include test cases for both file and HTTP protocol
80 for t in "$TEST_DIRECTORY"/t5411/test-*.sh
86 # Initialize the upstream repository and local workbench.
87 setup_upstream_and_workbench
89 # Load test cases that only need to be executed once.
90 for t in "$TEST_DIRECTORY"/t5411/once-*.sh
95 # Initialize the upstream repository and local workbench.
96 setup_upstream_and_workbench
98 # Run test cases for 'proc-receive' hook on local file protocol.
99 run_proc_receive_hook_test local
102 . "$TEST_DIRECTORY"/lib-gpg.sh
103 . "$TEST_DIRECTORY"/lib-httpd.sh
104 . "$TEST_DIRECTORY"/lib-terminal.sh
107 # Re-initialize the upstream repository and local workbench.
108 setup_upstream_and_workbench
110 # Refs of upstream : main(A)
111 # Refs of workbench: main(A) tags/v123
112 test_expect_success "setup for HTTP protocol" '
113 git -C upstream.git config http.receivepack true &&
114 upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
115 mv upstream.git "$upstream" &&
116 git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" &&
117 set_askpass user@host pass@host
122 # Run test cases for 'proc-receive' hook on HTTP protocol.
123 run_proc_receive_hook_test http