]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5411-proc-receive-hook.sh
Merge branch 'hx/push-atomic-with-cert'
[thirdparty/git.git] / t / t5411-proc-receive-hook.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2020 Jiang Xin
4 #
5
6 test_description='Test proc-receive hook'
7
8 . ./test-lib.sh
9
10 . "$TEST_DIRECTORY"/t5411/common-functions.sh
11
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 &&
21 (
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) &&
34
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
40 do
41 echo "pre-receive< $old $new $ref"
42 done
43 EOF
44
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
50 do
51 echo "post-receive< $old $new $ref"
52 done
53 EOF
54
55 upstream=upstream.git
56 '
57 }
58
59 run_proc_receive_hook_test() {
60 case $1 in
61 http)
62 PROTOCOL="HTTP protocol"
63 URL_PREFIX="http://.*"
64 ;;
65 local)
66 PROTOCOL="builtin protocol"
67 URL_PREFIX="\.\."
68 ;;
69 esac
70
71 # Include test cases for both file and HTTP protocol
72 for t in "$TEST_DIRECTORY"/t5411/test-*.sh
73 do
74 . "$t"
75 done
76 }
77
78 # Initialize the upstream repository and local workbench.
79 setup_upstream_and_workbench
80
81 # Load test cases that only need to be executed once.
82 for t in "$TEST_DIRECTORY"/t5411/once-*.sh
83 do
84 . "$t"
85 done
86
87 # Initialize the upstream repository and local workbench.
88 setup_upstream_and_workbench
89
90 # Run test cases for 'proc-receive' hook on local file protocol.
91 run_proc_receive_hook_test local
92
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
98
99 # Re-initialize the upstream repository and local workbench.
100 setup_upstream_and_workbench
101
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
110 '
111
112 setup_askpass_helper
113
114 # Run test cases for 'proc-receive' hook on HTTP protocol.
115 run_proc_receive_hook_test http
116
117 test_done