]>
Commit | Line | Data |
---|---|---|
38b9197a JX |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2020 Jiang Xin | |
4 | # | |
5 | ||
6 | test_description='Test proc-receive hook' | |
7 | ||
5d5f4ea3 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
f3384e77 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
38b9197a JX |
11 | . ./test-lib.sh |
12 | ||
13 | . "$TEST_DIRECTORY"/t5411/common-functions.sh | |
14 | ||
15 | setup_upstream_and_workbench () { | |
f3384e77 JS |
16 | # Refs of upstream : main(A) |
17 | # Refs of workbench: main(A) tags/v123 | |
38b9197a JX |
18 | test_expect_success "setup upstream and workbench" ' |
19 | rm -rf upstream.git && | |
20 | rm -rf workbench && | |
21 | git init --bare upstream.git && | |
22 | git init workbench && | |
23 | create_commits_in workbench A B && | |
24 | ( | |
25 | cd workbench && | |
26 | # Try to make a stable fixed width for abbreviated commit ID, | |
27 | # this fixed-width oid will be replaced with "<OID>". | |
28 | git config core.abbrev 7 && | |
29 | git tag -m "v123" v123 $A && | |
30 | git remote add origin ../upstream.git && | |
f3384e77 JS |
31 | git push origin main && |
32 | git update-ref refs/heads/main $A $B && | |
38b9197a | 33 | git -C ../upstream.git update-ref \ |
f3384e77 | 34 | refs/heads/main $A $B |
38b9197a JX |
35 | ) && |
36 | TAG=$(git -C workbench rev-parse v123) && | |
37 | ||
38 | # setup pre-receive hook | |
39 | write_script upstream.git/hooks/pre-receive <<-\EOF && | |
40 | exec >&2 | |
41 | echo "# pre-receive hook" | |
42 | while read old new ref | |
43 | do | |
44 | echo "pre-receive< $old $new $ref" | |
45 | done | |
46 | EOF | |
47 | ||
48 | # setup post-receive hook | |
49 | write_script upstream.git/hooks/post-receive <<-\EOF && | |
50 | exec >&2 | |
51 | echo "# post-receive hook" | |
52 | while read old new ref | |
53 | do | |
54 | echo "post-receive< $old $new $ref" | |
55 | done | |
56 | EOF | |
57 | ||
58 | upstream=upstream.git | |
59 | ' | |
60 | } | |
61 | ||
62 | run_proc_receive_hook_test() { | |
63 | case $1 in | |
64 | http) | |
65 | PROTOCOL="HTTP protocol" | |
66 | URL_PREFIX="http://.*" | |
67 | ;; | |
68 | local) | |
69 | PROTOCOL="builtin protocol" | |
70 | URL_PREFIX="\.\." | |
71 | ;; | |
72 | esac | |
73 | ||
74 | # Include test cases for both file and HTTP protocol | |
75 | for t in "$TEST_DIRECTORY"/t5411/test-*.sh | |
76 | do | |
77 | . "$t" | |
78 | done | |
79 | } | |
80 | ||
81 | # Initialize the upstream repository and local workbench. | |
82 | setup_upstream_and_workbench | |
83 | ||
63518a57 JX |
84 | # Load test cases that only need to be executed once. |
85 | for t in "$TEST_DIRECTORY"/t5411/once-*.sh | |
86 | do | |
87 | . "$t" | |
88 | done | |
89 | ||
90 | # Initialize the upstream repository and local workbench. | |
91 | setup_upstream_and_workbench | |
92 | ||
38b9197a JX |
93 | # Run test cases for 'proc-receive' hook on local file protocol. |
94 | run_proc_receive_hook_test local | |
95 | ||
96 | ROOT_PATH="$PWD" | |
97 | . "$TEST_DIRECTORY"/lib-gpg.sh | |
98 | . "$TEST_DIRECTORY"/lib-httpd.sh | |
99 | . "$TEST_DIRECTORY"/lib-terminal.sh | |
100 | start_httpd | |
101 | ||
102 | # Re-initialize the upstream repository and local workbench. | |
103 | setup_upstream_and_workbench | |
104 | ||
f3384e77 JS |
105 | # Refs of upstream : main(A) |
106 | # Refs of workbench: main(A) tags/v123 | |
38b9197a JX |
107 | test_expect_success "setup for HTTP protocol" ' |
108 | git -C upstream.git config http.receivepack true && | |
109 | upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" && | |
110 | mv upstream.git "$upstream" && | |
111 | git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" && | |
112 | set_askpass user@host pass@host | |
113 | ' | |
114 | ||
115 | setup_askpass_helper | |
116 | ||
117 | # Run test cases for 'proc-receive' hook on HTTP protocol. | |
118 | run_proc_receive_hook_test http | |
119 | ||
120 | test_done |