[PATCH 13/20] t9300: make the marks 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-13-dbd9ee502aae@gmail.com>
- In-Reply-To
- <20261110-kn-fast-import-tests-1-v1-0-dbd9ee502aae@gmail.com>
Similar to the previous commits, modify the marks tests to make them independent of state from previous tests.
Several tests import the marks file written by an earlier test. Add a 'create_marks_file()' function which writes one, with marks for commits and tags too, so each test can invoke it in its own repository.
'R: feature import-marks-if-exists' writes a marks file pointing to a blob it never stores, relying on an earlier test having written it. Write the blob in the test itself. Also run 'A: export marks with large values' in its own repository.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com> --- t/t9300-fast-import.sh | 512 +++++++++++++++++++++++++++++++------------------ 1 file changed, 322 insertions(+), 190 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index f55604bb87..82348c65cc 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -298,59 +298,65 @@ test_expect_success 'A: verify diff' ' ' test_expect_success 'A: export marks with large values' ' - test_tick && - mt=$(git hash-object --stdin < /dev/null) && - >input.blob && - >marks.exp && - >tree.exp && + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - cat >input.commit <<-EOF && - commit refs/heads/verify--dump-marks - committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE - data <<COMMIT - test the sparse array dumping routines with exponentially growing marks - COMMIT - EOF + test_tick && + mt=$(git hash-object --stdin < /dev/null) && + >input.blob && + >marks.exp && + >tree.exp && - i=0 l=4 m=6 n=7 && - while test "$i" -lt 27 - do - cat >>input.blob <<-EOF && - blob - mark :$l - data 0 - blob - mark :$m - data 0 - blob - mark :$n - data 0 + cat >input.commit <<-EOF && + commit refs/heads/verify--dump-marks + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + test the sparse array dumping routines with exponentially growing marks + COMMIT EOF - echo "M 100644 :$l l$i" >>input.commit && - echo "M 100644 :$m m$i" >>input.commit && - echo "M 100644 :$n n$i" >>input.commit && - echo ":$l $mt" >>marks.exp && - echo ":$m $mt" >>marks.exp && - echo ":$n $mt" >>marks.exp && + i=0 l=4 m=6 n=7 && + while test "$i" -lt 27 + do + cat >>input.blob <<-EOF && + blob + mark :$l + data 0 + blob + mark :$m + data 0 + blob + mark :$n + data 0 + EOF + echo "M 100644 :$l l$i" >>input.commit && + echo "M 100644 :$m m$i" >>input.commit && + echo "M 100644 :$n n$i" >>input.commit && - printf "100644 blob $mt\tl$i\n" >>tree.exp && - printf "100644 blob $mt\tm$i\n" >>tree.exp && - printf "100644 blob $mt\tn$i\n" >>tree.exp && + echo ":$l $mt" >>marks.exp && + echo ":$m $mt" >>marks.exp && + echo ":$n $mt" >>marks.exp && - l=$(($l + $l)) && - m=$(($m + $m)) && - n=$(($l + $n)) && + printf "100644 blob $mt\tl$i\n" >>tree.exp && + printf "100644 blob $mt\tm$i\n" >>tree.exp && + printf "100644 blob $mt\tn$i\n" >>tree.exp && - i=$((1 + $i)) || return 1 - done && + l=$(($l + $l)) && + m=$(($m + $m)) && + n=$(($l + $n)) && - sort tree.exp > tree.exp_s && + i=$((1 + $i)) || return 1 + done && - cat input.blob input.commit | git fast-import --export-marks=marks.large && - git ls-tree refs/heads/verify--dump-marks >tree.out && - test_cmp tree.exp_s tree.out && - test_cmp marks.exp marks.large + sort tree.exp > tree.exp_s && + + cat input.blob input.commit | git fast-import --export-marks=marks.large && + git ls-tree refs/heads/verify--dump-marks >tree.out && + test_cmp tree.exp_s tree.out && + test_cmp marks.exp marks.large + ) ' ### @@ -2652,196 +2658,316 @@ test_expect_success 'R: export-marks feature forbidden by default' ' ' test_expect_success 'R: export-marks feature results in a marks file being created' ' - cat >input <<-EOF && - feature export-marks=git.marks - blob - mark :1 - data 3 - hi + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF + cat >input <<-EOF && + feature export-marks=git.marks + blob + mark :1 + data 3 + hi - git fast-import --allow-unsafe-features <input && - test_grep :1 git.marks + EOF + + git fast-import --allow-unsafe-features <input && + test_grep :1 git.marks + ) ' test_expect_success 'R: export-marks options can be overridden by commandline options' ' - cat >input <<-\EOF && - feature export-marks=feature-sub/git.marks - blob - mark :1 - data 3 - hi + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - git fast-import --allow-unsafe-features \ - --export-marks=cmdline-sub/other.marks <input && - test_grep :1 cmdline-sub/other.marks && - test_path_is_missing feature-sub + cat >input <<-\EOF && + feature export-marks=feature-sub/git.marks + blob + mark :1 + data 3 + hi + + EOF + git fast-import --allow-unsafe-features \ + --export-marks=cmdline-sub/other.marks <input && + test_grep :1 cmdline-sub/other.marks && + test_path_is_missing feature-sub + ) ' test_expect_success 'R: catch typo in marks file name' ' - test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null && - echo "feature import-marks=nonexistent.marks" | - test_must_fail git fast-import --allow-unsafe-features + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null && + echo "feature import-marks=nonexistent.marks" | + test_must_fail git fast-import --allow-unsafe-features + ) ' test_expect_success 'R: import and output marks can be the same file' ' - rm -f io.marks && - blob=$(echo hi | git hash-object --stdin) && - cat >expect <<-EOF && - :1 $blob - :2 $blob - EOF - git fast-import --export-marks=io.marks <<-\EOF && - blob - mark :1 - data 3 - hi + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && - blob - mark :2 - data 3 - hi + rm -f io.marks && + blob=$(echo hi | git hash-object --stdin) && + cat >expect <<-EOF && + :1 $blob + :2 $blob + EOF + git fast-import --export-marks=io.marks <<-\EOF && + blob + mark :1 + data 3 + hi - EOF - test_cmp expect io.marks + EOF + git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && + blob + mark :2 + data 3 + hi + + EOF + test_cmp expect io.marks + ) ' test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' ' - rm -f io.marks && - test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF - blob - mark :1 - data 3 - hi + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF + rm -f io.marks && + test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF + blob + mark :1 + data 3 + hi + + EOF + ) ' test_expect_success 'R: --import-marks-if-exists' ' - rm -f io.marks && - blob=$(echo hi | git hash-object --stdin) && - echo ":1 $blob" >expect && - git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF && - blob - mark :1 - data 3 - hi + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - test_cmp expect io.marks + rm -f io.marks && + blob=$(echo hi | git hash-object --stdin) && + echo ":1 $blob" >expect && + git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF && + blob + mark :1 + data 3 + hi + + EOF + test_cmp expect io.marks + ) ' test_expect_success 'R: feature import-marks-if-exists' ' - rm -f io.marks && + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - git fast-import --export-marks=io.marks \ - --allow-unsafe-features <<-\EOF && - feature import-marks-if-exists=not_io.marks - EOF - test_must_be_empty io.marks && + rm -f io.marks && - blob=$(echo hi | git hash-object --stdin) && + git fast-import --export-marks=io.marks \ + --allow-unsafe-features <<-\EOF && + feature import-marks-if-exists=not_io.marks + EOF + test_must_be_empty io.marks && - echo ":1 $blob" >io.marks && - echo ":1 $blob" >expect && - echo ":2 $blob" >>expect && + blob=$(echo hi | git hash-object -w --stdin) && - git fast-import --export-marks=io.marks \ - --allow-unsafe-features <<-\EOF && - feature import-marks-if-exists=io.marks - blob - mark :2 - data 3 - hi + echo ":1 $blob" >io.marks && + echo ":1 $blob" >expect && + echo ":2 $blob" >>expect && - EOF - test_cmp expect io.marks && + git fast-import --export-marks=io.marks \ + --allow-unsafe-features <<-\EOF && + feature import-marks-if-exists=io.marks + blob + mark :2 + data 3 + hi - echo ":3 $blob" >>expect && + EOF + test_cmp expect io.marks && - git fast-import --import-marks=io.marks \ - --export-marks=io.marks \ - --allow-unsafe-features <<-\EOF && - feature import-marks-if-exists=not_io.marks - blob - mark :3 - data 3 - hi + echo ":3 $blob" >>expect && - EOF - test_cmp expect io.marks && + git fast-import --import-marks=io.marks \ + --export-marks=io.marks \ + --allow-unsafe-features <<-\EOF && + feature import-marks-if-exists=not_io.marks + blob + mark :3 + data 3 + hi - git fast-import --import-marks-if-exists=not_io.marks \ - --export-marks=io.marks \ - --allow-unsafe-features <<-\EOF && - feature import-marks-if-exists=io.marks - EOF - test_must_be_empty io.marks + EOF + test_cmp expect io.marks && + + git fast-import --import-marks-if-exists=not_io.marks \ + --export-marks=io.marks \ + --allow-unsafe-features <<-\EOF && + feature import-marks-if-exists=io.marks + EOF + test_must_be_empty io.marks + ) ' -test_expect_success 'R: import to output marks works without any content' ' - cat >input <<-EOF && - feature import-marks=marks.out - feature export-marks=marks.new - EOF +create_marks_file () { + git fast-import --export-marks="$1" <<-EOF + blob + mark :1 + data 4 + one - git fast-import --allow-unsafe-features <input && - test_cmp marks.out marks.new + blob + mark :2 + data 4 + two + + blob + mark :3 + data 6 + three + + blob + mark :4 + data 5 + four + + commit refs/heads/marks + mark :5 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + commit with a mark + COMMIT + M 100644 :1 one + + tag marks-tag + mark :6 + from :5 + tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<TAG + tag with a mark + TAG + + EOF +} + +test_expect_success 'R: import to output marks works without any content' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + create_marks_file marks.out && + + cat >input <<-EOF && + feature import-marks=marks.out + feature export-marks=marks.new + EOF + + git fast-import --allow-unsafe-features <input && + test_cmp marks.out marks.new + ) ' test_expect_success 'R: import marks prefers commandline marks file over the stream' ' - cat >input <<-EOF && - feature import-marks=nonexistent.marks - feature export-marks=marks.new - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + create_marks_file marks.out && - git fast-import --import-marks=marks.out --allow-unsafe-features <input && - test_cmp marks.out marks.new + cat >input <<-EOF && + feature import-marks=nonexistent.marks + feature export-marks=marks.new + EOF + + git fast-import --import-marks=marks.out --allow-unsafe-features <input && + test_cmp marks.out marks.new + ) ' - test_expect_success 'R: multiple --import-marks= should be honoured' ' - cat >input <<-EOF && - feature import-marks=nonexistent.marks - feature export-marks=combined.marks - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + create_marks_file marks.out && - head -n2 marks.out > one.marks && - tail -n +3 marks.out > two.marks && - git fast-import --import-marks=one.marks --import-marks=two.marks \ - --allow-unsafe-features <input && - test_cmp marks.out combined.marks + cat >input <<-EOF && + feature import-marks=nonexistent.marks + feature export-marks=combined.marks + EOF + + head -n2 marks.out >one.marks && + tail -n +3 marks.out >two.marks && + git fast-import --import-marks=one.marks --import-marks=two.marks \ + --allow-unsafe-features <input && + test_cmp marks.out combined.marks + ) ' test_expect_success 'R: feature relative-marks should be honoured' ' - cat >input <<-EOF && - feature relative-marks - feature import-marks=relative.in - feature export-marks=relative.out - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + create_marks_file marks.out && - mkdir -p .git/info/fast-import/ && - cp marks.new .git/info/fast-import/relative.in && - git fast-import --allow-unsafe-features <input && - test_cmp marks.new .git/info/fast-import/relative.out + cat >input <<-EOF && + feature relative-marks + feature import-marks=relative.in + feature export-marks=relative.out + EOF + + mkdir -p .git/info/fast-import/ && + cp marks.out .git/info/fast-import/relative.in && + git fast-import --allow-unsafe-features <input && + test_cmp marks.out .git/info/fast-import/relative.out + ) ' test_expect_success 'R: feature no-relative-marks should be honoured' ' - cat >input <<-EOF && - feature relative-marks - feature import-marks=relative.in - feature no-relative-marks - feature export-marks=non-relative.out - EOF + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + create_marks_file marks.out && - git fast-import --allow-unsafe-features <input && - test_cmp marks.new non-relative.out + cat >input <<-EOF && + feature relative-marks + feature import-marks=relative.in + feature no-relative-marks + feature export-marks=non-relative.out + EOF + + mkdir -p .git/info/fast-import/ && + cp marks.out .git/info/fast-import/relative.in && + git fast-import --allow-unsafe-features <input && + test_cmp marks.out non-relative.out + ) ' + test_expect_success 'R: feature ls supported' ' echo "feature ls" | git fast-import @@ -3187,18 +3313,24 @@ test_expect_success 'R: ignore non-git options' ' ' test_expect_success 'R: corrupt lines do not mess marks file' ' - rm -f io.marks && - blob=$(echo hi | git hash-object --stdin) && - cat >expect <<-EOF && - :3 $ZERO_OID - :1 $blob - :2 $blob - EOF - cp expect io.marks && - test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && - EOF - test_cmp expect io.marks + rm -f io.marks && + blob=$(echo hi | git hash-object --stdin) && + cat >expect <<-EOF && + :3 $ZERO_OID + :1 $blob + :2 $blob + EOF + cp expect io.marks && + test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && + + EOF + test_cmp expect io.marks + ) ' ##
-- 2.56.GIT