Git fork
at reftables-rust 263 lines 6.5 kB view raw
1#!/bin/sh 2 3test_description='git p4 label tests' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8. ./lib-git-p4.sh 9 10test_expect_success 'start p4d' ' 11 start_p4d 12' 13 14# Basic p4 label import tests. 15# 16test_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 -f f2 && 66 git checkout TAG_WITH\$_SHELL_CHAR && 67 test -f f1 && test -f f2 && test -f file_with_\$metachar && 68 69 git show TAG_LONG_LABEL | grep -q "A Label second line" 70 ) 71' 72# Test some label corner cases: 73# 74# - two tags on the same file; both should be available 75# - a tag that is only on one file; this kind of tag 76# cannot be imported (at least not easily). 77 78test_expect_success 'two labels on the same changelist' ' 79 test_when_finished cleanup_git && 80 ( 81 cd "$cli" && 82 mkdir -p main && 83 84 p4 edit main/f1 main/f2 && 85 echo "hello world" >main/f1 && 86 echo "not in the tag" >main/f2 && 87 p4 submit -d "main/f[12]: testing two labels" && 88 89 p4 tag -l TAG_F1_1 main/... && 90 p4 tag -l TAG_F1_2 main/... && 91 92 p4 labels ... && 93 94 git p4 clone --dest="$git" //depot@all && 95 cd "$git" && 96 git p4 sync --import-labels && 97 98 git show-ref --verify refs/tags/TAG_F1_1 && 99 git show-ref --verify refs/tags/TAG_F1_2 && 100 101 cd main && 102 103 git checkout TAG_F1_1 && 104 ls && 105 test -f f1 && 106 107 git checkout TAG_F1_2 && 108 ls && 109 test -f f1 110 ) 111' 112 113# Export some git tags to p4 114test_expect_success 'export git tags to p4' ' 115 test_when_finished cleanup_git && 116 git p4 clone --dest="$git" //depot@all && 117 ( 118 cd "$git" && 119 git tag -m "A tag created in git:xyzzy" GIT_TAG_1 && 120 echo "hello world" >main/f10 && 121 git add main/f10 && 122 git commit -m "Adding file for export test" && 123 git config git-p4.skipSubmitEdit true && 124 git p4 submit && 125 git tag -m "Another git tag" GIT_TAG_2 && 126 git tag LIGHTWEIGHT_TAG && 127 git p4 rebase --import-labels --verbose && 128 git p4 submit --export-labels --verbose 129 ) && 130 ( 131 cd "$cli" && 132 p4 sync ... && 133 p4 labels ... | grep GIT_TAG_1 && 134 p4 labels ... | grep GIT_TAG_2 && 135 p4 labels ... | grep LIGHTWEIGHT_TAG && 136 p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" && 137 p4 sync ...@GIT_TAG_1 && 138 ! test -f main/f10 && 139 p4 sync ...@GIT_TAG_2 && 140 test -f main/f10 141 ) 142' 143 144# Export a tag from git where an affected file is deleted later on 145# Need to create git tags after rebase, since only then can the 146# git commits be mapped to p4 changelists. 147test_expect_success 'export git tags to p4 with deletion' ' 148 test_when_finished cleanup_git && 149 git p4 clone --dest="$git" //depot@all && 150 ( 151 cd "$git" && 152 git p4 sync --import-labels && 153 echo "deleted file" >main/deleted_file && 154 git add main/deleted_file && 155 git commit -m "create deleted file" && 156 git rm main/deleted_file && 157 echo "new file" >main/f11 && 158 git add main/f11 && 159 git commit -m "delete the deleted file" && 160 git config git-p4.skipSubmitEdit true && 161 git p4 submit && 162 git p4 rebase --import-labels --verbose && 163 git tag -m "tag on deleted file" GIT_TAG_ON_DELETED HEAD~1 && 164 git tag -m "tag after deletion" GIT_TAG_AFTER_DELETION HEAD && 165 git p4 submit --export-labels --verbose 166 ) && 167 ( 168 cd "$cli" && 169 p4 sync ... && 170 p4 sync ...@GIT_TAG_ON_DELETED && 171 test -f main/deleted_file && 172 p4 sync ...@GIT_TAG_AFTER_DELETION && 173 ! test -f main/deleted_file && 174 echo "checking label contents" && 175 p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file" 176 ) 177' 178 179# Create a tag in git that cannot be exported to p4 180test_expect_success 'tag that cannot be exported' ' 181 test_when_finished cleanup_git && 182 git p4 clone --dest="$git" //depot@all && 183 ( 184 cd "$git" && 185 git checkout -b a_branch && 186 echo "hello" >main/f12 && 187 git add main/f12 && 188 git commit -m "adding f12" && 189 git tag -m "tag on a_branch" GIT_TAG_ON_A_BRANCH && 190 git checkout main && 191 git p4 submit --export-labels 192 ) && 193 ( 194 cd "$cli" && 195 p4 sync ... && 196 ! p4 labels | grep GIT_TAG_ON_A_BRANCH 197 ) 198' 199 200test_expect_success 'use git config to enable import/export of tags' ' 201 git p4 clone --verbose --dest="$git" //depot@all && 202 ( 203 cd "$git" && 204 git config git-p4.exportLabels true && 205 git config git-p4.importLabels true && 206 git tag CFG_A_GIT_TAG && 207 git p4 rebase --verbose && 208 git p4 submit --verbose && 209 git show-ref --verify refs/tags/TAG_F1_1 210 ) && 211 ( 212 cd "$cli" && 213 p4 labels && 214 p4 labels | grep CFG_A_GIT_TAG 215 ) 216' 217 218p4_head_revision() { 219 p4 changes -m 1 "$@" | awk '{print $2}' 220} 221 222# Importing a label that references a P4 commit that 223# has not been seen. The presence of a label on a commit 224# we haven't seen should not cause git-p4 to fail. It should 225# merely skip that label, and still import other labels. 226test_expect_success 'importing labels with missing revisions' ' 227 test_when_finished cleanup_git && 228 ( 229 rm -fr "$cli" "$git" && 230 mkdir "$cli" && 231 P4CLIENT=missing-revision && 232 client_view "//depot/missing-revision/... //missing-revision/..." && 233 cd "$cli" && 234 >f1 && p4 add f1 && p4 submit -d "start" && 235 236 p4 tag -l TAG_S0 ... && 237 238 >f2 && p4 add f2 && p4 submit -d "second" && 239 240 startrev=$(p4_head_revision //depot/missing-revision/...) && 241 242 >f3 && p4 add f3 && p4 submit -d "third" && 243 244 p4 edit f2 && date >f2 && p4 submit -d "change" f2 && 245 246 endrev=$(p4_head_revision //depot/missing-revision/...) && 247 248 p4 tag -l TAG_S1 ... && 249 250 # we should skip TAG_S0 since it is before our startpoint, 251 # but pick up TAG_S1. 252 253 git p4 clone --dest="$git" --import-labels -v \ 254 //depot/missing-revision/...@$startrev,$endrev && 255 ( 256 cd "$git" && 257 git rev-parse TAG_S1 && 258 ! git rev-parse TAG_S0 259 ) 260 ) 261' 262 263test_done