Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t9811-git-p4-label-import.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t9811-git-p4-label-import.sh` 273 lines ยท 6642 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git p4 label tests' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./lib-git-p4.sh 9 10 test_expect_success 'start p4d' ' 11 start_p4d 12 ' 13 14 # Basic p4 label import tests. 15 # 16 test_expect_success 'basic p4 labels' ' 17 test_when_finished cleanup_git && 18 ( 19 cd "$cli" && 20 mkdir -p main && 21 22 echo f1 >main/f1 && 23 p4 add main/f1 && 24 p4 submit -d "main/f1" && 25 26 echo f2 >main/f2 && 27 p4 add main/f2 && 28 p4 submit -d "main/f2" && 29 30 echo f3 >main/file_with_\$metachar && 31 p4 add main/file_with_\$metachar && 32 p4 submit -d "file with metachar" && 33 34 p4 tag -l TAG_F1_ONLY main/f1 && 35 p4 tag -l TAG_WITH\$_SHELL_CHAR main/... && 36 p4 tag -l this_tag_will_be\ skipped main/... && 37 38 echo f4 >main/f4 && 39 p4 add main/f4 && 40 p4 submit -d "main/f4" && 41 42 p4 label -i <<-EOF && 43 Label: TAG_LONG_LABEL 44 Description: 45 A Label first line 46 A Label second line 47 View: //depot/... 48 EOF 49 50 p4 tag -l TAG_LONG_LABEL ... && 51 52 p4 labels ... && 53 54 git p4 clone --dest="$git" //depot@all && 55 cd "$git" && 56 git config git-p4.labelImportRegexp ".*TAG.*" && 57 git p4 sync --import-labels --verbose && 58 59 git tag && 60 git tag >taglist && 61 test_line_count = 3 taglist && 62 63 cd main && 64 git checkout TAG_F1_ONLY && 65 test_path_is_missing f2 && 66 git checkout TAG_WITH\$_SHELL_CHAR && 67 test_path_is_file f1 && 68 test_path_is_file f2 && 69 test_path_is_file file_with_\$metachar && 70 71 git show TAG_LONG_LABEL | grep -q "A Label second line" 72 ) 73 ' 74 # Test some label corner cases: 75 # 76 # - two tags on the same file; both should be available 77 # - a tag that is only on one file; this kind of tag 78 # cannot be imported (at least not easily). 79 80 test_expect_success 'two labels on the same changelist' ' 81 test_when_finished cleanup_git && 82 ( 83 cd "$cli" && 84 mkdir -p main && 85 86 p4 edit main/f1 main/f2 && 87 echo "hello world" >main/f1 && 88 echo "not in the tag" >main/f2 && 89 p4 submit -d "main/f[12]: testing two labels" && 90 91 p4 tag -l TAG_F1_1 main/... && 92 p4 tag -l TAG_F1_2 main/... && 93 94 p4 labels ... && 95 96 git p4 clone --dest="$git" //depot@all && 97 cd "$git" && 98 git p4 sync --import-labels && 99 100 git show-ref --verify refs/tags/TAG_F1_1 && 101 git show-ref --verify refs/tags/TAG_F1_2 && 102 103 cd main && 104 105 git checkout TAG_F1_1 && 106 ls && 107 test_path_is_file f1 && 108 109 git checkout TAG_F1_2 && 110 ls && 111 test_path_is_file f1 112 ) 113 ' 114 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 && 119 ( 120 cd "$git" && 121 git tag -m "A tag created in git:xyzzy" GIT_TAG_1 && 122 echo "hello world" >main/f10 && 123 git add main/f10 && 124 git commit -m "Adding file for export test" && 125 git config git-p4.skipSubmitEdit true && 126 git p4 submit && 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 131 ) && 132 ( 133 cd "$cli" && 134 p4 sync ... && 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_path_is_missing main/f10 && 141 p4 sync ...@GIT_TAG_2 && 142 test_path_is_file main/f10 143 ) 144 ' 145 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 && 152 ( 153 cd "$git" && 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 && 160 git add main/f11 && 161 git commit -m "delete the deleted file" && 162 git config git-p4.skipSubmitEdit true && 163 git p4 submit && 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 168 ) && 169 ( 170 cd "$cli" && 171 p4 sync ... && 172 p4 sync ...@GIT_TAG_ON_DELETED && 173 test_path_is_file main/deleted_file && 174 p4 sync ...@GIT_TAG_AFTER_DELETION && 175 test_path_is_missing main/deleted_file && 176 echo "checking label contents" && 177 p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file" 178 ) 179 ' 180 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 && 185 ( 186 cd "$git" && 187 git checkout -b a_branch && 188 echo "hello" >main/f12 && 189 git add main/f12 && 190 git commit -m "adding f12" && 191 git tag -m "tag on a_branch" GIT_TAG_ON_A_BRANCH && 192 git checkout main && 193 git p4 submit --export-labels 194 ) && 195 ( 196 cd "$cli" && 197 p4 sync ... && 198 ! p4 labels | grep GIT_TAG_ON_A_BRANCH 199 ) 200 ' 201 202 test_expect_success 'use git config to enable import/export of tags' ' 203 git p4 clone --verbose --dest="$git" //depot@all && 204 ( 205 cd "$git" && 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 && 211 git show-ref --verify refs/tags/TAG_F1_1 212 ) && 213 ( 214 cd "$cli" && 215 p4 labels && 216 p4 labels | grep CFG_A_GIT_TAG 217 ) 218 ' 219 220 p4_head_revision() { 221 p4 changes -m 1 "$@" | awk '{print $2}' 222 } 223 224 # Importing a label that references a P4 commit that 225 # has not been seen. The presence of a label on a commit 226 # we haven't seen should not cause git-p4 to fail. It should 227 # merely skip that label, and still import other labels. 228 test_expect_success 'importing labels with missing revisions' ' 229 test_when_finished cleanup_git && 230 ( 231 rm -fr "$cli" "$git" && 232 mkdir "$cli" && 233 P4CLIENT=missing-revision && 234 client_view "//depot/missing-revision/... //missing-revision/..." && 235 cd "$cli" && 236 >f1 && 237 p4 add f1 && 238 p4 submit -d "start" && 239 240 p4 tag -l TAG_S0 ... && 241 242 >f2 && 243 p4 add f2 && 244 p4 submit -d "second" && 245 246 startrev=$(p4_head_revision //depot/missing-revision/...) && 247 248 >f3 && 249 p4 add f3 && 250 p4 submit -d "third" && 251 252 p4 edit f2 && 253 date >f2 && 254 p4 submit -d "change" f2 && 255 256 endrev=$(p4_head_revision //depot/missing-revision/...) && 257 258 p4 tag -l TAG_S1 ... && 259 260 # we should skip TAG_S0 since it is before our startpoint, 261 # but pick up TAG_S1. 262 263 git p4 clone --dest="$git" --import-labels -v \ 264 //depot/missing-revision/...@$startrev,$endrev && 265 ( 266 cd "$git" && 267 git rev-parse TAG_S1 && 268 ! git rev-parse TAG_S0 269 ) 270 ) 271 ' 272 273 test_done