The twelfth batch
[git/gitster.git] / t / t5411-proc-receive-hook.sh
blob13d2d310a9f11e4a54c9484e7d2f78b24ee82cd3
1 #!/bin/sh
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
12 . ./test-lib.sh
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 &&
21 rm -rf workbench &&
22 git init --bare upstream.git &&
23 git init workbench &&
24 create_commits_in workbench A B &&
26 cd workbench &&
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 \
35 refs/heads/main $A $B
36 ) &&
37 TAG=$(git -C workbench rev-parse v123) &&
39 # setup pre-receive hook
40 test_hook --setup -C upstream.git pre-receive <<-\EOF &&
41 exec >&2
42 echo "# pre-receive hook"
43 while read old new ref
45 echo "pre-receive< $old $new $ref"
46 done
47 EOF
49 # setup post-receive hook
50 test_hook --setup -C upstream.git post-receive <<-\EOF &&
51 exec >&2
52 echo "# post-receive hook"
53 while read old new ref
55 echo "post-receive< $old $new $ref"
56 done
57 EOF
59 upstream=upstream.git
63 run_proc_receive_hook_test() {
64 case $1 in
65 http)
66 PROTOCOL="HTTP protocol"
67 URL_PREFIX="http://.*"
69 local)
70 PROTOCOL="builtin protocol"
71 URL_PREFIX="\.\."
73 esac
75 # Include test cases for both file and HTTP protocol
76 for t in "$TEST_DIRECTORY"/t5411/test-*.sh
78 . "$t"
79 done
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
88 . "$t"
89 done
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
97 ROOT_PATH="$PWD"
98 . "$TEST_DIRECTORY"/lib-gpg.sh
99 . "$TEST_DIRECTORY"/lib-httpd.sh
100 . "$TEST_DIRECTORY"/lib-terminal.sh
101 start_httpd
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
116 setup_askpass_helper
118 # Run test cases for 'proc-receive' hook on HTTP protocol.
119 run_proc_receive_hook_test http
121 test_done