2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-06-16 14:07:26 +00:00
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-06-16 14:07:26 +00:00
|
|
|
|
|
|
|
begin_test "untrack"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# no need to setup a remote repo, since this test doesn't need to push or pull
|
|
|
|
|
|
|
|
reponame="untrack"
|
2015-06-16 21:07:27 +00:00
|
|
|
git init $reponame
|
|
|
|
cd $reponame
|
2015-06-16 14:07:26 +00:00
|
|
|
|
|
|
|
# track *.jpg once
|
2017-03-24 17:00:33 +00:00
|
|
|
git lfs track "*.jpg" | grep "Tracking \"\*.jpg\""
|
2015-06-16 14:07:26 +00:00
|
|
|
echo "* annex.backend=SHA512E" >> .gitattributes
|
|
|
|
|
|
|
|
git lfs untrack "*.jpg"
|
|
|
|
|
|
|
|
expected="* annex.backend=SHA512E"
|
|
|
|
[ "$expected" = "$(cat .gitattributes)" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "untrack outside git repo"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2015-06-16 21:07:27 +00:00
|
|
|
reponame="outside"
|
|
|
|
mkdir $reponame
|
|
|
|
cd $reponame
|
|
|
|
|
2015-06-16 14:07:26 +00:00
|
|
|
git lfs untrack "*.foo" || {
|
|
|
|
# this fails if it's run outside of a git repo using GIT_LFS_TEST_DIR
|
|
|
|
|
|
|
|
# git itself returns an exit status of 128
|
|
|
|
# $ git show
|
|
|
|
# fatal: Not a git repository (or any of the parent directories): .git
|
|
|
|
# $ echo "$?"
|
|
|
|
# 128
|
|
|
|
|
|
|
|
[ "$?" = "128" ]
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "$GIT_LFS_TEST_DIR" ]; then
|
|
|
|
echo "GIT_LFS_TEST_DIR should be set outside of any Git repository"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
2017-03-23 23:19:00 +00:00
|
|
|
|
|
|
|
begin_test "untrack removes escape sequences"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="untrack-remove-escape-sequence"
|
|
|
|
git init "$reponame"
|
|
|
|
cd "$reponame"
|
|
|
|
|
2017-03-24 17:00:33 +00:00
|
|
|
git lfs track " " | grep "Tracking \" \""
|
2017-03-23 23:19:00 +00:00
|
|
|
assert_attributes_count "[[:space:]]" "filter=lfs" 1
|
|
|
|
|
2017-03-24 17:00:33 +00:00
|
|
|
git lfs untrack " " | grep "Untracking \" \""
|
2017-03-23 23:19:00 +00:00
|
|
|
assert_attributes_count "[[:space:]]" "filter=lfs" 0
|
2017-03-23 23:19:26 +00:00
|
|
|
|
2017-03-24 17:00:33 +00:00
|
|
|
git lfs track "#" | grep "Tracking \"#\""
|
2017-03-23 23:19:26 +00:00
|
|
|
assert_attributes_count "\\#" "filter=lfs" 1
|
|
|
|
|
2017-03-24 17:00:33 +00:00
|
|
|
git lfs untrack "#" | grep "Untracking \"#\""
|
2017-03-23 23:19:26 +00:00
|
|
|
assert_attributes_count "\\#" "filter=lfs" 0
|
2017-03-23 23:19:00 +00:00
|
|
|
)
|
|
|
|
end_test
|
2018-04-05 17:51:26 +00:00
|
|
|
|
|
|
|
begin_test "untrack removes prefixed patterns (legacy)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="untrack-removes-prefix-patterns-legacy"
|
|
|
|
git init "$reponame"
|
|
|
|
cd "$reponame"
|
|
|
|
|
|
|
|
echo "./a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes
|
|
|
|
printf "a" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
git lfs untrack "./a.dat"
|
|
|
|
|
|
|
|
if [ ! -z "$(cat .gitattributes)" ]; then
|
2018-08-21 15:10:40 +00:00
|
|
|
echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
2018-04-05 17:51:26 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
git checkout -- .gitattributes
|
|
|
|
|
|
|
|
git lfs untrack "a.dat"
|
|
|
|
|
|
|
|
if [ ! -z "$(cat .gitattributes)" ]; then
|
2018-08-21 15:10:40 +00:00
|
|
|
echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
2018-04-05 17:51:26 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "untrack removes prefixed patterns (modern)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="untrack-removes-prefix-patterns-modern"
|
|
|
|
git init "$reponame"
|
|
|
|
cd "$reponame"
|
|
|
|
|
|
|
|
echo "a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes
|
|
|
|
printf "a" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
git lfs untrack "./a.dat"
|
|
|
|
|
|
|
|
if [ ! -z "$(cat .gitattributes)" ]; then
|
2018-08-21 15:10:40 +00:00
|
|
|
echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
2018-04-05 17:51:26 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
git checkout -- .gitattributes
|
|
|
|
|
|
|
|
git lfs untrack "a.dat"
|
|
|
|
|
|
|
|
if [ ! -z "$(cat .gitattributes)" ]; then
|
2018-08-21 15:10:40 +00:00
|
|
|
echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
2018-04-05 17:51:26 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
2018-08-21 08:50:57 +00:00
|
|
|
|
|
|
|
begin_test "untrack removes escaped pattern in .gitattributes"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="untrack-escaped"
|
|
|
|
git init "$reponame"
|
|
|
|
cd "$reponame"
|
|
|
|
|
|
|
|
filename="file with spaces.#"
|
|
|
|
|
|
|
|
# emulate multiple instances of the same file in gitattributes
|
|
|
|
echo 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes
|
|
|
|
echo 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes
|
|
|
|
echo 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes
|
|
|
|
|
|
|
|
git lfs untrack "$filename"
|
|
|
|
|
|
|
|
if [ ! -z "$(cat .gitattributes)" ]; then
|
2018-08-21 15:10:40 +00:00
|
|
|
echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes even if the file name was escaped"
|
2018-08-21 08:50:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
commands: make sure we're in the working tree
In the normal case, Git commands perform repository autodiscovery based
on the current working directory. However, in some cases, it's possible
to specify a Git working tree unrelated to the current working directory
by using GIT_WORK_TREE. In such a case, we want to make sure that we
change into the working tree such that our working directory is always
within the working tree, if one exists. This is what Git does, and it
means that when we write files into the repository, such as a
.gitattributes file, we write them into the proper place.
Note also that we adjust the code to require that the working directory
be non-empty when we require a working copy instead of that the
repository be non-bare. That's because we don't want people to be
working inside of the Git directory in such situations, where the
repository would be non-bare but would not have a working tree.
We add tests for this case for track and untrack, which require a
working tree, and for checkout, which requires only a repository. This
means that we can verify the behavior of the functions we've added
without needing to add tests for this case to each of the subcommands.
2020-10-02 19:03:55 +00:00
|
|
|
|
|
|
|
begin_test "untrack works with GIT_WORK_TREE"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="untrack-work-tree"
|
|
|
|
export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git"
|
|
|
|
mkdir "$GIT_WORK_TREE" "$GIT_DIR"
|
|
|
|
git init
|
|
|
|
git lfs track '*.bin'
|
|
|
|
|
|
|
|
grep -F '*.bin filter=lfs diff=lfs merge=lfs -text' "$reponame/.gitattributes"
|
|
|
|
|
|
|
|
git lfs untrack '*.bin'
|
|
|
|
|
|
|
|
[ ! -s "$reponame/.gitattributes" ]
|
|
|
|
)
|
|
|
|
end_test
|