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
|
#!/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 'Lock failed: Expected ref "refs/heads/other", got "refs/heads/main"' lock.json
)
end_test
begin_test "create lock with server using client cert"
(
set -e
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
|