debian: prepare for upload
[git/debian.git] / t / t5411-proc-receive-hook.sh
blob746487286f5d0824b33f7a1056afd3ec11f1f71a
1 #!/bin/sh
3 # Copyright (c) 2020 Jiang Xin
6 test_description='Test proc-receive hook'
8 . ./test-lib.sh
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 &&
17 rm -rf workbench &&
18 git init --bare upstream.git &&
19 git init workbench &&
20 create_commits_in workbench A B &&
22 cd workbench &&
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
32 ) &&
33 TAG=$(git -C workbench rev-parse v123) &&
35 # setup pre-receive hook
36 write_script upstream.git/hooks/pre-receive <<-\EOF &&
37 exec >&2
38 echo "# pre-receive hook"
39 while read old new ref
41 echo "pre-receive< $old $new $ref"
42 done
43 EOF
45 # setup post-receive hook
46 write_script upstream.git/hooks/post-receive <<-\EOF &&
47 exec >&2
48 echo "# post-receive hook"
49 while read old new ref
51 echo "post-receive< $old $new $ref"
52 done
53 EOF
55 upstream=upstream.git
59 run_proc_receive_hook_test() {
60 case $1 in
61 http)
62 PROTOCOL="HTTP protocol"
63 URL_PREFIX="http://.*"
65 local)
66 PROTOCOL="builtin protocol"
67 URL_PREFIX="\.\."
69 esac
71 # Include test cases for both file and HTTP protocol
72 for t in "$TEST_DIRECTORY"/t5411/test-*.sh
74 . "$t"
75 done
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
84 . "$t"
85 done
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
93 ROOT_PATH="$PWD"
94 . "$TEST_DIRECTORY"/lib-gpg.sh
95 . "$TEST_DIRECTORY"/lib-httpd.sh
96 . "$TEST_DIRECTORY"/lib-terminal.sh
97 start_httpd
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
112 setup_askpass_helper
114 # Run test cases for 'proc-receive' hook on HTTP protocol.
115 run_proc_receive_hook_test http
117 test_done