3 test_description
='git p4 label tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'start p4d' '
15 # Basic p4 label import tests.
17 test_expect_success
'basic p4 labels' '
18 test_when_finished cleanup_git &&
25 p4 submit -d "main/f1" &&
29 p4 submit -d "main/f2" &&
31 echo f3 >main/file_with_\$metachar &&
32 p4 add main/file_with_\$metachar &&
33 p4 submit -d "file with metachar" &&
35 p4 tag -l TAG_F1_ONLY main/f1 &&
36 p4 tag -l TAG_WITH\$_SHELL_CHAR main/... &&
37 p4 tag -l this_tag_will_be\ skipped main/... &&
41 p4 submit -d "main/f4" &&
51 p4 tag -l TAG_LONG_LABEL ... &&
55 git p4 clone --dest="$git" //depot@all &&
57 git config git-p4.labelImportRegexp ".*TAG.*" &&
58 git p4 sync --import-labels --verbose &&
62 test_line_count = 3 taglist &&
65 git checkout TAG_F1_ONLY &&
67 git checkout TAG_WITH\$_SHELL_CHAR &&
68 test -f f1 && test -f f2 && test -f file_with_\$metachar &&
70 git show TAG_LONG_LABEL | grep -q "A Label second line"
73 # Test some label corner cases:
75 # - two tags on the same file; both should be available
76 # - a tag that is only on one file; this kind of tag
77 # cannot be imported (at least not easily).
79 test_expect_success
'two labels on the same changelist' '
80 test_when_finished cleanup_git &&
85 p4 edit main/f1 main/f2 &&
86 echo "hello world" >main/f1 &&
87 echo "not in the tag" >main/f2 &&
88 p4 submit -d "main/f[12]: testing two labels" &&
90 p4 tag -l TAG_F1_1 main/... &&
91 p4 tag -l TAG_F1_2 main/... &&
95 git p4 clone --dest="$git" //depot@all &&
97 git p4 sync --import-labels &&
99 git tag | grep TAG_F1 &&
100 git tag | grep -q TAG_F1_1 &&
101 git tag | grep -q TAG_F1_2 &&
105 git checkout TAG_F1_1 &&
109 git checkout TAG_F1_2 &&
115 # Export some git tags to p4
116 test_expect_success
'export git tags to p4' '
117 test_when_finished cleanup_git &&
118 git p4 clone --dest="$git" //depot@all &&
121 git tag -m "A tag created in git:xyzzy" GIT_TAG_1 &&
122 echo "hello world" >main/f10 &&
124 git commit -m "Adding file for export test" &&
125 git config git-p4.skipSubmitEdit true &&
127 git tag -m "Another git tag" GIT_TAG_2 &&
128 git tag LIGHTWEIGHT_TAG &&
129 git p4 rebase --import-labels --verbose &&
130 git p4 submit --export-labels --verbose
135 p4 labels ... | grep GIT_TAG_1 &&
136 p4 labels ... | grep GIT_TAG_2 &&
137 p4 labels ... | grep LIGHTWEIGHT_TAG &&
138 p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
139 p4 sync ...@GIT_TAG_1 &&
140 ! test -f main/f10 &&
141 p4 sync ...@GIT_TAG_2 &&
146 # Export a tag from git where an affected file is deleted later on
147 # Need to create git tags after rebase, since only then can the
148 # git commits be mapped to p4 changelists.
149 test_expect_success
'export git tags to p4 with deletion' '
150 test_when_finished cleanup_git &&
151 git p4 clone --dest="$git" //depot@all &&
154 git p4 sync --import-labels &&
155 echo "deleted file" >main/deleted_file &&
156 git add main/deleted_file &&
157 git commit -m "create deleted file" &&
158 git rm main/deleted_file &&
159 echo "new file" >main/f11 &&
161 git commit -m "delete the deleted file" &&
162 git config git-p4.skipSubmitEdit true &&
164 git p4 rebase --import-labels --verbose &&
165 git tag -m "tag on deleted file" GIT_TAG_ON_DELETED HEAD~1 &&
166 git tag -m "tag after deletion" GIT_TAG_AFTER_DELETION HEAD &&
167 git p4 submit --export-labels --verbose
172 p4 sync ...@GIT_TAG_ON_DELETED &&
173 test -f main/deleted_file &&
174 p4 sync ...@GIT_TAG_AFTER_DELETION &&
175 ! test -f main/deleted_file &&
176 echo "checking label contents" &&
177 p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file"
181 # Create a tag in git that cannot be exported to p4
182 test_expect_success
'tag that cannot be exported' '
183 test_when_finished cleanup_git &&
184 git p4 clone --dest="$git" //depot@all &&
187 git checkout -b a_branch &&
188 echo "hello" >main/f12 &&
190 git commit -m "adding f12" &&
191 git tag -m "tag on a_branch" GIT_TAG_ON_A_BRANCH &&
193 git p4 submit --export-labels
198 ! p4 labels | grep GIT_TAG_ON_A_BRANCH
202 test_expect_success
'use git config to enable import/export of tags' '
203 git p4 clone --verbose --dest="$git" //depot@all &&
206 git config git-p4.exportLabels true &&
207 git config git-p4.importLabels true &&
208 git tag CFG_A_GIT_TAG &&
209 git p4 rebase --verbose &&
210 git p4 submit --verbose &&
212 git tag | grep TAG_F1_1
217 p4 labels | grep CFG_A_GIT_TAG
222 p4 changes
-m 1 "$@" |
awk '{print $2}'
225 # Importing a label that references a P4 commit that
226 # has not been seen. The presence of a label on a commit
227 # we haven't seen should not cause git-p4 to fail. It should
228 # merely skip that label, and still import other labels.
229 test_expect_success
'importing labels with missing revisions' '
230 test_when_finished cleanup_git &&
232 rm -fr "$cli" "$git" &&
234 P4CLIENT=missing-revision &&
235 client_view "//depot/missing-revision/... //missing-revision/..." &&
237 >f1 && p4 add f1 && p4 submit -d "start" &&
239 p4 tag -l TAG_S0 ... &&
241 >f2 && p4 add f2 && p4 submit -d "second" &&
243 startrev=$(p4_head_revision //depot/missing-revision/...) &&
245 >f3 && p4 add f3 && p4 submit -d "third" &&
247 p4 edit f2 && date >f2 && p4 submit -d "change" f2 &&
249 endrev=$(p4_head_revision //depot/missing-revision/...) &&
251 p4 tag -l TAG_S1 ... &&
253 # we should skip TAG_S0 since it is before our startpoint,
254 # but pick up TAG_S1.
256 git p4 clone --dest="$git" --import-labels -v \
257 //depot/missing-revision/...@$startrev,$endrev &&
260 git rev-parse TAG_S1 &&
261 ! git rev-parse TAG_S0