[PATCH 02/20] t9300: make the series B tests self-contained
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Nov 10, 2026, 11:49 UTC
- Message-ID
- <20261110-kn-fast-import-tests-1-v1-2-dbd9ee502aae@gmail.com>
- In-Reply-To
- <20261110-kn-fast-import-tests-1-v1-0-dbd9ee502aae@gmail.com>
The 't/t9300-fast-import.sh' test file contains numerous tests and is currently just shy of 4000 lines. This is because the file contains tests over multiple series, each series testing particular functionality or sections of 'git-fast-import(1)'. In upcoming commits, we want to split out these tests into individual files for better discoverability.
First, we need to remove the dependency tests have on preceding tests. Modify the tests in 'series B' to each run in a new repository, which is removed when the test completes, so that they neither depend on nor leave behind any state.
The 'B: fail on invalid blob sha1' and 'B: accept branch name "TEMP_TAG"' tests import on top of 'main', which used to exist from earlier tests. Create it with 'test_commit', so that the first import can only fail because of the invalid blob ID.
The 'fsck' tests require the whole repository to be free of unreachable objects. They only passed because of the garbage collection in the cleanup of other tests. A new repository makes that unnecessary.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com> --- t/t9300-fast-import.sh | 472 ++++++++++++++++++++++++++++--------------------- 1 file changed, 275 insertions(+), 197 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index fb23492202..1b34f6491c 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -358,274 +358,352 @@ test_expect_success 'A: export marks with large values' ' ### test_expect_success 'B: fail on invalid blob sha1' ' - test_tick && - cat >input <<-INPUT_END && - commit refs/heads/branch - mark :1 - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE - data <<COMMIT - corrupt - COMMIT + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit base && - from refs/heads/main - M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1 + test_tick && + cat >input <<-INPUT_END && + commit refs/heads/branch + mark :1 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + corrupt + COMMIT - INPUT_END + from refs/heads/main + M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1 - test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" && - test_must_fail git fast-import <input + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: accept branch name "TEMP_TAG"' ' - cat >input <<-INPUT_END && - commit TEMP_TAG - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE - data <<COMMIT - tag base - COMMIT + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit new && - from refs/heads/main + cat >input <<-INPUT_END && + commit TEMP_TAG + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + tag base + COMMIT - INPUT_END + from refs/heads/main - test_when_finished "rm -f .git/TEMP_TAG && git gc --prune=now" && - git fast-import <input && - test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" && - test $(git rev-parse main) = $(git rev-parse TEMP_TAG^) + INPUT_END + + git fast-import <input && + test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" && + test $(git rev-parse main) = $(git rev-parse TEMP_TAG^) + ) ' test_expect_success 'B: accept empty committer' ' - cat >input <<-INPUT_END && - commit refs/heads/empty-committer-1 - committer <> $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + cat >input <<-INPUT_END && + commit refs/heads/empty-committer-1 + committer <> $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END - test_when_finished "git update-ref -d refs/heads/empty-committer-1 - git gc --prune=now" && - git fast-import <input && - out=$(git fsck) && - echo "$out" && - test -z "$out" + git fast-import <input && + out=$(git fsck) && + echo "$out" && + test -z "$out" + ) ' test_expect_success 'B: reject invalid timezone' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-timezone - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - test_when_finished "git update-ref -d refs/heads/invalid-timezone" && - test_must_fail git fast-import <input + cat >input <<-INPUT_END && + commit refs/heads/invalid-timezone + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: accept invalid timezone with raw-permissive' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-timezone - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - git init invalid-timezone && - git -C invalid-timezone fast-import --date-format=raw-permissive <input && - git -C invalid-timezone cat-file -p invalid-timezone >out && - test_grep "1234567890 [+]051800" out + cat >input <<-INPUT_END && + commit refs/heads/invalid-timezone + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 + data <<COMMIT + empty commit + COMMIT + INPUT_END + + git fast-import --date-format=raw-permissive <input && + git cat-file -p invalid-timezone >out && + test_grep "1234567890 [+]051800" out + ) ' test_expect_success 'B: accept and fixup committer with no name' ' - cat >input <<-INPUT_END && - commit refs/heads/empty-committer-2 - committer <a@b.com> $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + cat >input <<-INPUT_END && + commit refs/heads/empty-committer-2 + committer <a@b.com> $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END - test_when_finished "git update-ref -d refs/heads/empty-committer-2 - git gc --prune=now" && - git fast-import <input && - out=$(git fsck) && - echo "$out" && - test -z "$out" + git fast-import <input && + out=$(git fsck) && + echo "$out" && + test -z "$out" + ) ' test_expect_success 'B: fail on invalid committer (1)' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-committer - committer Name email> $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - test_when_finished "git update-ref -d refs/heads/invalid-committer" && - test_must_fail git fast-import <input + cat >input <<-INPUT_END && + commit refs/heads/invalid-committer + committer Name email> $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid committer (2)' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-committer - committer Name <e<mail> $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - test_when_finished "git update-ref -d refs/heads/invalid-committer" && - test_must_fail git fast-import <input + cat >input <<-INPUT_END && + commit refs/heads/invalid-committer + committer Name <e<mail> $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid committer (3)' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-committer - committer Name <email>> $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - test_when_finished "git update-ref -d refs/heads/invalid-committer" && - test_must_fail git fast-import <input + cat >input <<-INPUT_END && + commit refs/heads/invalid-committer + committer Name <email>> $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid committer (4)' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-committer - committer Name <email $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - test_when_finished "git update-ref -d refs/heads/invalid-committer" && - test_must_fail git fast-import <input + cat >input <<-INPUT_END && + commit refs/heads/invalid-committer + committer Name <email $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid committer (5)' ' - cat >input <<-INPUT_END && - commit refs/heads/invalid-committer - committer Name<email> $GIT_COMMITTER_DATE - data <<COMMIT - empty commit - COMMIT - INPUT_END + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - test_when_finished "git update-ref -d refs/heads/invalid-committer" && - test_must_fail git fast-import <input + cat >input <<-INPUT_END && + commit refs/heads/invalid-committer + committer Name<email> $GIT_COMMITTER_DATE + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid file path of ..' ' - cat >input <<-INPUT_END && - blob - mark :1 - data <<EOF - File contents - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - commit refs/heads/badpath - committer Name <email> $GIT_COMMITTER_DATE - data <<COMMIT - Commit Message - COMMIT - M 100644 :1 ../invalid-path - INPUT_END + cat >input <<-INPUT_END && + blob + mark :1 + data <<EOF + File contents + EOF - test_when_finished "git update-ref -d refs/heads/badpath" && - test_must_fail git fast-import <input + commit refs/heads/badpath + committer Name <email> $GIT_COMMITTER_DATE + data <<COMMIT + Commit Message + COMMIT + M 100644 :1 ../invalid-path + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid file path of .' ' - cat >input <<-INPUT_END && - blob - mark :1 - data <<EOF - File contents - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - commit refs/heads/badpath - committer Name <email> $GIT_COMMITTER_DATE - data <<COMMIT - Good path - COMMIT - M 100644 :1 ok-path + cat >input <<-INPUT_END && + blob + mark :1 + data <<EOF + File contents + EOF - commit refs/heads/badpath - committer Name <email> $GIT_COMMITTER_DATE - data <<COMMIT - Bad path - COMMIT - R ok-path ./invalid-path - INPUT_END + commit refs/heads/badpath + committer Name <email> $GIT_COMMITTER_DATE + data <<COMMIT + Good path + COMMIT + M 100644 :1 ok-path - test_when_finished "git update-ref -d refs/heads/badpath" && - test_must_fail git fast-import <input + commit refs/heads/badpath + committer Name <email> $GIT_COMMITTER_DATE + data <<COMMIT + Bad path + COMMIT + R ok-path ./invalid-path + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success WINDOWS 'B: fail on invalid file path of C:' ' - cat >input <<-INPUT_END && - blob - mark :1 - data <<EOF - File contents - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - commit refs/heads/badpath - committer Name <email> $GIT_COMMITTER_DATE - data <<COMMIT - Commit Message - COMMIT - M 100644 :1 C:/invalid-path - INPUT_END + cat >input <<-INPUT_END && + blob + mark :1 + data <<EOF + File contents + EOF - test_when_finished "git update-ref -d refs/heads/badpath" && - test_must_fail git fast-import <input + commit refs/heads/badpath + committer Name <email> $GIT_COMMITTER_DATE + data <<COMMIT + Commit Message + COMMIT + M 100644 :1 C:/invalid-path + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid file path of .git' ' - cat >input <<-INPUT_END && - blob - mark :1 - data <<EOF - File contents - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - commit refs/heads/badpath - committer Name <email> $GIT_COMMITTER_DATE - data <<COMMIT - Commit Message - COMMIT - M 100644 :1 .git/invalid-path - INPUT_END + cat >input <<-INPUT_END && + blob + mark :1 + data <<EOF + File contents + EOF - test_when_finished "git update-ref -d refs/heads/badpath" && - test_must_fail git fast-import <input + commit refs/heads/badpath + committer Name <email> $GIT_COMMITTER_DATE + data <<COMMIT + Commit Message + COMMIT + M 100644 :1 .git/invalid-path + INPUT_END + + test_must_fail git fast-import <input + ) ' test_expect_success 'B: fail on invalid file path of .gitmodules' ' - cat >input <<-INPUT_END && - blob - mark :1 - data <<EOF - File contents - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - commit refs/heads/badpath - committer Name <email> $GIT_COMMITTER_DATE - data <<COMMIT - Commit Message - COMMIT - M 120000 :1 .gitmodules - INPUT_END + cat >input <<-INPUT_END && + blob + mark :1 + data <<EOF + File contents + EOF - test_when_finished "git update-ref -d refs/heads/badpath" && - test_must_fail git fast-import <input + commit refs/heads/badpath + committer Name <email> $GIT_COMMITTER_DATE + data <<COMMIT + Commit Message + COMMIT + M 120000 :1 .gitmodules + INPUT_END + + test_must_fail git fast-import <input + ) ' ###
-- 2.56.GIT