[PATCH 18/20] t9300: make the get-mark and encoding tests self-contained
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Nov 10, 2026, 11:50 UTC
- Message-ID
- <20261110-kn-fast-import-tests-1-v1-18-dbd9ee502aae@gmail.com>
- In-Reply-To
- <20261110-kn-fast-import-tests-1-v1-0-dbd9ee502aae@gmail.com>
Similar to the previous commits, modify the tests in 'series W' and 'X: handling encoding' to make them independent of state from previous tests.
The 'W' tests read the 'W-input' file written at the top level of the script, which is not in the new repository. Turn it into a 'w_input()' function which prints the stream.
'X: replace ref that becomes useless is removed' changes its working directory and doesn't change back, so the tests after it, run in that repository. Move the 'cd' into the subshell, and cleanup when the test completes.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com> --- t/t9300-fast-import.sh | 81 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 24 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index c719b2115e..09cd2c5bf3 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -4503,7 +4503,8 @@ test_expect_success PIPE 'V: checkpoint updates tags after tag' ' ### series W (get-mark and empty orphan commits) ### -cat >>W-input <<-W_INPUT_END +w_input () { + cat <<-W_INPUT_END commit refs/heads/W-branch mark :1 author Full Name <user@company.tld> 1000000000 +0100 @@ -4512,28 +4513,53 @@ cat >>W-input <<-W_INPUT_END Intentionally empty commit LFsget-mark :1 W_INPUT_END +} test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' ' - sed -e s/LFs// W-input | tr L "\n" | git fast-import + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + w_input | sed -e s/LFs// | tr L "\n" | git fast-import + ) ' test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' ' - sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + w_input | sed -e s/LFs/L/ | tr L "\n" | git fast-import + ) ' test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' ' - # Technically, this should fail as it has too many linefeeds - # according to the grammar in fast-import.txt. But, for whatever - # reason, it works. Since using the correct number of newlines - # does not work with older (pre-2.22) versions of git, allow apps - # that used this second-newline workaround to keep working by - # checking it with this test... - sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + # Technically, this should fail as it has too many linefeeds + # according to the grammar in fast-import.txt. But, for whatever + # reason, it works. Since using the correct number of newlines + # does not work with older (pre-2.22) versions of git, allow apps + # that used this second-newline workaround to keep working by + # checking it with this test... + w_input | sed -e s/LFs/LL/ | tr L "\n" | git fast-import + ) ' test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' ' - # ...but do NOT allow more empty lines than that (see previous test). - sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + # ...but do NOT allow more empty lines than that (see previous test). + w_input | sed -e s/LFs/LLL/ | tr L "\n" | test_must_fail git fast-import + ) ' ### @@ -4541,25 +4567,32 @@ test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous thi ### test_expect_success ICONV 'X: handling encoding' ' - test_tick && - cat >input <<-INPUT_END && - commit refs/heads/encoding - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE - encoding iso-8859-7 - data <<COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - printf "Pi: \360\nCOMMIT\n" >>input && + test_tick && + cat >input <<-INPUT_END && + commit refs/heads/encoding + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + encoding iso-8859-7 + data <<COMMIT + INPUT_END - git fast-import <input && - git cat-file -p encoding | grep $(printf "\360") && - git log -1 --format=%B encoding | grep $(printf "\317\200") + printf "Pi: \360\nCOMMIT\n" >>input && + + git fast-import <input && + git cat-file -p encoding | grep $(printf "\360") && + git log -1 --format=%B encoding | grep $(printf "\317\200") + ) ' test_expect_success 'X: replace ref that becomes useless is removed' ' + test_when_finished "rm -rf testrepo" && git init -qb main testrepo && - cd testrepo && ( + cd testrepo && test_commit test && test_commit msg somename content &&
-- 2.56.GIT