summaryrefslogtreecommitdiff
path: root/t/t5545-push-options.sh
blob: 90a4b0d2fe9d8a1d9963bea54d2d1198a24003c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/sh
 
test_description='pushing to a repository using push options'
 
. ./test-lib.sh
 
mk_repo_pair () {
	rm -rf workbench upstream &&
	test_create_repo upstream &&
	test_create_repo workbench &&
	(
		cd upstream &&
		git config receive.denyCurrentBranch warn &&
		mkdir -p .git/hooks &&
		cat >.git/hooks/pre-receive <<-'EOF' &&
		#!/bin/sh
		if test -n "$GIT_PUSH_OPTION_COUNT"; then
			i=0
			>hooks/pre-receive.push_options
			while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
				eval "value=\$GIT_PUSH_OPTION_$i"
				echo $value >>hooks/pre-receive.push_options
				i=$((i + 1))
			done
		fi
		EOF
		chmod u+x .git/hooks/pre-receive
 
		cat >.git/hooks/post-receive <<-'EOF' &&
		#!/bin/sh
		if test -n "$GIT_PUSH_OPTION_COUNT"; then
			i=0
			>hooks/post-receive.push_options
			while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
				eval "value=\$GIT_PUSH_OPTION_$i"
				echo $value >>hooks/post-receive.push_options
				i=$((i + 1))
			done
		fi
		EOF
		chmod u+x .git/hooks/post-receive
	) &&
	(
		cd workbench &&
		git remote add up ../upstream
	)
}
 
# Compare the ref ($1) in upstream with a ref value from workbench ($2)
# i.e. test_refs second HEAD@{2}
test_refs () {
	test $# = 2 &&
	git -C upstream rev-parse --verify "$1" >expect &&
	git -C workbench rev-parse --verify "$2" >actual &&
	test_cmp expect actual
}
 
test_expect_success 'one push option works for a single branch' '
	mk_repo_pair &&
	git -C upstream config receive.advertisePushOptions true &&
	(
		cd workbench &&
		test_commit one &&
		git push --mirror up &&
		test_commit two &&
		git push --push-option=asdf up master
	) &&
	test_refs master master &&
	echo "asdf" >expect &&
	test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
	test_cmp expect upstream/.git/hooks/post-receive.push_options
'
 
test_expect_success 'push option denied by remote' '
	mk_repo_pair &&
	git -C upstream config receive.advertisePushOptions false &&
	(
		cd workbench &&
		test_commit one &&
		git push --mirror up &&
		test_commit two &&
		test_must_fail git push --push-option=asdf up master
	) &&
	test_refs master HEAD@{1}
'
 
test_expect_success 'two push options work' '
	mk_repo_pair &&
	git -C upstream config receive.advertisePushOptions true &&
	(
		cd workbench &&
		test_commit one &&
		git push --mirror up &&
		test_commit two &&
		git push --push-option=asdf --push-option="more structured text" up master
	) &&
	test_refs master master &&
	printf "asdf\nmore structured text\n" >expect &&
	test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
	test_cmp expect upstream/.git/hooks/post-receive.push_options
'
 
test_expect_success 'push options and submodules' '
	test_when_finished "rm -rf parent" &&
	test_when_finished "rm -rf parent_upstream" &&
	mk_repo_pair &&
	git -C upstream config receive.advertisePushOptions true &&
	cp -r upstream parent_upstream &&
	test_commit -C upstream one &&
 
	test_create_repo parent &&
	git -C parent remote add up ../parent_upstream &&
	test_commit -C parent one &&
	git -C parent push --mirror up &&
 
	git -C parent submodule add ../upstream workbench &&
	git -C parent/workbench remote add up ../../upstream &&
	git -C parent commit -m "add submoule" &&
 
	test_commit -C parent/workbench two &&
	git -C parent add workbench &&
	git -C parent commit -m "update workbench" &&
 
	git -C parent push \
		--push-option=asdf --push-option="more structured text" \
		--recurse-submodules=on-demand up master &&
 
	git -C upstream rev-parse --verify master >expect &&
	git -C parent/workbench rev-parse --verify master >actual &&
	test_cmp expect actual &&
 
	git -C parent_upstream rev-parse --verify master >expect &&
	git -C parent rev-parse --verify master >actual &&
	test_cmp expect actual &&
 
	printf "asdf\nmore structured text\n" >expect &&
	test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
	test_cmp expect upstream/.git/hooks/post-receive.push_options &&
	test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
	test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
'
 
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
 
test_expect_success 'push option denied properly by http server' '
	test_when_finished "rm -rf test_http_clone" &&
	test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
	mk_repo_pair &&
	git -C upstream config receive.advertisePushOptions false &&
	git -C upstream config http.receivepack true &&
	cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
	git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
	test_commit -C test_http_clone one &&
	test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
	test_i18ngrep "the receiving end does not support push options" actual &&
	git -C test_http_clone push origin master
'
 
test_expect_success 'push options work properly across http' '
	test_when_finished "rm -rf test_http_clone" &&
	test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
	mk_repo_pair &&
	git -C upstream config receive.advertisePushOptions true &&
	git -C upstream config http.receivepack true &&
	cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
	git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
 
	test_commit -C test_http_clone one &&
	git -C test_http_clone push origin master &&
	git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
	git -C test_http_clone rev-parse --verify master >actual &&
	test_cmp expect actual &&
 
	test_commit -C test_http_clone two &&
	git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
	printf "asdf\nmore structured text\n" >expect &&
	test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
	test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
 
	git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
	git -C test_http_clone rev-parse --verify master >actual &&
	test_cmp expect actual
'
 
stop_httpd
 
test_done