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