2016-06-03 16:36:26 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2016-06-03 16:36:26 +00:00
|
|
|
|
2017-12-06 22:50:08 +00:00
|
|
|
begin_test "lock with good ref"
|
2016-06-03 16:36:26 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
reponame="lock-main-branch-required"
|
2016-12-28 23:22:47 +00:00
|
|
|
setup_remote_repo_with_file "$reponame" "a.dat"
|
2017-12-06 22:50:08 +00:00
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs lock "a.dat" --json 2>&1 | tee lock.json
|
|
|
|
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
|
2018-05-04 21:48:34 +00:00
|
|
|
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
|
2017-12-06 22:50:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-06-03 16:36:26 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
id=$(assert_lock lock.json a.dat)
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_lock "$reponame" "$id" "refs/heads/main"
|
2016-06-03 16:36:26 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-12-06 22:50:08 +00:00
|
|
|
begin_test "lock with good tracked ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-tracked-branch-required"
|
2018-01-05 21:25:50 +00:00
|
|
|
setup_remote_repo "$reponame"
|
2017-12-06 22:50:08 +00:00
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
2018-01-05 21:25:50 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "a" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
2017-12-06 22:50:08 +00:00
|
|
|
git config push.default upstream
|
2020-06-29 16:18:57 +00:00
|
|
|
git config branch.main.merge refs/heads/tracked
|
|
|
|
git config branch.main.remote origin
|
|
|
|
git push origin main
|
2018-01-05 21:25:50 +00:00
|
|
|
|
2017-12-06 22:50:08 +00:00
|
|
|
git lfs lock "a.dat" --json 2>&1 | tee lock.json
|
|
|
|
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
|
2018-05-04 21:48:34 +00:00
|
|
|
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
|
2017-12-06 22:50:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
id=$(assert_lock lock.json a.dat)
|
2017-12-06 23:47:57 +00:00
|
|
|
assert_server_lock "$reponame" "$id" "refs/heads/tracked"
|
2017-12-06 22:50:08 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "lock with bad ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-other-branch-required"
|
2018-01-05 21:25:50 +00:00
|
|
|
setup_remote_repo "$reponame"
|
2017-12-06 22:50:08 +00:00
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
2018-01-05 21:25:50 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "a" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main:other
|
2018-01-05 21:25:50 +00:00
|
|
|
|
|
|
|
GIT_CURL_VERBOSE=1 git lfs lock "a.dat" 2>&1 | tee lock.json
|
2017-12-06 22:50:08 +00:00
|
|
|
if [ "0" -eq "${PIPESTATUS[0]}" ]; then
|
2018-05-04 21:48:34 +00:00
|
|
|
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to fail"
|
2017-12-06 22:50:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-22 13:35:29 +00:00
|
|
|
grep 'Locking a.dat failed: Expected ref "refs/heads/other", got "refs/heads/main"' lock.json
|
2017-12-06 22:50:08 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2021-06-17 13:25:25 +00:00
|
|
|
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
|
|
|
|
|
2021-07-22 13:35:29 +00:00
|
|
|
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
|
2021-06-17 13:25:25 +00:00
|
|
|
|
2021-07-22 13:35:29 +00:00
|
|
|
git lfs lock --json *.dat | tee lock.json
|
2021-10-07 14:35:33 +00:00
|
|
|
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
|
2021-06-17 13:25:25 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2021-06-17 13:25:46 +00:00
|
|
|
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
|
|
|
|
|
2017-01-24 22:19:12 +00:00
|
|
|
begin_test "create lock with server using client cert"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="lock_create_client_cert"
|
2017-01-25 08:29:23 +00:00
|
|
|
setup_remote_repo_with_file "$reponame" "cc.dat"
|
2017-01-24 22:19:12 +00:00
|
|
|
|
|
|
|
git config lfs.url "$CLIENTCERTGITSERVER/$reponame.git/info/lfs"
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock --json "cc.dat" | tee lock.json
|
|
|
|
id=$(assert_lock lock.json cc.dat)
|
2017-01-24 22:19:12 +00:00
|
|
|
assert_server_lock "$reponame" "$id"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
begin_test "creating a lock (with output)"
|
2016-12-28 00:11:11 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
reponame="lock_create_simple_output"
|
|
|
|
setup_remote_repo_with_file "$reponame" "a_output.dat"
|
2016-12-28 00:11:11 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock "a_output.dat" | tee lock.log
|
2017-02-23 19:54:57 +00:00
|
|
|
grep "Locked a_output.dat" lock.log
|
2017-02-23 19:47:14 +00:00
|
|
|
id=$(grep -oh "\((.*)\)" lock.log | tr -d \(\))
|
2017-01-06 16:15:16 +00:00
|
|
|
assert_server_lock "$reponame" "$id"
|
2016-12-28 00:11:11 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2020-05-11 02:41:36 +00:00
|
|
|
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
|
|
|
|
|
2016-06-03 16:36:26 +00:00
|
|
|
begin_test "locking a previously locked file"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2016-12-28 23:22:47 +00:00
|
|
|
reponame="lock_create_previously_created"
|
|
|
|
setup_remote_repo_with_file "$reponame" "b.dat"
|
2016-06-03 16:36:26 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock --json "b.dat" | tee lock.json
|
|
|
|
id=$(assert_lock lock.json b.dat)
|
2016-12-28 23:22:47 +00:00
|
|
|
assert_server_lock "$reponame" "$id"
|
2016-06-03 16:36:26 +00:00
|
|
|
|
2017-02-15 18:11:23 +00:00
|
|
|
grep "lock already created" <(git lfs lock "b.dat" 2>&1)
|
2016-06-03 16:36:26 +00:00
|
|
|
)
|
|
|
|
end_test
|
2016-06-04 17:25:02 +00:00
|
|
|
|
|
|
|
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
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main (root-commit)" commit.log
|
2016-06-04 17:25:02 +00:00
|
|
|
grep "2 files changed" commit.log
|
|
|
|
grep "create mode 100644 dir/a.dat" commit.log
|
|
|
|
grep "create mode 100644 .gitattributes" commit.log
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
|
|
|
grep "main -> main" push.log
|
2016-06-04 17:25:02 +00:00
|
|
|
|
2017-02-15 18:11:23 +00:00
|
|
|
git lfs lock ./dir/ 2>&1 | tee lock.log
|
2016-06-04 17:25:02 +00:00
|
|
|
grep "cannot lock directory" lock.log
|
|
|
|
)
|
|
|
|
end_test
|
2017-04-07 14:55:45 +00:00
|
|
|
|
|
|
|
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")"
|
|
|
|
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > foo/bar/baz/a.dat
|
2017-04-07 14:55:45 +00:00
|
|
|
git add foo/bar/baz/a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2017-04-07 14:55:45 +00:00
|
|
|
|
|
|
|
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
|
2017-08-11 18:32:59 +00:00
|
|
|
|
|
|
|
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
|
2018-05-04 21:48:34 +00:00
|
|
|
echo >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
|
2017-08-11 18:32:59 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-08-11 20:16:52 +00:00
|
|
|
id=$(assert_lock lock.json sub/a.dat)
|
2017-08-11 18:32:59 +00:00
|
|
|
assert_server_lock "$reponame" "$id"
|
|
|
|
)
|
|
|
|
end_test
|
2018-05-04 22:03:35 +00:00
|
|
|
|
|
|
|
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"
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2018-05-04 22:03:35 +00:00
|
|
|
|
|
|
|
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)"
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_lock "$reponame" "$id" main
|
2018-05-04 22:03:35 +00:00
|
|
|
popd > /dev/null
|
|
|
|
)
|
|
|
|
end_test
|
2018-08-20 13:42:28 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
locking: add flag to control modification of ignored files
In a727fea2 ("locking: remove write permission for ignored files",
2018-08-20), we learned to set and clear the read-only attribute on
ignored files that match the lockable pattern, since "git lfs lock"
operates on pathspecs, not actual files.
However, in doing so, we caused a regression for people who have ignored
files (such as build files) which match the lockable pattern, but should
not have their permissions modified. Since there is no easy way for us
to know if the user would like their files modified, add a config option
to control this behavior, and leave it at the historical (i.e.,
pre-a727fea2) default, off. Add documentation accordingly.
Choosing the historical behavior is compatible with the most existing
use cases and preserves the behavior people expect with Git, which is
that it does not touch ignored files.
2018-12-03 22:13:55 +00:00
|
|
|
echo "*.txt" > .gitignore
|
|
|
|
git add .gitignore
|
|
|
|
git commit -m ".gitignore: ignore 'a.txt'"
|
|
|
|
rm -f a.txt && git checkout a.txt
|
2019-09-17 19:20:04 +00:00
|
|
|
refute_file_writeable a.txt
|
locking: add flag to control modification of ignored files
In a727fea2 ("locking: remove write permission for ignored files",
2018-08-20), we learned to set and clear the read-only attribute on
ignored files that match the lockable pattern, since "git lfs lock"
operates on pathspecs, not actual files.
However, in doing so, we caused a regression for people who have ignored
files (such as build files) which match the lockable pattern, but should
not have their permissions modified. Since there is no easy way for us
to know if the user would like their files modified, add a config option
to control this behavior, and leave it at the historical (i.e.,
pre-a727fea2) default, off. Add documentation accordingly.
Choosing the historical behavior is compatible with the most existing
use cases and preserves the behavior people expect with Git, which is
that it does not touch ignored files.
2018-12-03 22:13:55 +00:00
|
|
|
)
|
|
|
|
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
|
|
|
|
|
2018-08-20 13:42:28 +00:00
|
|
|
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
|
2021-05-14 19:23:14 +00:00
|
|
|
|
|
|
|
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
|