| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "list a single lock with bad ref" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="locks-list-other-branch-required" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | git lfs track "*.dat" |
| 14 | echo "f" > f.dat |
| 15 | git add .gitattributes f.dat |
| 16 | git commit -m "add f.dat" |
| 17 | git push origin main:other |
| 18 | |
| 19 | git checkout -b other |
| 20 | git lfs lock --json "f.dat" | tee lock.log |
| 21 | |
| 22 | git checkout main |
| 23 | git lfs locks --path "f.dat" 2>&1 | tee locks.log |
| 24 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 25 | echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail" |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | grep 'Expected ref "refs/heads/other", got "refs/heads/main"' locks.log |
| 30 | ) |
| 31 | end_test |
| 32 | |
| 33 | begin_test "list a single lock" |
| 34 | ( |
| 35 | set -e |
| 36 | |
| 37 | reponame="locks-list-main-branch-required" |
| 38 | setup_remote_repo_with_file "$reponame" "f.dat" |
| 39 | clone_repo "$reponame" "$reponame" |
| 40 | |
| 41 | git lfs lock --json "f.dat" | tee lock.log |
| 42 | |
| 43 | id=$(assert_lock lock.log f.dat) |
| 44 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 45 | |
| 46 | git lfs locks --path "f.dat" | tee locks.log |
| 47 | [ $(wc -l < locks.log) -eq 1 ] |
| 48 | grep "f.dat" locks.log |
| 49 | grep "Git LFS Tests" locks.log |
| 50 | ) |
| 51 | end_test |
| 52 | |
| 53 | begin_test "list a single lock (--remote overrides push default)" |
| 54 | ( |
| 55 | set -e |
| 56 | |
| 57 | reponame="locks-list-remote" |
| 58 | setup_remote_repo_with_file "$reponame" "a.dat" |
| 59 | clone_repo "$reponame" "$reponame" |
| 60 | |
| 61 | git lfs lock --json "a.dat" | tee lock.log |
| 62 | |
| 63 | id=$(assert_lock lock.log "a.dat") |
| 64 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 65 | |
| 66 | # Check invalid "remote.pushDefault" configuration causes error. |
| 67 | git remote add bad-remote "invalid-url" |
| 68 | git config remote.pushDefault bad-remote |
| 69 | |
| 70 | git lfs locks 2>&1 | tee locks.log |
| 71 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 72 | echo >&2 "fatal: expected 'git lfs locks' to fail ..." |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | # Check --remote option overrides "remote.pushDefault" configuration. |
| 77 | git lfs locks --remote origin --path "a.dat" | tee locks.log |
| 78 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 79 | echo >&2 "fatal: expected 'git lfs locks' to succeed ..." |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | [ 1 -eq "$(wc -l <locks.log)" ] |
| 84 | grep -F "a.dat" locks.log |
| 85 | grep -F "ID:$id" locks.log |
| 86 | |
| 87 | # Remove "remote.pushDefault" configuration. |
| 88 | git config --unset remote.pushDefault |
| 89 | |
| 90 | # Check invalid "branch.<name>.pushRemote" configuration causes error. |
| 91 | git config branch.main.pushRemote bad-remote |
| 92 | |
| 93 | git lfs locks 2>&1 | tee locks.log |
| 94 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 95 | echo >&2 "fatal: expected 'git lfs locks' to fail ..." |
| 96 | exit 1 |
| 97 | fi |
| 98 | |
| 99 | # Check --remote option overrides "branch.<name>.pushRemote" configuration. |
| 100 | git lfs locks --remote origin --path "a.dat" | tee locks.log |
| 101 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 102 | echo >&2 "fatal: expected 'git lfs locks' to succeed ..." |
| 103 | exit 1 |
| 104 | fi |
| 105 | |
| 106 | [ 1 -eq "$(wc -l <locks.log)" ] |
| 107 | grep -F "a.dat" locks.log |
| 108 | grep -F "ID:$id" locks.log |
| 109 | ) |
| 110 | end_test |
| 111 | |
| 112 | begin_test "list a single lock (SSH; git-lfs-authenticate)" |
| 113 | ( |
| 114 | set -e |
| 115 | |
| 116 | reponame="locks-list-ssh" |
| 117 | setup_remote_repo_with_file "$reponame" "f.dat" |
| 118 | clone_repo "$reponame" "$reponame" |
| 119 | |
| 120 | sshurl="${GITSERVER/http:\/\//ssh://git@}/$reponame" |
| 121 | git config lfs.url "$sshurl" |
| 122 | |
| 123 | git lfs lock --json "f.dat" | tee lock.log |
| 124 | |
| 125 | id=$(assert_lock lock.log f.dat) |
| 126 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 127 | |
| 128 | GIT_TRACE=1 git lfs locks --path "f.dat" 2>trace.log | tee locks.log |
| 129 | cat trace.log |
| 130 | [ $(wc -l < locks.log) -eq 1 ] |
| 131 | grep "f.dat" locks.log |
| 132 | grep "Git LFS Tests" locks.log |
| 133 | grep "lfs-ssh-echo.*git-lfs-authenticate /$reponame download" trace.log |
| 134 | |
| 135 | GIT_TRACE=1 git -c lfs."$sshurl".sshtransfer=never lfs locks --path "f.dat" 2>trace.log | tee locks.log |
| 136 | [ $(wc -l < locks.log) -eq 1 ] |
| 137 | grep "f.dat" locks.log |
| 138 | grep "Git LFS Tests" locks.log |
| 139 | grep "lfs-ssh-echo.*git-lfs-authenticate /$reponame download" trace.log |
| 140 | grep "skipping pure SSH protocol" trace.log |
| 141 | |
| 142 | GIT_TRACE=1 git -c lfs."$sshurl".sshtransfer=always lfs locks --path "f.dat" 2>trace.log && exit 1 |
| 143 | grep "git-lfs-authenticate has been disabled by request" trace.log |
| 144 | ) |
| 145 | end_test |
| 146 | |
| 147 | begin_test "list a single lock (SSH; git-lfs-transfer)" |
| 148 | ( |
| 149 | set -e |
| 150 | |
| 151 | setup_pure_ssh |
| 152 | |
| 153 | reponame="locks-list-ssh-pure" |
| 154 | setup_remote_repo_with_file "$reponame" "f.dat" |
| 155 | clone_repo "$reponame" "$reponame" |
| 156 | |
| 157 | sshurl=$(ssh_remote "$reponame") |
| 158 | git config lfs.url "$sshurl" |
| 159 | |
| 160 | GIT_TRACE_PACKET=1 git lfs lock --json "f.dat" | tee lock.log |
| 161 | |
| 162 | id=$(assert_lock lock.log f.dat) |
| 163 | assert_server_lock_ssh "$reponame" "$id" "refs/heads/main" |
| 164 | |
| 165 | GIT_TRACE=1 git lfs locks --path "f.dat" 2>trace.log | tee locks.log |
| 166 | cat trace.log |
| 167 | [ $(wc -l < locks.log) -eq 1 ] |
| 168 | grep "f.dat" locks.log |
| 169 | grep "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log |
| 170 | |
| 171 | GIT_TRACE=1 git -c lfs."$sshurl".sshtransfer=always lfs locks --path "f.dat" 2>trace.log | tee locks.log |
| 172 | [ $(wc -l < locks.log) -eq 1 ] |
| 173 | grep "f.dat" locks.log |
| 174 | grep "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log |
| 175 | |
| 176 | GIT_TRACE=1 git -c lfs."$sshurl".sshtransfer=negotiate lfs locks --path "f.dat" 2>trace.log | tee locks.log |
| 177 | [ $(wc -l < locks.log) -eq 1 ] |
| 178 | grep "f.dat" locks.log |
| 179 | grep "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log |
| 180 | ) |
| 181 | end_test |
| 182 | |
| 183 | begin_test "list a single lock (--json)" |
| 184 | ( |
| 185 | set -e |
| 186 | |
| 187 | reponame="locks_list_single_json" |
| 188 | setup_remote_repo_with_file "$reponame" "f_json.dat" |
| 189 | |
| 190 | git lfs lock --json "f_json.dat" | tee lock.log |
| 191 | |
| 192 | id=$(assert_lock lock.log f_json.dat) |
| 193 | assert_server_lock "$reponame" "$id" |
| 194 | |
| 195 | git lfs locks --json --path "f_json.dat" | tee locks.log |
| 196 | grep "\"path\":\"f_json.dat\"" locks.log |
| 197 | grep "\"owner\":{\"name\":\"Git LFS Tests\"}" locks.log |
| 198 | ) |
| 199 | end_test |
| 200 | |
| 201 | begin_test "list locks with a limit" |
| 202 | ( |
| 203 | set -e |
| 204 | |
| 205 | reponame="locks_list_limit" |
| 206 | setup_remote_repo "$reponame" |
| 207 | clone_repo "$reponame" "clone_$reponame" |
| 208 | |
| 209 | git lfs track "*.dat" |
| 210 | echo "foo" > "g_1.dat" |
| 211 | echo "bar" > "g_2.dat" |
| 212 | |
| 213 | git add "g_1.dat" "g_2.dat" ".gitattributes" |
| 214 | git commit -m "add files" | tee commit.log |
| 215 | grep "3 files changed" commit.log |
| 216 | grep "create mode 100644 g_1.dat" commit.log |
| 217 | grep "create mode 100644 g_2.dat" commit.log |
| 218 | grep "create mode 100644 .gitattributes" commit.log |
| 219 | |
| 220 | |
| 221 | git push origin main 2>&1 | tee push.log |
| 222 | grep "main -> main" push.log |
| 223 | |
| 224 | git lfs lock --json "g_1.dat" | tee lock.log |
| 225 | assert_server_lock "$reponame" "$(assert_log "lock.log" g_1.dat)" |
| 226 | |
| 227 | git lfs lock --json "g_2.dat" | tee lock.log |
| 228 | assert_server_lock "$reponame" "$(assert_lock "lock.log" g_2.dat)" |
| 229 | |
| 230 | git lfs locks --limit 1 | tee locks.log |
| 231 | [ $(wc -l < locks.log) -eq 1 ] |
| 232 | ) |
| 233 | end_test |
| 234 | |
| 235 | begin_test "list locks with pagination" |
| 236 | ( |
| 237 | set -e |
| 238 | |
| 239 | reponame="locks_list_paginate" |
| 240 | setup_remote_repo "$reponame" |
| 241 | clone_repo "$reponame" "clone_$reponame" |
| 242 | |
| 243 | git lfs track "*.dat" |
| 244 | for i in $(seq 1 5); do |
| 245 | echo "$i" > "h_$i.dat" |
| 246 | done |
| 247 | |
| 248 | git add "h_1.dat" "h_2.dat" "h_3.dat" "h_4.dat" "h_5.dat" ".gitattributes" |
| 249 | |
| 250 | git commit -m "add files" | tee commit.log |
| 251 | grep "6 files changed" commit.log |
| 252 | for i in $(seq 1 5); do |
| 253 | grep "create mode 100644 h_$i.dat" commit.log |
| 254 | done |
| 255 | grep "create mode 100644 .gitattributes" commit.log |
| 256 | |
| 257 | git push origin main 2>&1 | tee push.log |
| 258 | grep "main -> main" push.log |
| 259 | |
| 260 | for i in $(seq 1 5); do |
| 261 | git lfs lock --json "h_$i.dat" | tee lock.log |
| 262 | assert_server_lock "$reponame" "$(assert_lock "lock.log" "h_$i.dat")" |
| 263 | done |
| 264 | |
| 265 | # The server will return, at most, three locks at a time |
| 266 | git lfs locks --limit 4 | tee locks.log |
| 267 | [ $(wc -l < locks.log) -eq 4 ] |
| 268 | ) |
| 269 | end_test |
| 270 | |
| 271 | begin_test "cached locks" |
| 272 | ( |
| 273 | set -e |
| 274 | |
| 275 | reponame="cached_locks" |
| 276 | setup_remote_repo "remote_$reponame" |
| 277 | clone_repo "remote_$reponame" "clone_$reponame" |
| 278 | |
| 279 | git lfs track "*.dat" |
| 280 | echo "foo" > "cached1.dat" |
| 281 | echo "bar" > "cached2.dat" |
| 282 | |
| 283 | git add "cached1.dat" "cached2.dat" ".gitattributes" |
| 284 | git commit -m "add files" | tee commit.log |
| 285 | grep "3 files changed" commit.log |
| 286 | grep "create mode 100644 cached1.dat" commit.log |
| 287 | grep "create mode 100644 cached2.dat" commit.log |
| 288 | grep "create mode 100644 .gitattributes" commit.log |
| 289 | |
| 290 | git push origin main 2>&1 | tee push.log |
| 291 | grep "main -> main" push.log |
| 292 | |
| 293 | git lfs lock --json "cached1.dat" | tee lock.log |
| 294 | assert_server_lock "$(assert_lock "lock.log" cached1.dat)" |
| 295 | |
| 296 | git lfs lock --json "cached2.dat" | tee lock.log |
| 297 | assert_server_lock "$(assert_lock "lock.log" cached2.dat)" |
| 298 | |
| 299 | git lfs locks --local | tee locks.log |
| 300 | [ $(wc -l < locks.log) -eq 2 ] |
| 301 | |
| 302 | # delete the remote to prove we're using the local records |
| 303 | git remote remove origin |
| 304 | |
| 305 | git lfs locks --local --path "cached1.dat" | tee locks.log |
| 306 | [ $(wc -l < locks.log) -eq 1 ] |
| 307 | grep "cached1.dat" locks.log |
| 308 | |
| 309 | git lfs locks --local --limit 1 | tee locks.log |
| 310 | [ $(wc -l < locks.log) -eq 1 ] |
| 311 | ) |
| 312 | end_test |
| 313 | |
| 314 | begin_test "cached locks with failed lock" |
| 315 | ( |
| 316 | set -e |
| 317 | |
| 318 | reponame="cached-locks-failed-lock" |
| 319 | setup_remote_repo "remote_$reponame" |
| 320 | clone_repo "remote_$reponame" "clone_$reponame" |
| 321 | |
| 322 | git lfs track "*.dat" |
| 323 | echo "foo" > "cached1.dat" |
| 324 | echo "bar" > "cached2.dat" |
| 325 | |
| 326 | git add "cached1.dat" "cached2.dat" ".gitattributes" |
| 327 | git commit -m "add files" | tee commit.log |
| 328 | grep "3 files changed" commit.log |
| 329 | grep "create mode 100644 cached1.dat" commit.log |
| 330 | grep "create mode 100644 cached2.dat" commit.log |
| 331 | grep "create mode 100644 .gitattributes" commit.log |
| 332 | |
| 333 | git push origin main 2>&1 | tee push.log |
| 334 | grep "main -> main" push.log |
| 335 | |
| 336 | git lfs lock --json "cached1.dat" | tee lock.log |
| 337 | assert_server_lock "$(assert_lock "lock.log" cached1.dat)" |
| 338 | |
| 339 | git lfs lock --json "cached1.dat" "cached2.dat" | tee lock.log |
| 340 | assert_server_lock "$(assert_lock "lock.log" cached2.dat)" |
| 341 | |
| 342 | git lfs locks --local | tee locks.log |
| 343 | [ $(wc -l < locks.log) -eq 2 ] |
| 344 | |
| 345 | git lfs unlock --json "cached1.dat" |
| 346 | |
| 347 | git lfs unlock --json "cached1.dat" "cached2.dat" || true |
| 348 | |
| 349 | git lfs locks --local | tee locks.log |
| 350 | [ $(wc -l < locks.log) -eq 0 ] |
| 351 | ) |
| 352 | end_test |