1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
|
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "lock with good ref"
(
set -e
reponame="lock-main-branch-required"
setup_remote_repo_with_file "$reponame" "a.dat"
clone_repo "$reponame" "$reponame"
git lfs lock "a.dat" --json 2>&1 | tee lock.json
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
exit 1
fi
id=$(assert_lock lock.json a.dat)
assert_server_lock "$reponame" "$id" "refs/heads/main"
)
end_test
begin_test "lock with good tracked ref"
(
set -e
reponame="lock-tracked-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
echo "a" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
git config push.default upstream
git config branch.main.merge refs/heads/tracked
git config branch.main.remote origin
git push origin main
git lfs lock "a.dat" --json 2>&1 | tee lock.json
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
exit 1
fi
id=$(assert_lock lock.json a.dat)
assert_server_lock "$reponame" "$id" "refs/heads/tracked"
)
end_test
begin_test "lock with bad ref"
(
set -e
reponame="lock-other-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
echo "a" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
git push origin main:other
GIT_CURL_VERBOSE=1 git lfs lock "a.dat" 2>&1 | tee lock.json
if [ "0" -eq "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to fail"
exit 1
fi
grep 'Locking a.dat failed: Expected ref "refs/heads/other", got "refs/heads/main"' lock.json
)
end_test
begin_test "lock multiple files"
(
set -e
reponame="lock-multiple-files"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
echo "a" > a.dat
echo "b" > b.dat
git add .gitattributes a.dat b.dat
git commit -m "add dat files"
git push origin main:other
GIT_TRACE=0 git lfs lock *.dat >log 2>errlog
[ $(grep -c "Locked [ab].dat" log) -eq 2 ]
grep -v CREDS errlog && exit 1
grep "Usage:" errlog && exit 1
true
)
end_test
begin_test "lock multiple files (JSON)"
(
set -e
reponame="lock-multiple-files-json"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
echo "a" > a.dat
echo "b" > b.dat
git add .gitattributes a.dat b.dat
git commit -m "add dat files"
git push origin main:other
git lfs lock --json *.dat | tee lock.json
grep -E '\[\{"id":"[^"]+","path":"a\.dat","owner":\{"name":"Git LFS Tests"\},"locked_at":"[^"]+"\},\{"id":"[^"]+","path":"b\.dat","owner":\{"name":"Git LFS Tests"\},"locked_at":"[^"]+"\}\]' lock.json
)
end_test
begin_test "lock absolute path"
(
set -e
reponame="lock-absolute-path"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
echo "a" > a.dat
echo "b" > b.dat
git add .gitattributes a.dat b.dat
git commit -m "add dat files"
git push origin main:other
git lfs lock --json "$(pwd)/a.dat" | tee lock.json
id=$(assert_lock lock.json a.dat)
assert_server_lock "$reponame" "$id"
)
end_test
begin_test "create lock with server using client cert"
(
set -e
git config --global "http.$LFS_CLIENT_CERT_URL/.sslCert" "$LFS_CLIENT_CERT_FILE"
git config --global "http.$LFS_CLIENT_CERT_URL/.sslKey" "$LFS_CLIENT_KEY_FILE"
reponame="lock_create_client_cert"
setup_remote_repo_with_file "$reponame" "cc.dat"
git config lfs.url "$CLIENTCERTGITSERVER/$reponame.git/info/lfs"
git lfs lock --json "cc.dat" | tee lock.json
id=$(assert_lock lock.json cc.dat)
assert_server_lock "$reponame" "$id"
)
end_test
begin_test "creating a lock (with output)"
(
set -e
reponame="lock_create_simple_output"
setup_remote_repo_with_file "$reponame" "a_output.dat"
git lfs lock "a_output.dat" | tee lock.log
grep "Locked a_output.dat" lock.log
id=$(grep -oh "\((.*)\)" lock.log | tr -d \(\))
assert_server_lock "$reponame" "$id"
)
end_test
begin_test "locking a file that doesn't exist"
(
set -e
reponame="lock_create_nonexistent"
setup_remote_repo_with_file "$reponame" "a_output.dat"
git lfs lock "b_output.dat" | tee lock.log
grep "Locked b_output.dat" lock.log
id=$(grep -oh "\((.*)\)" lock.log | tr -d \(\))
assert_server_lock "$reponame" "$id"
)
end_test
begin_test "locking a previously locked file"
(
set -e
reponame="lock_create_previously_created"
setup_remote_repo_with_file "$reponame" "b.dat"
git lfs lock --json "b.dat" | tee lock.json
id=$(assert_lock lock.json b.dat)
assert_server_lock "$reponame" "$id"
grep "lock already created" <(git lfs lock "b.dat" 2>&1)
)
end_test
begin_test "locking a directory"
(
set -e
reponame="locking_directories"
setup_remote_repo "remote_$reponame"
clone_repo "remote_$reponame" "clone_$reponame"
git lfs track "*.dat"
mkdir dir
echo "a" > dir/a.dat
git add dir/a.dat .gitattributes
git commit -m "add dir/a.dat" | tee commit.log
grep "main (root-commit)" commit.log
grep "2 files changed" commit.log
grep "create mode 100644 dir/a.dat" commit.log
grep "create mode 100644 .gitattributes" commit.log
git push origin main 2>&1 | tee push.log
grep "main -> main" push.log
git lfs lock ./dir/ 2>&1 | tee lock.log
grep "cannot lock directory" lock.log
)
end_test
begin_test "locking a nested file"
(
set -e
reponame="locking-nested-file"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat" --lockable
git add .gitattributes
git commit -m "initial commit"
mkdir -p foo/bar/baz
contents="contents"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > foo/bar/baz/a.dat
git add foo/bar/baz/a.dat
git commit -m "add a.dat"
git push origin main
assert_server_object "$reponame" "$contents_oid"
git lfs lock foo/bar/baz/a.dat 2>&1 | tee lock.log
grep "Locked foo/bar/baz/a.dat" lock.log
git lfs locks 2>&1 | tee locks.log
grep "foo/bar/baz/a.dat" locks.log
)
end_test
begin_test "creating a lock (within subdirectory)"
(
set -e
reponame="lock_create_within_subdirectory"
setup_remote_repo_with_file "$reponame" "sub/a.dat"
cd sub
git lfs lock --json "a.dat" | tee lock.json
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
exit 1
fi
id=$(assert_lock lock.json sub/a.dat)
assert_server_lock "$reponame" "$id"
)
end_test
begin_test "creating a lock (symlinked working directory)"
(
set -eo pipefail
if [[ $(uname) == *"MINGW"* ]]; then
echo >&2 "info: skipped on Windows ..."
exit 0
fi
reponame="lock-in-symlinked-working-directory"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track -l "*.dat"
mkdir -p folder1 folder2
printf "hello" > folder2/a.dat
add_symlink "../folder2" "folder1/folder2"
git add --all .
git commit -m "initial commit"
git push origin main
pushd "$TRASHDIR" > /dev/null
ln -s "$reponame" "$reponame-symlink"
cd "$reponame-symlink"
git lfs lock --json folder1/folder2/a.dat 2>&1 | tee lock.json
id="$(assert_lock lock.json folder1/folder2/a.dat)"
assert_server_lock "$reponame" "$id" main
popd > /dev/null
)
end_test
begin_test "lock with .gitignore"
(
set -e
reponame="lock-with-gitignore"
setup_remote_repo_with_file "$reponame" "a.txt"
clone_repo "$reponame" "$reponame"
echo "*.txt filter=lfs diff=lfs merge=lfs -text lockable" > .gitattributes
git add .gitattributes
git commit -m ".gitattributes: mark 'a.txt' as lockable"
rm -f a.txt && git checkout a.txt
refute_file_writeable a.txt
echo "*.txt" > .gitignore
git add .gitignore
git commit -m ".gitignore: ignore 'a.txt'"
rm -f a.txt && git checkout a.txt
refute_file_writeable a.txt
)
end_test
begin_test "lock with .gitignore and lfs.lockignoredfiles"
(
set -e
reponame="lock-with-gitignore-and-ignoredfiles"
setup_remote_repo_with_file "$reponame" "a.txt"
clone_repo "$reponame" "$reponame"
git config lfs.lockignoredfiles true
echo "*.txt filter=lfs diff=lfs merge=lfs -text lockable" > .gitattributes
git add .gitattributes
git commit -m ".gitattributes: mark 'a.txt' as lockable"
rm -f a.txt && git checkout a.txt
refute_file_writeable a.txt
echo "*.txt" > .gitignore
git add .gitignore
git commit -m ".gitignore: ignore 'a.txt'"
rm -f a.txt && git checkout a.txt
refute_file_writeable a.txt
)
end_test
begin_test "lock with git-lfs-transfer"
(
set -e
setup_pure_ssh
reponame="lock-with-git-lfs-transfer"
setup_remote_repo_with_file "$reponame" "f.dat"
clone_repo "$reponame" "$reponame"
sshurl=$(ssh_remote "$reponame")
git config lfs.url "$sshurl"
GIT_TRACE_PACKET=1 git lfs lock --json "f.dat" | tee lock.log
id=$(assert_lock lock.log f.dat)
assert_server_lock_ssh "$reponame" "$id" "refs/heads/main"
)
end_test
|