git-lfs/t/t-migrate-fixup.sh
Chris Darroch 739fbbcef2 t: revise ls-tree path matching in pointer helpers
The assert_pointer() and refute_pointer() test helper functions
use grep to match specific lines of output from "git ls-tree".
However, while assert_pointer() matches with fixed patterns by using
grep's -F option, refute_pointer() does not.  This difference was
introduced in commit fc421da1c176a9d0844a38e6eb2cba154d864069 of
PR #3756, so we update refute_pointer() here to match.

In a subsequent PR we will also need to ensure that the file paths
we provide as arguments to these functions (specifically, to
assert_pointer()) do not match just any part of the paths output
by "git ls-tree", but only at the start of the path.  That is,
"a.bin" should match "a.bin" but not "foo/a.bin".

Because the output from "git ls-tree" is space-separated, we
prepend a space to our fixed patterns so we match against the
start of the file path.  This has the limitation that if a test
has a file named "foo a.bin", and calls one of these functions with
just the filename "a.bin", it will incorrectly match the filename
with a space.

However, at present only one of our tests that calls either of these
functions, specifically the "track: escaped glob pattern with spaces
in .gitattributes" test in t/t-track.sh, has a filename with a
space in it, and does not create any additional files which might
be confused by that filename.
2022-04-25 02:37:49 -07:00

157 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(dirname "$0")/fixtures/migrate.sh"
. "$(dirname "$0")/testlib.sh"
begin_test "migrate import (--fixup)"
(
set -e
setup_single_local_branch_tracked_corrupt
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
git lfs migrate import --everything --fixup --yes
assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
assert_local_object "$txt_oid" "120"
main="$(git rev-parse refs/heads/main)"
main_attrs="$(git cat-file -p "$main:.gitattributes")"
echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
)
end_test
begin_test "migrate import (--fixup, complex nested)"
(
set -e
setup_single_local_branch_complex_tracked
a_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
b_oid="$(calc_oid "$(git cat-file -p :dir/b.txt)")"
git lfs migrate import --everything --fixup --yes
assert_pointer "refs/heads/main" "a.txt" "$a_oid" "1"
refute_pointer "refs/heads/main" "dir/b.txt"
assert_local_object "$a_oid" "1"
refute_local_object "$b_oid" "1"
main="$(git rev-parse refs/heads/main)"
main_attrs="$(git cat-file -p "$main:.gitattributes")"
main_dir_attrs="$(git cat-file -p "$main:dir/.gitattributes")"
echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
echo "$main_dir_attrs" | grep -q "*.txt !filter !diff !merge"
)
end_test
begin_test "migrate import (--fixup, --include)"
(
set -e
setup_single_local_branch_tracked_corrupt
git lfs migrate import --everything --fixup --yes --include="*.txt" 2>&1 \
| tee migrate.log
if [ "${PIPESTATUS[0]}" -eq 0 ]; then
echo >&2 "Expected 'git lfs migrate ...' to fail, didn't ..."
exit 1
fi
grep -q "Cannot use --fixup with --include, --exclude" migrate.log
)
end_test
begin_test "migrate import (--fixup, --exclude)"
(
set -e
setup_single_local_branch_tracked_corrupt
git lfs migrate import --everything --fixup --yes --exclude="*.txt" 2>&1 \
| tee migrate.log
if [ "${PIPESTATUS[0]}" -eq 0 ]; then
echo >&2 "Expected 'git lfs migrate ...' to fail, didn't ..."
exit 1
fi
grep -q "Cannot use --fixup with --include, --exclude" migrate.log
)
end_test
begin_test "migrate import (--fixup, --no-rewrite)"
(
set -e
setup_single_local_branch_tracked_corrupt
git lfs migrate import --everything --fixup --yes --no-rewrite 2>&1 \
| tee migrate.log
if [ "${PIPESTATUS[0]}" -eq 0 ]; then
echo >&2 "Expected 'git lfs migrate ...' to fail, didn't ..."
exit 1
fi
grep -qe "--no-rewrite and --fixup cannot be combined" migrate.log
)
end_test
begin_test "migrate import (--fixup with remote tags)"
(
set -e
setup_single_local_branch_tracked_corrupt
git lfs uninstall
base64 < /dev/urandom | head -c 120 > b.txt
git add b.txt
git commit -m "b.txt"
git tag -m tag1 -a tag1
git reset --hard HEAD^
git lfs install
cwd=$(pwd)
cd "$TRASHDIR"
git clone "$cwd" "$reponame-2"
cd "$reponame-2"
# We're checking here that this succeeds even though it does nothing in this
# case.
git lfs migrate import --fixup --yes main
)
end_test
begin_test "migrate import (--fixup, .gitattributes symlink)"
(
set -e
setup_single_local_branch_tracked_corrupt link
git lfs migrate import --everything --fixup --yes 2>&1 | tee migrate.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo >&2 "fatal: expected git lfs migrate import to fail, didn't"
exit 1
fi
grep "migrate: expected '.gitattributes' to be a file, got a symbolic link" migrate.log
main="$(git rev-parse refs/heads/main)"
attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)"
diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF
120000 blob $attrs_main_sha .gitattributes
EOF
)
)
end_test