git-lfs/test/test-unlock.sh

155 lines
3.8 KiB
Bash
Raw Normal View History

2016-06-03 21:00:57 +00:00
#!/usr/bin/env bash
. "test/testlib.sh"
begin_test "unlocking a lock by path"
(
set -e
reponame="unlock_by_path"
2016-06-03 21:05:55 +00:00
setup_remote_repo_with_file "unlock_by_path" "c.dat"
2016-06-03 21:00:57 +00:00
GITLFSLOCKSENABLED=1 git lfs lock "c.dat" | tee lock.log
2016-06-03 21:00:57 +00:00
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
2016-06-03 21:00:57 +00:00
GITLFSLOCKSENABLED=1 git lfs unlock "c.dat" 2>&1 | tee unlock.log
refute_server_lock "$reponame" "$id"
2016-06-03 21:00:57 +00:00
)
end_test
2016-12-28 00:16:00 +00:00
begin_test "unlocking a lock (--json)"
(
set -e
reponame="unlock_by_path_json"
setup_remote_repo_with_file "$reponame" "c_json.dat"
2016-12-28 00:16:00 +00:00
GITLFSLOCKSENABLED=1 git lfs lock "c_json.dat" | tee lock.log
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
2016-12-28 00:16:00 +00:00
GITLFSLOCKSENABLED=1 git lfs unlock --json "c_json.dat" 2>&1 | tee unlock.log
grep "\"unlocked\":true" unlock.log
refute_server_lock "$reponame" "$id"
2016-12-28 00:16:00 +00:00
)
end_test
2016-06-03 21:00:57 +00:00
begin_test "unlocking a lock by id"
(
set -e
reponame="unlock_by_id"
2016-06-03 21:05:55 +00:00
setup_remote_repo_with_file "unlock_by_id" "d.dat"
2016-06-03 21:00:57 +00:00
GITLFSLOCKSENABLED=1 git lfs lock "d.dat" | tee lock.log
2016-06-03 21:00:57 +00:00
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
2016-06-03 21:00:57 +00:00
GITLFSLOCKSENABLED=1 git lfs unlock --id="$id" 2>&1 | tee unlock.log
refute_server_lock "$reponame" "$id"
2016-06-03 21:00:57 +00:00
)
end_test
begin_test "unlocking a lock without sufficient info"
(
set -e
reponame="unlock_ambiguous"
setup_remote_repo_with_file "$reponame" "e.dat"
2016-06-03 21:00:57 +00:00
GITLFSLOCKSENABLED=1 git lfs lock "e.dat" | tee lock.log
2016-06-03 21:00:57 +00:00
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
2016-06-03 21:00:57 +00:00
GITLFSLOCKSENABLED=1 git lfs unlock 2>&1 | tee unlock.log
2016-06-03 21:00:57 +00:00
grep "Usage: git lfs unlock" unlock.log
assert_server_lock "$reponame" "$id"
2016-06-03 21:00:57 +00:00
)
end_test
begin_test "unlocking a lock while uncommitted"
(
set -e
reponame="unlock_modified"
2017-01-30 17:09:41 +00:00
setup_remote_repo_with_file "$reponame" "mod.dat"
2017-01-30 17:09:41 +00:00
GITLFSLOCKSENABLED=1 git lfs lock "mod.dat" | tee lock.log
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
2017-01-30 17:09:41 +00:00
echo "\nSomething" >> mod.dat
2017-01-30 17:09:41 +00:00
GITLFSLOCKSENABLED=1 git lfs unlock "mod.dat" 2>&1 | tee unlock.log
[ ${PIPESTATUS[0]} -ne "0" ]
grep "Cannot unlock file with uncommitted changes" unlock.log
assert_server_lock "$reponame" "$id"
# should allow after discard
2017-01-30 17:09:41 +00:00
git checkout mod.dat
GITLFSLOCKSENABLED=1 git lfs unlock "mod.dat" 2>&1 | tee unlock.log
refute_server_lock "$reponame" "$id"
)
end_test
begin_test "unlocking a lock while uncommitted with --force"
(
set -e
reponame="unlock_modified_force"
2017-01-30 17:09:41 +00:00
setup_remote_repo_with_file "$reponame" "modforce.dat"
2017-01-30 17:09:41 +00:00
GITLFSLOCKSENABLED=1 git lfs lock "modforce.dat" | tee lock.log
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
2017-01-30 17:09:41 +00:00
echo "\nSomething" >> modforce.dat
# should allow with --force
2017-01-30 17:09:41 +00:00
GITLFSLOCKSENABLED=1 git lfs unlock --force "modforce.dat" 2>&1 | tee unlock.log
grep "Warning: unlocking with uncommitted changes" unlock.log
refute_server_lock "$reponame" "$id"
)
end_test
2017-02-03 09:44:29 +00:00
begin_test "unlocking a lock while untracked"
(
set -e
reponame="unlock_untracked"
setup_remote_repo_with_file "$reponame" "notrelevant.dat"
git lfs track "*.dat"
# Create file but don't add it to git
# Shouldn't be able to unlock it
echo "something" > untracked.dat
GITLFSLOCKSENABLED=1 git lfs lock "untracked.dat" | tee lock.log
id=$(grep -oh "\((.*)\)" lock.log | tr -d "()")
assert_server_lock "$reponame" "$id"
GITLFSLOCKSENABLED=1 git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
[ ${PIPESTATUS[0]} -ne "0" ]
grep "Cannot unlock file with uncommitted changes" unlock.log
assert_server_lock "$reponame" "$id"
# should allow after add/commit
git add untracked.dat
git commit -m "Added untracked"
GITLFSLOCKSENABLED=1 git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
refute_server_lock "$reponame" "$id"
)
end_test