fsmonitor--daemon: don't translate literal commands
[git/debian.git] / t / t5411-proc-receive-hook.sh
blob92cf52c6d4a32c401680a068f9d892950e13d99a
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-lib.sh
13 . "$TEST_DIRECTORY"/t5411/common-functions.sh
15 setup_upstream_and_workbench () {
16 # Refs of upstream : main(A)
17 # Refs of workbench: main(A) tags/v123
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 &&
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 &&
31 git push origin main &&
32 git update-ref refs/heads/main $A $B &&
33 git -C ../upstream.git update-ref \
34 refs/heads/main $A $B
35 ) &&
36 TAG=$(git -C workbench rev-parse v123) &&
38 # setup pre-receive hook
39 test_hook --setup -C upstream.git pre-receive <<-\EOF &&
40 exec >&2
41 echo "# pre-receive hook"
42 while read old new ref
44 echo "pre-receive< $old $new $ref"
45 done
46 EOF
48 # setup post-receive hook
49 test_hook --setup -C upstream.git post-receive <<-\EOF &&
50 exec >&2
51 echo "# post-receive hook"
52 while read old new ref
54 echo "post-receive< $old $new $ref"
55 done
56 EOF
58 upstream=upstream.git
62 run_proc_receive_hook_test() {
63 case $1 in
64 http)
65 PROTOCOL="HTTP protocol"
66 URL_PREFIX="http://.*"
68 local)
69 PROTOCOL="builtin protocol"
70 URL_PREFIX="\.\."
72 esac
74 # Include test cases for both file and HTTP protocol
75 for t in "$TEST_DIRECTORY"/t5411/test-*.sh
77 . "$t"
78 done
81 # Initialize the upstream repository and local workbench.
82 setup_upstream_and_workbench
84 # Load test cases that only need to be executed once.
85 for t in "$TEST_DIRECTORY"/t5411/once-*.sh
87 . "$t"
88 done
90 # Initialize the upstream repository and local workbench.
91 setup_upstream_and_workbench
93 # Run test cases for 'proc-receive' hook on local file protocol.
94 run_proc_receive_hook_test local
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
102 # Re-initialize the upstream repository and local workbench.
103 setup_upstream_and_workbench
105 # Refs of upstream : main(A)
106 # Refs of workbench: main(A) tags/v123
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
115 setup_askpass_helper
117 # Run test cases for 'proc-receive' hook on HTTP protocol.
118 run_proc_receive_hook_test http
120 test_done