2006-07-16 10:38:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Eric Wong
|
|
|
|
#
|
|
|
|
|
2007-07-03 05:52:14 +00:00
|
|
|
test_description='git apply should not get confused with type changes.
|
2006-07-16 10:38:40 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
leak tests: mark passing SANITIZE=leak tests as leak-free
Mark those remaining tests that pass when run under SANITIZE=leak with
TEST_PASSES_SANITIZE_LEAK=true, these were either omitted in
f346fcb62a0 (Merge branch 'ab/mark-leak-free-tests-even-more',
2021-12-15) and 5a4f8381b68 (Merge branch 'ab/mark-leak-free-tests',
2021-10-25), or have had their memory leaks fixed since then.
With this change there's now a a one-to-one mapping between those
tests that we have opted-in via "TEST_PASSES_SANITIZE_LEAK=true", and
those that pass with the new "check" mode:
GIT_TEST_PASSING_SANITIZE_LEAK=check \
GIT_TEST_SANITIZE_LEAK_LOG=true \
make test SANITIZE=leak
Note that the "GIT_TEST_SANITIZE_LEAK_LOG=true" is needed due to the
edge cases noted in a preceding commit, i.e. in some cases we'd pass
the test itself, but still have outstanding leaks due to ignored exit
codes.
The "GIT_TEST_SANITIZE_LEAK_LOG=true" corrects for that, we're only
marking those tests as passing that really don't have any leaks,
whether that was reflected in their exit code or not.
Note that the change here to "t9100-git-svn-basic.sh" is marking that
test as passing under SANITIZE=leak, we're removing a
"TEST_FAILS_SANITIZE_LEAK=true" line, not
"TEST_PASSES_SANITIZE_LEAK=true". See 7a98d9ab00d (revisions API: have
release_revisions() release "cmdline", 2022-04-13) for the
introduction of that t/lib-git-svn.sh-specific variable.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-07-27 23:13:41 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2006-07-16 10:38:40 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'setup repository and commits' '
|
2006-07-16 10:38:40 +00:00
|
|
|
echo "hello world" > foo &&
|
|
|
|
echo "hi planet" > bar &&
|
|
|
|
git update-index --add foo bar &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git branch initial &&
|
|
|
|
rm -f foo &&
|
2013-06-07 20:53:32 +00:00
|
|
|
test_ln_s_add bar foo &&
|
2006-07-16 10:38:40 +00:00
|
|
|
git commit -m "foo symlinked to bar" &&
|
|
|
|
git branch foo-symlinked-to-bar &&
|
2013-06-07 20:53:32 +00:00
|
|
|
git rm -f foo &&
|
2006-07-16 10:38:40 +00:00
|
|
|
echo "how far is the sun?" > foo &&
|
2013-06-07 20:53:32 +00:00
|
|
|
git update-index --add foo &&
|
2006-07-16 10:38:40 +00:00
|
|
|
git commit -m "foo back to file" &&
|
|
|
|
git branch foo-back-to-file &&
|
2009-01-26 08:08:24 +00:00
|
|
|
printf "\0" > foo &&
|
|
|
|
git update-index foo &&
|
|
|
|
git commit -m "foo becomes binary" &&
|
|
|
|
git branch foo-becomes-binary &&
|
2006-07-16 10:38:40 +00:00
|
|
|
rm -f foo &&
|
|
|
|
git update-index --remove foo &&
|
|
|
|
mkdir foo &&
|
|
|
|
echo "if only I knew" > foo/baz &&
|
|
|
|
git update-index --add foo/baz &&
|
|
|
|
git commit -m "foo becomes a directory" &&
|
|
|
|
git branch "foo-becomes-a-directory" &&
|
|
|
|
echo "hello world" > foo/baz &&
|
|
|
|
git update-index foo/baz &&
|
|
|
|
git commit -m "foo/baz is the original foo" &&
|
|
|
|
git branch foo-baz-renamed-from-foo
|
|
|
|
'
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'file renamed from foo to foo/baz' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f initial &&
|
|
|
|
git diff-tree -M -p HEAD foo-baz-renamed-from-foo > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'file renamed from foo/baz to foo' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f foo-baz-renamed-from-foo &&
|
|
|
|
git diff-tree -M -p HEAD initial > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'directory becomes file' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f foo-becomes-a-directory &&
|
|
|
|
git diff-tree -p HEAD initial > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'file becomes directory' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f initial &&
|
|
|
|
git diff-tree -p HEAD foo-becomes-a-directory > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'file becomes symlink' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f initial &&
|
|
|
|
git diff-tree -p HEAD foo-symlinked-to-bar > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'symlink becomes file' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f foo-symlinked-to-bar &&
|
|
|
|
git diff-tree -p HEAD foo-back-to-file > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
apply: when -R, also reverse list of sections
A patch changing a symlink into a file is written with 2 sections (in
the code, represented as "struct patch"): firstly, the deletion of the
symlink, and secondly, the creation of the file. When applying that
patch with -R, the sections are reversed, so we get:
(1) creation of a symlink, then
(2) deletion of a file.
This causes an issue when the "deletion of a file" section is checked,
because Git observes that the so-called file is not a file but a
symlink, resulting in a "wrong type" error message.
What we want is:
(1) deletion of a file, then
(2) creation of a symlink.
In the code, this is reflected in the behavior of previous_patch() when
invoked from check_preimage() when the deletion is checked. Creation
then deletion means that when the deletion is checked, previous_patch()
returns the creation section, triggering a mode conflict resulting in
the "wrong type" error message. But deletion then creation means that
when the deletion is checked, previous_patch() returns NULL, so the
deletion mode is checked against lstat, which is what we want.
There are also other ways a patch can contain 2 sections referencing the
same file, for example, in 7a07841c0b ("git-apply: handle a patch that
touches the same path more than once better", 2008-06-27). "git apply
-R" fails in the same way, and this commit makes this case succeed.
Therefore, when building the list of sections, build them in reverse
order (by adding to the front of the list instead of the back) when -R
is passed.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-20 22:04:52 +00:00
|
|
|
test_expect_success 'symlink becomes file, in reverse' '
|
|
|
|
git checkout -f foo-symlinked-to-bar &&
|
|
|
|
git diff-tree -p HEAD foo-back-to-file > patch &&
|
|
|
|
git checkout foo-back-to-file &&
|
|
|
|
git apply -R --index < patch
|
|
|
|
'
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'binary file becomes symlink' '
|
2009-01-26 08:08:24 +00:00
|
|
|
git checkout -f foo-becomes-binary &&
|
|
|
|
git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'symlink becomes binary file' '
|
2009-01-26 08:08:24 +00:00
|
|
|
git checkout -f foo-symlinked-to-bar &&
|
|
|
|
git diff-tree -p --binary HEAD foo-becomes-binary > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
2006-07-16 10:38:40 +00:00
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'symlink becomes directory' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f foo-symlinked-to-bar &&
|
|
|
|
git diff-tree -p HEAD foo-becomes-a-directory > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
2013-06-07 20:53:32 +00:00
|
|
|
test_expect_success 'directory becomes symlink' '
|
2006-07-16 10:38:40 +00:00
|
|
|
git checkout -f foo-becomes-a-directory &&
|
|
|
|
git diff-tree -p HEAD foo-symlinked-to-bar > patch &&
|
|
|
|
git apply --index < patch
|
|
|
|
'
|
|
|
|
test_debug 'cat patch'
|
|
|
|
|
|
|
|
|
|
|
|
test_done
|