git/t/t4007-rename-3.sh
Ævar Arnfjörð Bjarmason 15b808da74 "lib-diff" tests: make "README" and "COPYING" test data smaller
Follow-up the change in 459b8d22e5 (tests: do not borrow from COPYING
and README from the real source, 2015-02-15) by not shipping a full
copy of older versions of the top-level "COPYING" and "README" files.

The tests that use them just need the small blurb at the top of
"COPYING" as test data, or mock data that's dissimilar. Let's provide
that with a "COPYING_test_data" function instead.

We're not replacing this with some other generic test
data (e.g. "lorum ipsum") because these tests require test file header
to be the old "COPYING" file. See e.g. "t4003-diff-rename-1.sh" which
changes the file, and then does full "test_cmp" comparisons on the
resulting "git diff" output.

This change only changes tests that used the "lib-diff.sh" library,
but splits up what they need into a new "lib-diff-data.sh". A
subsequent commit will change related tests that were missed in
459b8d22e5.

For the test in "t4008-diff-break-rewrite.sh" the "README" file can go
away in favor of echoing the line "some dissimilar content" to a file
in the one test that needed it.

The point of that test is to start with files "A" and "B", and then
have A be more similar to the state of "B" than to its old version (by
copying over the content from the "COPYING" file). Just comparing the
pre-image of "some dissimilar content" and later a munged version of
the "COPYING" output serves that purpose.

While we're at it get rid of a stray "echo $tree" debugging line added
in 15d061b435 ([PATCH] Fix the way diffcore-rename records unremoved
source., 2005-05-27), and stop calling "hash-object" to get the hash
of an object we've just added to the index. We can instead extract
that information from the index itself with "rev-parse".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-10-15 09:36:46 -07:00

91 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
#
# Copyright (c) 2005 Junio C Hamano
#
test_description='Rename interaction with pathspec.
'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
test_expect_success 'prepare reference tree' '
mkdir path0 path1 &&
COPYING_test_data >path0/COPYING &&
git update-index --add path0/COPYING &&
tree=$(git write-tree) &&
blob=$(git rev-parse :path0/COPYING)
'
test_expect_success 'prepare work tree' '
cp path0/COPYING path1/COPYING &&
git update-index --add --remove path0/COPYING path1/COPYING
'
# In the tree, there is only path0/COPYING. In the cache, path0 and
# path1 both have COPYING and the latter is a copy of path0/COPYING.
# Comparing the full tree with cache should tell us so.
cat >expected <<EOF
:100644 100644 $blob $blob C100 path0/COPYING path1/COPYING
EOF
test_expect_success 'copy detection' '
git diff-index -C --find-copies-harder $tree >current &&
compare_diff_raw current expected
'
test_expect_success 'copy detection, cached' '
git diff-index -C --find-copies-harder --cached $tree >current &&
compare_diff_raw current expected
'
# In the tree, there is only path0/COPYING. In the cache, path0 and
# path1 both have COPYING and the latter is a copy of path0/COPYING.
# However when we say we care only about path1, we should just see
# path1/COPYING suddenly appearing from nowhere, not detected as
# a copy from path0/COPYING.
cat >expected <<EOF
:000000 100644 $ZERO_OID $blob A path1/COPYING
EOF
test_expect_success 'copy, limited to a subtree' '
git diff-index -C --find-copies-harder $tree path1 >current &&
compare_diff_raw current expected
'
test_expect_success 'tweak work tree' '
rm -f path0/COPYING &&
git update-index --remove path0/COPYING
'
# In the tree, there is only path0/COPYING. In the cache, path0 does
# not have COPYING anymore and path1 has COPYING which is a copy of
# path0/COPYING. Showing the full tree with cache should tell us about
# the rename.
cat >expected <<EOF
:100644 100644 $blob $blob R100 path0/COPYING path1/COPYING
EOF
test_expect_success 'rename detection' '
git diff-index -C --find-copies-harder $tree >current &&
compare_diff_raw current expected
'
# In the tree, there is only path0/COPYING. In the cache, path0 does
# not have COPYING anymore and path1 has COPYING which is a copy of
# path0/COPYING. When we say we care only about path1, we should just
# see path1/COPYING appearing from nowhere.
cat >expected <<EOF
:000000 100644 $ZERO_OID $blob A path1/COPYING
EOF
test_expect_success 'rename, limited to a subtree' '
git diff-index -C --find-copies-harder $tree path1 >current &&
compare_diff_raw current expected
'
test_done