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.
This commit is contained in:
Chris Darroch 2022-04-18 23:52:46 -07:00
parent b4e70fffa9
commit 739fbbcef2
2 changed files with 9 additions and 3 deletions

@ -34,7 +34,7 @@ begin_test "migrate import (--fixup, complex nested)"
git lfs migrate import --everything --fixup --yes
assert_pointer "refs/heads/main" "a.txt" "$a_oid" "1"
refute_pointer "refs/heads/main" "b.txt"
refute_pointer "refs/heads/main" "dir/b.txt"
assert_local_object "$a_oid" "1"
refute_local_object "$b_oid" "1"

@ -2,6 +2,9 @@
# assert_pointer confirms that the pointer in the repository for $path in the
# given $ref matches the given $oid and $size.
# Note that $path is prepended with a space to match the against the start
# of path field in the ls-tree output, so be careful if your test involves
# files with spaces in their paths.
#
# $ assert_pointer "main" "path/to/file" "some-oid" 123
assert_pointer() {
@ -14,7 +17,7 @@ assert_pointer() {
while read -r -d $'\0' x; do
echo $x
done |
grep -F "$path" | cut -f 3 -d " ")
grep -F " $path" | cut -f 3 -d " ")
actual=$(git cat-file -p $gitblob)
expected=$(pointer $oid $size)
@ -26,6 +29,9 @@ assert_pointer() {
# refute_pointer confirms that the file in the repository for $path in the
# given $ref is _not_ a pointer.
# Note that $path is prepended with a space to match the against the start
# of path field in the ls-tree output, so be careful if your test involves
# files with spaces in their paths.
#
# $ refute_pointer "main" "path/to/file"
refute_pointer() {
@ -36,7 +42,7 @@ refute_pointer() {
while read -r -d $'\0' x; do
echo $x
done |
grep "$path" | cut -f 3 -d " ")
grep -F " $path" | cut -f 3 -d " ")
file=$(git cat-file -p $gitblob)
version="version https://git-lfs.github.com/spec/v[0-9]"