t9350: redirect input to only fast-import

A number of tests in "t9350-fast-export.sh" are using sub-shells to
redirect content to a number of commands instead of only
`git fast-import`.

This is confusing and possibly error-prone, so let's change those tests
so that no sub-shell is used and the content goes only to
`git fast-import`.

Reported-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder
2025-07-25 18:05:36 +02:00
committed by Junio C Hamano
parent b5b3ddbe5c
commit 5345ca1745

View File

@@ -48,12 +48,11 @@ test_expect_success 'fast-export | fast-import' '
mkdir new && mkdir new &&
git --git-dir=new/.git init && git --git-dir=new/.git init &&
git fast-export --all >actual && git fast-export --all >actual &&
(cd new && git -C new fast-import <actual &&
git fast-import && test $MAIN = $(git -C new rev-parse --verify refs/heads/main) &&
test $MAIN = $(git rev-parse --verify refs/heads/main) && test $REIN = $(git -C new rev-parse --verify refs/tags/rein) &&
test $REIN = $(git rev-parse --verify refs/tags/rein) && test $WER = $(git -C new rev-parse --verify refs/heads/wer) &&
test $WER = $(git rev-parse --verify refs/heads/wer) && test $MUSS = $(git -C new rev-parse --verify refs/tags/muss)
test $MUSS = $(git rev-parse --verify refs/tags/muss)) <actual
' '
@@ -87,13 +86,11 @@ test_expect_success 'fast-export --mark-tags ^muss^{commit} muss' '
test_expect_success 'fast-export main~2..main' ' test_expect_success 'fast-export main~2..main' '
git fast-export main~2..main >actual && git fast-export main~2..main >actual &&
sed "s/main/partial/" actual | sed "s/main/partial/" actual | git -C new fast-import &&
(cd new && test $MAIN != $(git -C new rev-parse --verify refs/heads/partial) &&
git fast-import && git -C new diff --exit-code main partial &&
test $MAIN != $(git rev-parse --verify refs/heads/partial) && git -C new diff --exit-code main^ partial^ &&
git diff --exit-code main partial && test_must_fail git -C new rev-parse partial~2
git diff --exit-code main^ partial^ &&
test_must_fail git rev-parse partial~2)
' '
@@ -102,10 +99,8 @@ test_expect_success 'fast-export --reference-excluded-parents main~2..main' '
git fast-export --reference-excluded-parents main~2..main >actual && git fast-export --reference-excluded-parents main~2..main >actual &&
grep commit.refs/heads/main actual >commit-count && grep commit.refs/heads/main actual >commit-count &&
test_line_count = 2 commit-count && test_line_count = 2 commit-count &&
sed "s/main/rewrite/" actual | sed "s/main/rewrite/" actual | git -C new fast-import &&
(cd new && test $MAIN = $(git -C new rev-parse --verify refs/heads/rewrite)
git fast-import &&
test $MAIN = $(git rev-parse --verify refs/heads/rewrite))
' '
test_expect_success 'fast-export --show-original-ids' ' test_expect_success 'fast-export --show-original-ids' '
@@ -133,20 +128,19 @@ test_expect_success ICONV 'reencoding iso-8859-7' '
echo rosten >file && echo rosten >file &&
git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file && git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
git fast-export --reencode=yes wer^..wer >iso-8859-7.fi && git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
sed "s/wer/i18n/" iso-8859-7.fi | sed "s/wer/i18n/" iso-8859-7.fi | git -C new fast-import &&
(cd new &&
git fast-import && # The commit object, if not re-encoded, would be 200 bytes plus hash.
# The commit object, if not re-encoded, would be 200 bytes plus hash. # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
# Removing the "encoding iso-8859-7\n" header drops 20 bytes. # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
# Re-encoding the Pi character from \xF0 (\360) in iso-8859-7 # to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for
# to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for # the expected size.
# the expected size. test $(($(test_oid hexsz) + 181)) -eq "$(git -C new cat-file -s i18n)" &&
test $(($(test_oid hexsz) + 181)) -eq "$(git cat-file -s i18n)" && # ...and for the expected translation of bytes.
# ...and for the expected translation of bytes. git -C new cat-file commit i18n >actual &&
git cat-file commit i18n >actual && grep $(printf "\317\200") actual &&
grep $(printf "\317\200") actual && # Also make sure the commit does not have the "encoding" header
# Also make sure the commit does not have the "encoding" header ! grep ^encoding actual
! grep ^encoding actual)
' '
test_expect_success 'aborting on iso-8859-7' ' test_expect_success 'aborting on iso-8859-7' '
@@ -165,20 +159,19 @@ test_expect_success 'preserving iso-8859-7' '
echo rosten >file && echo rosten >file &&
git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file && git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
git fast-export --reencode=no wer^..wer >iso-8859-7.fi && git fast-export --reencode=no wer^..wer >iso-8859-7.fi &&
sed "s/wer/i18n-no-recoding/" iso-8859-7.fi | sed "s/wer/i18n-no-recoding/" iso-8859-7.fi | git -C new fast-import &&
(cd new &&
git fast-import && # The commit object, if not re-encoded, is 200 bytes plus hash.
# The commit object, if not re-encoded, is 200 bytes plus hash. # Removing the "encoding iso-8859-7\n" header would drops 20
# Removing the "encoding iso-8859-7\n" header would drops 20 # bytes. Re-encoding the Pi character from \xF0 (\360) in
# bytes. Re-encoding the Pi character from \xF0 (\360) in # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte.
# iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte. # Check for the expected size...
# Check for the expected size... test $(($(test_oid hexsz) + 200)) -eq "$(git -C new cat-file -s i18n-no-recoding)" &&
test $(($(test_oid hexsz) + 200)) -eq "$(git cat-file -s i18n-no-recoding)" && # ...as well as the expected byte.
# ...as well as the expected byte. git -C new cat-file commit i18n-no-recoding >actual &&
git cat-file commit i18n-no-recoding >actual && grep $(printf "\360") actual &&
grep $(printf "\360") actual && # Also make sure the commit has the "encoding" header
# Also make sure the commit has the "encoding" header grep ^encoding actual
grep ^encoding actual)
' '
test_expect_success 'encoding preserved if reencoding fails' ' test_expect_success 'encoding preserved if reencoding fails' '
@@ -188,18 +181,17 @@ test_expect_success 'encoding preserved if reencoding fails' '
echo rosten >file && echo rosten >file &&
git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file && git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file &&
git fast-export --reencode=yes wer^..wer >iso-8859-7.fi && git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
sed "s/wer/i18n-invalid/" iso-8859-7.fi | sed "s/wer/i18n-invalid/" iso-8859-7.fi | git -C new fast-import &&
(cd new && git -C new cat-file commit i18n-invalid >actual &&
git fast-import &&
git cat-file commit i18n-invalid >actual && # Make sure the commit still has the encoding header
# Make sure the commit still has the encoding header grep ^encoding actual &&
grep ^encoding actual && # Verify that the commit has the expected size; i.e.
# Verify that the commit has the expected size; i.e. # that no bytes were re-encoded to a different encoding.
# that no bytes were re-encoded to a different encoding. test $(($(test_oid hexsz) + 212)) -eq "$(git -C new cat-file -s i18n-invalid)" &&
test $(($(test_oid hexsz) + 212)) -eq "$(git cat-file -s i18n-invalid)" && # ...and check for the original special bytes
# ...and check for the original special bytes grep $(printf "\360") actual &&
grep $(printf "\360") actual && grep $(printf "\377") actual
grep $(printf "\377") actual)
' '
test_expect_success 'import/export-marks' ' test_expect_success 'import/export-marks' '
@@ -316,12 +308,9 @@ test_expect_success GPG 'signed-commits=verbatim' '
git fast-export --signed-commits=verbatim --reencode=no commit-signing >output && git fast-export --signed-commits=verbatim --reencode=no commit-signing >output &&
test_grep -E "^gpgsig $GIT_DEFAULT_HASH openpgp" output && test_grep -E "^gpgsig $GIT_DEFAULT_HASH openpgp" output &&
grep "encoding ISO-8859-1" output && grep "encoding ISO-8859-1" output &&
( git -C new fast-import <output &&
cd new && STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-signing) &&
git fast-import && test $COMMIT_SIGNING = $STRIPPED
STRIPPED=$(git rev-parse --verify refs/heads/commit-signing) &&
test $COMMIT_SIGNING = $STRIPPED
) <output
' '
@@ -331,12 +320,9 @@ test_expect_success GPG 'signed-commits=warn-verbatim' '
test_grep -E "^gpgsig $GIT_DEFAULT_HASH openpgp" output && test_grep -E "^gpgsig $GIT_DEFAULT_HASH openpgp" output &&
grep "encoding ISO-8859-1" output && grep "encoding ISO-8859-1" output &&
test -s err && test -s err &&
( git -C new fast-import <output &&
cd new && STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-signing) &&
git fast-import && test $COMMIT_SIGNING = $STRIPPED
STRIPPED=$(git rev-parse --verify refs/heads/commit-signing) &&
test $COMMIT_SIGNING = $STRIPPED
) <output
' '
@@ -345,12 +331,9 @@ test_expect_success GPG 'signed-commits=strip' '
git fast-export --signed-commits=strip --reencode=no commit-signing >output && git fast-export --signed-commits=strip --reencode=no commit-signing >output &&
! grep ^gpgsig output && ! grep ^gpgsig output &&
grep "^encoding ISO-8859-1" output && grep "^encoding ISO-8859-1" output &&
sed "s/commit-signing/commit-strip-signing/" output | ( sed "s/commit-signing/commit-strip-signing/" output | git -C new fast-import &&
cd new && STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-strip-signing) &&
git fast-import && test $COMMIT_SIGNING != $STRIPPED
STRIPPED=$(git rev-parse --verify refs/heads/commit-strip-signing) &&
test $COMMIT_SIGNING != $STRIPPED
)
' '
@@ -360,12 +343,9 @@ test_expect_success GPG 'signed-commits=warn-strip' '
! grep ^gpgsig output && ! grep ^gpgsig output &&
grep "^encoding ISO-8859-1" output && grep "^encoding ISO-8859-1" output &&
test -s err && test -s err &&
sed "s/commit-signing/commit-strip-signing/" output | ( sed "s/commit-signing/commit-strip-signing/" output | git -C new fast-import &&
cd new && STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-strip-signing) &&
git fast-import && test $COMMIT_SIGNING != $STRIPPED
STRIPPED=$(git rev-parse --verify refs/heads/commit-strip-signing) &&
test $COMMIT_SIGNING != $STRIPPED
)
' '
@@ -386,14 +366,11 @@ test_expect_success GPGSM 'round-trip X.509 signed commit' '
git fast-export --signed-commits=verbatim x509-signing >output && git fast-export --signed-commits=verbatim x509-signing >output &&
test_grep -E "^gpgsig $GIT_DEFAULT_HASH x509" output && test_grep -E "^gpgsig $GIT_DEFAULT_HASH x509" output &&
( git -C new fast-import <output &&
cd new && git -C new cat-file commit refs/heads/x509-signing >actual &&
git fast-import && grep "^gpgsig" actual &&
git cat-file commit refs/heads/x509-signing >actual && IMPORTED=$(git -C new rev-parse refs/heads/x509-signing) &&
grep "^gpgsig" actual && test $X509_COMMIT = $IMPORTED
IMPORTED=$(git rev-parse refs/heads/x509-signing) &&
test $X509_COMMIT = $IMPORTED
) <output
' '
@@ -414,14 +391,11 @@ test_expect_success GPGSSH 'round-trip SSH signed commit' '
git fast-export --signed-commits=verbatim ssh-signing >output && git fast-export --signed-commits=verbatim ssh-signing >output &&
test_grep -E "^gpgsig $GIT_DEFAULT_HASH ssh" output && test_grep -E "^gpgsig $GIT_DEFAULT_HASH ssh" output &&
( git -C new fast-import <output &&
cd new && git -C new cat-file commit refs/heads/ssh-signing >actual &&
git fast-import && grep "^gpgsig" actual &&
git cat-file commit refs/heads/ssh-signing >actual && IMPORTED=$(git -C new rev-parse refs/heads/ssh-signing) &&
grep "^gpgsig" actual && test $SSH_COMMIT = $IMPORTED
IMPORTED=$(git rev-parse refs/heads/ssh-signing) &&
test $SSH_COMMIT = $IMPORTED
) <output
' '
@@ -461,14 +435,13 @@ test_expect_success 'submodule fast-export | fast-import' '
mkdir new && mkdir new &&
git --git-dir=new/.git init && git --git-dir=new/.git init &&
git fast-export --signed-tags=strip --all >actual && git fast-export --signed-tags=strip --all >actual &&
(cd new && git -C new fast-import <actual &&
git fast-import && test "$SUBENT1" = "$(git -C new ls-tree refs/heads/main^ sub)" &&
test "$SUBENT1" = "$(git ls-tree refs/heads/main^ sub)" && test "$SUBENT2" = "$(git -C new ls-tree refs/heads/main sub)" &&
test "$SUBENT2" = "$(git ls-tree refs/heads/main sub)" && git -C new checkout main &&
git checkout main && git -C new submodule init &&
git submodule init && git -C new submodule update &&
git submodule update && cmp new/sub/file sub/file
cmp sub/file ../sub/file) <actual
' '
@@ -510,10 +483,8 @@ test_expect_success 'fast-export -C -C | fast-import' '
git --git-dir=new/.git init && git --git-dir=new/.git init &&
git fast-export -C -C --signed-tags=strip --all > output && git fast-export -C -C --signed-tags=strip --all > output &&
grep "^C file2 file4\$" output && grep "^C file2 file4\$" output &&
cat output | git -C new fast-import <output &&
(cd new && test $ENTRY = $(git -C new rev-parse --verify refs/heads/copy)
git fast-import &&
test $ENTRY = $(git rev-parse --verify refs/heads/copy))
' '
@@ -986,21 +957,17 @@ test_expect_success GPG 'export and import of doubly signed commit' '
git -C explicit-sha256 fast-export --signed-commits=verbatim dual-signed >output && git -C explicit-sha256 fast-export --signed-commits=verbatim dual-signed >output &&
test_grep -E "^gpgsig sha1 openpgp" output && test_grep -E "^gpgsig sha1 openpgp" output &&
test_grep -E "^gpgsig sha256 openpgp" output && test_grep -E "^gpgsig sha256 openpgp" output &&
git -C new fast-import <output &&
( git -C new cat-file commit refs/heads/dual-signed >actual &&
cd new && test_grep -E "^gpgsig " actual &&
git fast-import && test_grep -E "^gpgsig-sha256 " actual &&
git cat-file commit refs/heads/dual-signed >actual && IMPORTED=$(git -C new rev-parse refs/heads/dual-signed) &&
test_grep -E "^gpgsig " actual && if test "$GIT_DEFAULT_HASH" = "sha1"
test_grep -E "^gpgsig-sha256 " actual && then
IMPORTED=$(git rev-parse refs/heads/dual-signed) && test $SHA1_B = $IMPORTED
if test "$GIT_DEFAULT_HASH" = "sha1" else
then test $SHA256_B = $IMPORTED
test $SHA1_B = $IMPORTED fi
else
test $SHA256_B = $IMPORTED
fi
) <output
' '
test_done test_done