From: Karthik Nayak Date: Thu, 12 Nov 2026 17:34:15 GMT Subject: [PATCH v2 15/20] t9300: make the cat-blob tests self-contained Message-ID: <20261112-kn-fast-import-tests-1-v2-15-b8c3a0ab27e8@gmail.com> In-Reply-To: <20261112-kn-fast-import-tests-1-v2-0-b8c3a0ab27e8@gmail.com> Similar to the previous commits, modify the cat-blog tests to make them independent of state from previous tests. Signed-off-by: Karthik Nayak --- t/t9300-fast-import.sh | 428 ++++++++++++++++++++++++++++--------------------- 1 file changed, 242 insertions(+), 186 deletions(-) diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 7b755d8de1..0dc71648ca 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -3048,87 +3048,117 @@ test_expect_success 'R: cat-blob-fd must be a nonnegative integer' ' ' test_expect_success !MINGW 'R: print old blob' ' - blob=$(echo "yes it can" | git hash-object -w --stdin) && - cat >expect <<-EOF && - ${blob} blob 11 - yes it can + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - echo "cat-blob $blob" | - git fast-import --cat-blob-fd=6 6>actual && - test_cmp expect actual + blob=$(echo "yes it can" | git hash-object -w --stdin) && + cat >expect <<-EOF && + ${blob} blob 11 + yes it can + + EOF + echo "cat-blob $blob" | + git fast-import --cat-blob-fd=6 6>actual && + test_cmp expect actual + ) ' test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' ' - echo hello >greeting && - blob=$(git hash-object -w greeting) && - cat >expect <<-EOF && - ${blob} blob 6 - hello + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF && - cat-blob $blob - EOF - test_cmp expect actual.3 && - test_must_be_empty actual.1 && - git fast-import 3>actual.3 >actual.1 <<-EOF && - option cat-blob-fd=3 - cat-blob $blob - EOF - test_must_be_empty actual.3 && - test_cmp expect actual.1 + echo hello >greeting && + blob=$(git hash-object -w greeting) && + cat >expect <<-EOF && + ${blob} blob 6 + hello + + EOF + git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF && + cat-blob $blob + EOF + test_cmp expect actual.3 && + test_must_be_empty actual.1 && + git fast-import 3>actual.3 >actual.1 <<-EOF && + option cat-blob-fd=3 + cat-blob $blob + EOF + test_must_be_empty actual.3 && + test_cmp expect actual.1 + ) ' test_expect_success !MINGW 'R: print mark for new blob' ' - echo "effluentish" | git hash-object --stdin >expect && - git fast-import --cat-blob-fd=6 6>actual <<-\EOF && - blob - mark :1 - data <expect && + git fast-import --cat-blob-fd=6 6>actual <<-\EOF && + blob + mark :1 + data <expect <<-EOF && - ${blob} blob 12 - yep yep yep + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - git fast-import --cat-blob-fd=6 6>actual <<-\EOF && - blob - mark :1 - data <expect <<-EOF && + ${blob} blob 12 + yep yep yep + + EOF + git fast-import --cat-blob-fd=6 6>actual <<-\EOF && + blob + mark :1 + data <expect <<-EOF && - ${blob} blob 25 - a new blob named by sha1 + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - git fast-import --cat-blob-fd=6 6>actual <<-EOF && - blob - data <expect <<-EOF && + ${blob} blob 25 + a new blob named by sha1 + + EOF + git fast-import --cat-blob-fd=6 6>actual <<-EOF && + blob + data <big && for i in 1 2 3 @@ -3138,153 +3168,179 @@ test_expect_success 'setup: big file' ' exit done ) -' +} test_expect_success 'R: print two blobs to stdout' ' - blob1=$(git hash-object big) && - blob1_len=$(wc -c expect && - { - cat <<-\END_PART1 && - blob - mark :1 - data <actual && - test_cmp expect actual + + EOF + } >expect && + { + cat <<-\END_PART1 && + blob + mark :1 + data <actual && + test_cmp expect actual + ) ' test_expect_success PIPE 'R: copy using cat-file' ' - expect_id=$(git hash-object big) && - expect_len=$(wc -c expect.response && - - rm -f blobs && - - mkfifo blobs && + test_when_finished "rm -rf repo" && + git init repo && ( - export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE && - cat <<-\EOF && - feature cat-blob - blob - mark :1 - data <response && - test_copy_bytes $size >blob <&3 && - read newline <&3 && + setup_big_file && + expect_id=$(git hash-object big) && + expect_len=$(wc -c expect.response && - cat <<-EOF && - commit refs/heads/copied - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE - data <blobs && - git show copied:file3 >actual && - test_cmp expect.response response && - test_cmp big actual + rm -f blobs && + + mkfifo blobs && + ( + export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE && + cat <<-\EOF && + feature cat-blob + blob + mark :1 + data <response && + test_copy_bytes $size >blob <&3 && + read newline <&3 && + + cat <<-EOF && + commit refs/heads/copied + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <blobs && + git show copied:file3 >actual && + test_cmp expect.response response && + test_cmp big actual + ) ' test_expect_success PIPE 'R: print blob mid-commit' ' - rm -f blobs && - echo "A blob from _before_ the commit." >expect && - mkfifo blobs && + test_when_finished "rm -rf repo" && + git init repo && ( - exec 3 $GIT_COMMITTER_DATE - data <actual <&3 && - read newline <&3 && + rm -f blobs && + echo "A blob from _before_ the commit." >expect && + mkfifo blobs && + ( + exec 3 $GIT_COMMITTER_DATE + data <blobs && - test_cmp expect actual + read blob_id type size <&3 && + test_copy_bytes $size >actual <&3 && + read newline <&3 && + + echo + ) | + git fast-import --cat-blob-fd=3 3>blobs && + test_cmp expect actual + ) ' test_expect_success PIPE 'R: print staged blob within commit' ' - rm -f blobs && - echo "A blob from _within_ the commit." >expect && - mkfifo blobs && + test_when_finished "rm -rf repo" && + git init repo && ( - exec 3 $GIT_COMMITTER_DATE - data <expect && + mkfifo blobs && + ( + exec 3 $GIT_COMMITTER_DATE + data <actual <&3 && - read newline <&3 && + to_get=$( + echo "A blob from _within_ the commit." | + git hash-object --stdin + ) && + echo "cat-blob $to_get" && - echo deleteall - ) | - git fast-import --cat-blob-fd=3 3>blobs && - test_cmp expect actual + read blob_id type size <&3 && + test_copy_bytes $size >actual <&3 && + read newline <&3 && + + echo deleteall + ) | + git fast-import --cat-blob-fd=3 3>blobs && + test_cmp expect actual + ) ' test_expect_success 'R: quiet option results in no stats being output' ' -- 2.56.GIT