git-lfs/test/test-status.sh

173 lines
2.8 KiB
Bash
Raw Normal View History

2015-07-30 02:37:31 +00:00
#!/usr/bin/env bash
2015-05-26 21:38:24 +00:00
. "test/testlib.sh"
begin_test "status"
(
set -e
mkdir repo-1
cd repo-1
git init
git lfs track "*.dat"
echo "some data" > file1.dat
git add file1.dat
git commit -m "file1.dat"
echo "other data" > file1.dat
echo "file2 data" > file2.dat
git add file2.dat
echo "file3 data" > file3.dat
git add file3.dat
echo "file3 other data" > file3.dat
expected="On branch master
Git LFS objects to be committed:
2017-03-16 20:07:26 +00:00
file2.dat
file3.dat
2015-05-26 21:38:24 +00:00
Git LFS objects not staged for commit:
file1.dat
file3.dat"
2015-05-26 21:38:24 +00:00
[ "$expected" = "$(git lfs status)" ]
2015-05-26 21:38:24 +00:00
)
end_test
begin_test "status --porcelain"
(
set -e
mkdir repo-2
cd repo-2
git init
git lfs track "*.dat"
echo "some data" > file1.dat
git add file1.dat
git commit -m "file1.dat"
echo "other data" > file1.dat
echo "file2 data" > file2.dat
git add file2.dat
echo "file3 data" > file3.dat
git add file3.dat
echo "file3 other data" > file3.dat
2017-03-16 20:07:26 +00:00
expected=" M file1.dat
A file3.dat
A file2.dat"
2015-05-26 21:38:24 +00:00
[ "$expected" = "$(git lfs status --porcelain)" ]
2015-05-26 21:38:24 +00:00
)
end_test
begin_test "status: outside git repository"
(
2015-09-08 16:20:52 +00:00
set +e
git lfs status 2>&1 > status.log
res=$?
set -e
if [ "$res" = "0" ]; then
echo "Passes because $GIT_LFS_TEST_DIR is unset."
exit 0
fi
2015-09-08 16:20:52 +00:00
[ "$res" = "128" ]
grep "Not in a git repository" status.log
)
end_test
begin_test "status - before initial commit"
(
set -e
git init repo-initial
cd repo-initial
git lfs track "*.dat"
# should not fail when nothing to display (ignore output, will be blank)
git lfs status
echo "some data" > file1.dat
git add file1.dat
expected="
Git LFS objects to be committed:
2017-03-16 20:07:26 +00:00
file1.dat
Git LFS objects not staged for commit:"
[ "$expected" = "$(git lfs status)" ]
)
end_test
begin_test "status shows multiple files with identical contents"
(
set -e
reponame="uniq-status"
mkdir "$reponame"
cd "$reponame"
git init
git lfs track "*.dat"
contents="contents"
printf "$contents" > a.dat
printf "$contents" > b.dat
git add --all .
git lfs status | tee status.log
[ "1" -eq "$(grep -c "a.dat" status.log)" ]
[ "1" -eq "$(grep -c "b.dat" status.log)" ]
)
end_test
begin_test "status shows multiple copies of partially staged files"
(
set -e
reponame="status-partially-staged"
git init "$reponame"
cd "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
contents_1="part 1"
printf "$contents_1" > a.dat
# "$contents_1" changes are staged
git add a.dat
# "$contents_2" changes are unstaged
contents_2="part 2"
printf "$contents_2" >> a.dat
expected="On branch master
Git LFS objects to be committed:
a.dat
Git LFS objects not staged for commit:
a.dat"
actual="$(git lfs status)"
diff -u <(echo "$expected") <(echo "$actual")
)
end_test