mirror of
https://github.com/git/git.git
synced 2026-03-04 14:37:35 +01:00
We've got a couple of tests related to diffs in t40xx that use the iconv(1) executable to convert the encoding of a commit message. All of these tests are prepared to handle a missing ICONV prereq, in which case they will simply use UTF-8 encoding. But even if the ICONV prerequisite has failed we try to use the iconv(1) executable, even though it's not safe to assume that the executable exists in that case. And besides that, it's also unnecessary to use iconv(1) in the first place, as we would only use it to convert from UTF-8 to UTF-8, which should be equivalent to a no-op. Fix the issue and skip the call to iconv(1) in case the prerequisite is not set. This makes tests work on systems that don't have iconv at all. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
138 lines
3.5 KiB
Bash
Executable File
138 lines
3.5 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2016 Jacob Keller, based on t4041 by Jens Lehmann
|
|
#
|
|
|
|
test_description='Test for submodule diff on non-checked out submodule
|
|
|
|
This test tries to verify that add_submodule_odb works when the submodule was
|
|
initialized previously but the checkout has since been removed.
|
|
'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
# Test non-UTF-8 encoding in case iconv is available.
|
|
if test_have_prereq ICONV
|
|
then
|
|
test_encoding="ISO8859-1"
|
|
# String "added" in German (translated with Google Translate), encoded in UTF-8,
|
|
# used in sample commit log messages in add_file() function below.
|
|
added=$(printf "hinzugef\303\274gt")
|
|
else
|
|
test_encoding="UTF-8"
|
|
added="added"
|
|
fi
|
|
|
|
add_file () {
|
|
(
|
|
cd "$1" &&
|
|
shift &&
|
|
for name
|
|
do
|
|
echo "$name" >"$name" &&
|
|
git add "$name" &&
|
|
test_tick &&
|
|
# "git commit -m" would break MinGW, as Windows refuse to pass
|
|
# $test_encoding encoded parameter to git.
|
|
message="Add $name ($added $name)" &&
|
|
if test_have_prereq ICONV
|
|
then
|
|
message=$(echo "$message" | iconv -f utf-8 -t $test_encoding)
|
|
fi &&
|
|
echo "$message" | git -c "i18n.commitEncoding=$test_encoding" commit -F -
|
|
done >/dev/null &&
|
|
git rev-parse --short --verify HEAD
|
|
)
|
|
}
|
|
|
|
commit_file () {
|
|
test_tick &&
|
|
git commit "$@" -m "Commit $*" >/dev/null
|
|
}
|
|
|
|
test_expect_success 'setup - submodules' '
|
|
test_create_repo sm2 &&
|
|
add_file . foo &&
|
|
add_file sm2 foo1 foo2 &&
|
|
smhead1=$(git -C sm2 rev-parse --short --verify HEAD)
|
|
'
|
|
|
|
test_expect_success 'setup - git submodule add' '
|
|
git -c protocol.file.allow=always submodule add ./sm2 sm1 &&
|
|
commit_file sm1 .gitmodules &&
|
|
git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm1 0000000...$smhead1 (new submodule)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'submodule directory removed' '
|
|
rm -rf sm1 &&
|
|
git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm1 0000000...$smhead1 (new submodule)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'setup - submodule multiple commits' '
|
|
git submodule update --checkout sm1 &&
|
|
smhead2=$(add_file sm1 foo3 foo4) &&
|
|
commit_file sm1 &&
|
|
git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm1 $smhead1..$smhead2:
|
|
> Add foo4 ($added foo4)
|
|
> Add foo3 ($added foo3)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'submodule removed multiple commits' '
|
|
rm -rf sm1 &&
|
|
git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm1 $smhead1..$smhead2:
|
|
> Add foo4 ($added foo4)
|
|
> Add foo3 ($added foo3)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'submodule not initialized in new clone' '
|
|
git clone . sm3 &&
|
|
git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm1 $smhead1...$smhead2 (commits not present)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'setup submodule moved' '
|
|
git submodule update --checkout sm1 &&
|
|
git mv sm1 sm4 &&
|
|
commit_file sm4 &&
|
|
git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm4 0000000...$smhead2 (new submodule)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'submodule moved then removed' '
|
|
smhead3=$(add_file sm4 foo6 foo7) &&
|
|
commit_file sm4 &&
|
|
rm -rf sm4 &&
|
|
git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
|
|
cat >expected <<-EOF &&
|
|
Submodule sm4 $smhead2..$smhead3:
|
|
> Add foo7 ($added foo7)
|
|
> Add foo6 ($added foo6)
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_done
|