| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git p4 options' |
| 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 | test_expect_success 'init depot' ' |
| 15 | ( |
| 16 | cd "$cli" && |
| 17 | echo file1 >file1 && |
| 18 | p4 add file1 && |
| 19 | p4 submit -d "change 1" && |
| 20 | echo file2 >file2 && |
| 21 | p4 add file2 && |
| 22 | p4 submit -d "change 2" && |
| 23 | echo file3 >file3 && |
| 24 | p4 add file3 && |
| 25 | p4 submit -d "change 3" |
| 26 | ) |
| 27 | ' |
| 28 | |
| 29 | test_expect_success 'clone no --git-dir' ' |
| 30 | test_must_fail git p4 clone --git-dir=xx //depot |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'clone --branch should checkout main' ' |
| 34 | git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot && |
| 35 | test_when_finished cleanup_git && |
| 36 | ( |
| 37 | cd "$git" && |
| 38 | git rev-parse refs/remotes/p4/sb >sb && |
| 39 | git rev-parse refs/heads/main >main && |
| 40 | test_cmp sb main && |
| 41 | git rev-parse HEAD >head && |
| 42 | test_cmp sb head |
| 43 | ) |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'sync when no master branch prints a nice error' ' |
| 47 | test_when_finished cleanup_git && |
| 48 | git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 && |
| 49 | ( |
| 50 | cd "$git" && |
| 51 | test_must_fail git p4 sync 2>err && |
| 52 | grep "Error: no branch refs/remotes/p4/master" err |
| 53 | ) |
| 54 | ' |
| 55 | |
| 56 | test_expect_success 'sync --branch builds the full ref name correctly' ' |
| 57 | test_when_finished cleanup_git && |
| 58 | ( |
| 59 | cd "$git" && |
| 60 | git init && |
| 61 | |
| 62 | git p4 sync --branch=b1 //depot && |
| 63 | git rev-parse --verify refs/remotes/p4/b1 && |
| 64 | git p4 sync --branch=p4/b2 //depot && |
| 65 | git rev-parse --verify refs/remotes/p4/b2 && |
| 66 | |
| 67 | git p4 sync --import-local --branch=h1 //depot && |
| 68 | git rev-parse --verify refs/heads/p4/h1 && |
| 69 | git p4 sync --import-local --branch=p4/h2 //depot && |
| 70 | git rev-parse --verify refs/heads/p4/h2 && |
| 71 | |
| 72 | git p4 sync --branch=refs/stuff //depot && |
| 73 | git rev-parse --verify refs/stuff |
| 74 | ) |
| 75 | ' |
| 76 | |
| 77 | # engages --detect-branches code, which will do filename filtering so |
| 78 | # no sync to either b1 or b2 |
| 79 | test_expect_success 'sync when two branches but no master should noop' ' |
| 80 | test_when_finished cleanup_git && |
| 81 | ( |
| 82 | cd "$git" && |
| 83 | git init && |
| 84 | git p4 sync --branch=refs/remotes/p4/b1 //depot@2 && |
| 85 | git p4 sync --branch=refs/remotes/p4/b2 //depot@2 && |
| 86 | git p4 sync && |
| 87 | git show -s --format=%s refs/remotes/p4/b1 >show && |
| 88 | grep "Initial import" show && |
| 89 | git show -s --format=%s refs/remotes/p4/b2 >show && |
| 90 | grep "Initial import" show |
| 91 | ) |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'sync --branch updates specific branch, no detection' ' |
| 95 | test_when_finished cleanup_git && |
| 96 | ( |
| 97 | cd "$git" && |
| 98 | git init && |
| 99 | git p4 sync --branch=b1 //depot@2 && |
| 100 | git p4 sync --branch=b2 //depot@2 && |
| 101 | git p4 sync --branch=b2 && |
| 102 | git show -s --format=%s refs/remotes/p4/b1 >show && |
| 103 | grep "Initial import" show && |
| 104 | git show -s --format=%s refs/remotes/p4/b2 >show && |
| 105 | grep "change 3" show |
| 106 | ) |
| 107 | ' |
| 108 | |
| 109 | # allows using the refname "p4" as a short name for p4/master |
| 110 | test_expect_success 'clone creates HEAD symbolic reference' ' |
| 111 | git p4 clone --dest="$git" //depot && |
| 112 | test_when_finished cleanup_git && |
| 113 | ( |
| 114 | cd "$git" && |
| 115 | git rev-parse --verify refs/remotes/p4/master >master && |
| 116 | git rev-parse --verify p4 >p4 && |
| 117 | test_cmp master p4 |
| 118 | ) |
| 119 | ' |
| 120 | |
| 121 | test_expect_success 'clone --branch creates HEAD symbolic reference' ' |
| 122 | git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot && |
| 123 | test_when_finished cleanup_git && |
| 124 | ( |
| 125 | cd "$git" && |
| 126 | git rev-parse --verify refs/remotes/p4/sb >sb && |
| 127 | git rev-parse --verify p4 >p4 && |
| 128 | test_cmp sb p4 |
| 129 | ) |
| 130 | ' |
| 131 | |
| 132 | test_expect_success 'clone --changesfile' ' |
| 133 | test_when_finished "rm cf" && |
| 134 | printf "1\n3\n" >cf && |
| 135 | git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot && |
| 136 | test_when_finished cleanup_git && |
| 137 | ( |
| 138 | cd "$git" && |
| 139 | git log --oneline p4/master >lines && |
| 140 | test_line_count = 2 lines && |
| 141 | test_path_is_file file1 && |
| 142 | test_path_is_missing file2 && |
| 143 | test_path_is_file file3 |
| 144 | ) |
| 145 | ' |
| 146 | |
| 147 | test_expect_success 'clone --changesfile, @all' ' |
| 148 | test_when_finished "rm cf" && |
| 149 | printf "1\n3\n" >cf && |
| 150 | test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all |
| 151 | ' |
| 152 | |
| 153 | # imports both main and p4/master in refs/heads |
| 154 | # requires --import-local on sync to find p4 refs/heads |
| 155 | # does not update main on sync, just p4/master |
| 156 | test_expect_success 'clone/sync --import-local' ' |
| 157 | git p4 clone --import-local --dest="$git" //depot@1,2 && |
| 158 | test_when_finished cleanup_git && |
| 159 | ( |
| 160 | cd "$git" && |
| 161 | git log --oneline refs/heads/main >lines && |
| 162 | test_line_count = 2 lines && |
| 163 | git log --oneline refs/heads/p4/master >lines && |
| 164 | test_line_count = 2 lines && |
| 165 | test_must_fail git p4 sync && |
| 166 | |
| 167 | git p4 sync --import-local && |
| 168 | git log --oneline refs/heads/main >lines && |
| 169 | test_line_count = 2 lines && |
| 170 | git log --oneline refs/heads/p4/master >lines && |
| 171 | test_line_count = 3 lines |
| 172 | ) |
| 173 | ' |
| 174 | |
| 175 | test_expect_success 'clone --max-changes' ' |
| 176 | git p4 clone --dest="$git" --max-changes 2 //depot@all && |
| 177 | test_when_finished cleanup_git && |
| 178 | ( |
| 179 | cd "$git" && |
| 180 | git log --oneline refs/heads/main >lines && |
| 181 | test_line_count = 2 lines |
| 182 | ) |
| 183 | ' |
| 184 | |
| 185 | test_expect_success 'clone --keep-path' ' |
| 186 | ( |
| 187 | cd "$cli" && |
| 188 | mkdir -p sub/dir && |
| 189 | echo f4 >sub/dir/f4 && |
| 190 | p4 add sub/dir/f4 && |
| 191 | p4 submit -d "change 4" |
| 192 | ) && |
| 193 | git p4 clone --dest="$git" --keep-path //depot/sub/dir@all && |
| 194 | test_when_finished cleanup_git && |
| 195 | ( |
| 196 | cd "$git" && |
| 197 | test_path_is_missing f4 && |
| 198 | test_path_is_file sub/dir/f4 |
| 199 | ) && |
| 200 | cleanup_git && |
| 201 | git p4 clone --dest="$git" //depot/sub/dir@all && |
| 202 | ( |
| 203 | cd "$git" && |
| 204 | test_path_is_file f4 && |
| 205 | test_path_is_missing sub/dir/f4 |
| 206 | ) |
| 207 | ' |
| 208 | |
| 209 | # clone --use-client-spec must still specify a depot path |
| 210 | # if given, it should rearrange files according to client spec |
| 211 | # when it has view lines that match the depot path |
| 212 | # XXX: should clone/sync just use the client spec exactly, rather |
| 213 | # than needing depot paths? |
| 214 | test_expect_success 'clone --use-client-spec' ' |
| 215 | ( |
| 216 | # big usage message |
| 217 | exec >/dev/null && |
| 218 | test_must_fail git p4 clone --dest="$git" --use-client-spec |
| 219 | ) && |
| 220 | # build a different client |
| 221 | cli2="$TRASH_DIRECTORY/cli2" && |
| 222 | mkdir -p "$cli2" && |
| 223 | test_when_finished "rmdir \"$cli2\"" && |
| 224 | test_when_finished cleanup_git && |
| 225 | ( |
| 226 | # group P4CLIENT and cli changes in a sub-shell |
| 227 | P4CLIENT=client2 && |
| 228 | cli="$cli2" && |
| 229 | client_view "//depot/sub/... //client2/bus/..." && |
| 230 | git p4 clone --dest="$git" --use-client-spec //depot/... && |
| 231 | ( |
| 232 | cd "$git" && |
| 233 | test_path_is_file bus/dir/f4 && |
| 234 | test_path_is_missing file1 |
| 235 | ) && |
| 236 | cleanup_git && |
| 237 | # same thing again, this time with variable instead of option |
| 238 | ( |
| 239 | cd "$git" && |
| 240 | git init && |
| 241 | git config git-p4.useClientSpec true && |
| 242 | git p4 sync //depot/... && |
| 243 | git checkout -b main p4/master && |
| 244 | test_path_is_file bus/dir/f4 && |
| 245 | test_path_is_missing file1 |
| 246 | ) |
| 247 | ) |
| 248 | ' |
| 249 | |
| 250 | test_expect_success 'submit works with no p4/master' ' |
| 251 | test_when_finished cleanup_git && |
| 252 | git p4 clone --branch=b1 //depot@1,2 --destination="$git" && |
| 253 | ( |
| 254 | cd "$git" && |
| 255 | test_commit submit-1-branch && |
| 256 | git config git-p4.skipSubmitEdit true && |
| 257 | git p4 submit --branch=b1 |
| 258 | ) |
| 259 | ' |
| 260 | |
| 261 | # The sync/rebase part post-submit will engage detect-branches |
| 262 | # machinery which will not do anything in this particular test. |
| 263 | test_expect_success 'submit works with two branches' ' |
| 264 | test_when_finished cleanup_git && |
| 265 | git p4 clone --branch=b1 //depot@1,2 --destination="$git" && |
| 266 | ( |
| 267 | cd "$git" && |
| 268 | git p4 sync --branch=b2 //depot@1,3 && |
| 269 | test_commit submit-2-branches && |
| 270 | git config git-p4.skipSubmitEdit true && |
| 271 | git p4 submit |
| 272 | ) |
| 273 | ' |
| 274 | |
| 275 | test_expect_success 'use --git-dir option and GIT_DIR' ' |
| 276 | test_when_finished cleanup_git && |
| 277 | git p4 clone //depot --destination="$git" && |
| 278 | ( |
| 279 | cd "$git" && |
| 280 | git config git-p4.skipSubmitEdit true && |
| 281 | test_commit first-change && |
| 282 | git p4 submit --git-dir "$git" |
| 283 | ) && |
| 284 | ( |
| 285 | cd "$cli" && |
| 286 | p4 sync && |
| 287 | test_path_is_file first-change.t && |
| 288 | echo "cli_file" >cli_file.t && |
| 289 | p4 add cli_file.t && |
| 290 | p4 submit -d "cli change" |
| 291 | ) && |
| 292 | (git --git-dir "$git" p4 sync) && |
| 293 | (cd "$git" && git checkout -q p4/master) && |
| 294 | test_path_is_file "$git"/cli_file.t && |
| 295 | ( |
| 296 | cd "$cli" && |
| 297 | echo "cli_file2" >cli_file2.t && |
| 298 | p4 add cli_file2.t && |
| 299 | p4 submit -d "cli change2" |
| 300 | ) && |
| 301 | (GIT_DIR="$git" git p4 sync) && |
| 302 | (cd "$git" && git checkout -q p4/master) && |
| 303 | test_path_is_file "$git"/cli_file2.t |
| 304 | ' |
| 305 | |
| 306 | test_done |