aboutsummaryrefslogtreecommitdiff
path: root/t/t9811-git-p4-label-import.sh
blob: 095238fffe2757a5bf1c5c2f877791117fbf09a3 (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/sh

test_description='git p4 label tests'

. ./lib-git-p4.sh

test_expect_success 'start p4d' '
	start_p4d
'

# Basic p4 label import tests.
#
test_expect_success 'basic p4 labels' '
	test_when_finished cleanup_git &&
	(
		cd "$cli" &&
		mkdir -p main &&

		echo f1 >main/f1 &&
		p4 add main/f1 &&
		p4 submit -d "main/f1" &&

		echo f2 >main/f2 &&
		p4 add main/f2 &&
		p4 submit -d "main/f2" &&

		echo f3 >main/file_with_\$metachar &&
		p4 add main/file_with_\$metachar &&
		p4 submit -d "file with metachar" &&

		p4 tag -l TAG_F1_ONLY main/f1 &&
		p4 tag -l TAG_WITH\$_SHELL_CHAR main/... &&
		p4 tag -l this_tag_will_be\ skipped main/... &&

		echo f4 >main/f4 &&
		p4 add main/f4 &&
		p4 submit -d "main/f4" &&

		p4 label -i <<-EOF &&
		Label: TAG_LONG_LABEL
		Description:
		   A Label first line
		   A Label second line
		View:	//depot/...
		EOF

		p4 tag -l TAG_LONG_LABEL ... &&

		p4 labels ... &&

		git p4 clone --dest="$git" //depot@all &&
		cd "$git" &&
		git config git-p4.labelImportRegexp ".*TAG.*" &&
		git p4 sync --import-labels --verbose &&

		git tag &&
		git tag >taglist &&
		test_line_count = 3 taglist &&

		cd main &&
		git checkout TAG_F1_ONLY &&
		! test -f f2 &&
		git checkout TAG_WITH\$_SHELL_CHAR &&
		test -f f1 && test -f f2 && test -f file_with_\$metachar &&

		git show TAG_LONG_LABEL | grep -q "A Label second line"
	)
'
# Test some label corner cases:
#
# - two tags on the same file; both should be available
# - a tag that is only on one file; this kind of tag
#   cannot be imported (at least not easily).

test_expect_success 'two labels on the same changelist' '
	test_when_finished cleanup_git &&
	(
		cd "$cli" &&
		mkdir -p main &&

		p4 edit main/f1 main/f2 &&
		echo "hello world" >main/f1 &&
		echo "not in the tag" >main/f2 &&
		p4 submit -d "main/f[12]: testing two labels" &&

		p4 tag -l TAG_F1_1 main/... &&
		p4 tag -l TAG_F1_2 main/... &&

		p4 labels ... &&

		git p4 clone --dest="$git" //depot@all &&
		cd "$git" &&
		git p4 sync --import-labels &&

		git tag | grep TAG_F1 &&
		git tag | grep -q TAG_F1_1 &&
		git tag | grep -q TAG_F1_2 &&

		cd main &&

		git checkout TAG_F1_1 &&
		ls &&
		test -f f1 &&

		git checkout TAG_F1_2 &&
		ls &&
		test -f f1
	)
'

# Export some git tags to p4
test_expect_success 'export git tags to p4' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot@all &&
	(
		cd "$git" &&
		git tag -m "A tag created in git:xyzzy" GIT_TAG_1 &&
		echo "hello world" >main/f10 &&
		git add main/f10 &&
		git commit -m "Adding file for export test" &&
		git config git-p4.skipSubmitEdit true &&
		git p4 submit &&
		git tag -m "Another git tag" GIT_TAG_2 &&
		git tag LIGHTWEIGHT_TAG &&
		git p4 rebase --import-labels --verbose &&
		git p4 submit --export-labels --verbose
	) &&
	(
		cd "$cli" &&
		p4 sync ... &&
		p4 labels ... | grep GIT_TAG_1 &&
		p4 labels ... | grep GIT_TAG_2 &&
		p4 labels ... | grep LIGHTWEIGHT_TAG &&
		p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
		p4 sync ...@GIT_TAG_1 &&
		! test -f main/f10
		p4 sync ...@GIT_TAG_2 &&
		test -f main/f10
	)
'

# Export a tag from git where an affected file is deleted later on
# Need to create git tags after rebase, since only then can the
# git commits be mapped to p4 changelists.
test_expect_success 'export git tags to p4 with deletion' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot@all &&
	(
		cd "$git" &&
		git p4 sync --import-labels &&
		echo "deleted file" >main/deleted_file &&
		git add main/deleted_file &&
		git commit -m "create deleted file" &&
		git rm main/deleted_file &&
		echo "new file" >main/f11 &&
		git add main/f11 &&
		git commit -m "delete the deleted file" &&
		git config git-p4.skipSubmitEdit true &&
		git p4 submit &&
		git p4 rebase --import-labels --verbose &&
		git tag -m "tag on deleted file" GIT_TAG_ON_DELETED HEAD~1 &&
		git tag -m "tag after deletion" GIT_TAG_AFTER_DELETION HEAD &&
		git p4 submit --export-labels --verbose
	) &&
	(
		cd "$cli" &&
		p4 sync ... &&
		p4 sync ...@GIT_TAG_ON_DELETED &&
		test -f main/deleted_file &&
		p4 sync ...@GIT_TAG_AFTER_DELETION &&
		! test -f main/deleted_file &&
		echo "checking label contents" &&
		p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file"
	)
'

# Create a tag in git that cannot be exported to p4
test_expect_success 'tag that cannot be exported' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot@all &&
	(
		cd "$git" &&
		git checkout -b a_branch &&
		echo "hello" >main/f12 &&
		git add main/f12 &&
		git commit -m "adding f12" &&
		git tag -m "tag on a_branch" GIT_TAG_ON_A_BRANCH &&
		git checkout master &&
		git p4 submit --export-labels
	) &&
	(
		cd "$cli" &&
		p4 sync ... &&
		!(p4 labels | grep GIT_TAG_ON_A_BRANCH)
	)
'

test_expect_success 'use git config to enable import/export of tags' '
	git p4 clone --verbose --dest="$git" //depot@all &&
	(
		cd "$git" &&
		git config git-p4.exportLabels true &&
		git config git-p4.importLabels true &&
		git tag CFG_A_GIT_TAG &&
		git p4 rebase --verbose &&
		git p4 submit --verbose &&
		git tag &&
		git tag | grep TAG_F1_1
	) &&
	(
		cd "$cli" &&
		p4 labels &&
		p4 labels | grep CFG_A_GIT_TAG
	)
'


test_expect_success 'kill p4d' '
	kill_p4d
'

test_done