[PATCH 2/2] pack-objects: add tests for keep-true-parents
From: Yuvraj Singh Chauhan <hidden>
Date: 2026-09-02 11:31:18
Subsystem:
the rest · Maintainer:
Linus Torvalds
Add tests for '--keep-true-parents' to 't5300-pack-object.sh' to ensure that: 1. Grafts hide parents by default during pack-objects. 2. The flag successfully reveals grafted-over parents. 3. It safely skips shallow commits (where 'nr_parent < 0') without causing failures or undefined behavior. Signed-off-by: Yuvraj Singh Chauhan <redacted> --- t/t5300-pack-object.sh | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index aac139e6a0..62b29c7e05 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh@@ -766,4 +766,59 @@ test_expect_success '--path-walk thin pack' ' git -C server index-pack --fix-thin --stdin <out.pack ' +test_expect_success 'setup graft and test repos' ' + git init graft-test && + ( + cd graft-test && + git commit --allow-empty -m "root" && + git commit --allow-empty -m "commit_A" && + A=$(git rev-parse HEAD) && + git commit --allow-empty -m "commit_B" && + B=$(git rev-parse HEAD) && + git commit --allow-empty -m "commit_C" && + C=$(git rev-parse HEAD) && + mkdir -p .git/info && + echo "$C $A" >.git/info/grafts && + echo "$C" >../C_sha && + echo "$B" >../B_sha && + echo "$A" >../A_sha + ) +' + +test_expect_success 'pack-objects without --keep-true-parents respects graft (hides real parent)' ' + C=$(cat C_sha) && + B=$(cat B_sha) && + echo "$C" | git -C graft-test pack-objects --revs --stdout >test-no-ktp.pack && + git init unpack-test && + git -C unpack-test index-pack --stdin <test-no-ktp.pack && + git -C unpack-test cat-file -p "$C" >/dev/null && + ! git -C unpack-test cat-file -p "$B" >/dev/null 2>&1 +' + +test_expect_success 'pack-objects --keep-true-parents ignores graft (exposes real parent)' ' + C=$(cat C_sha) && + B=$(cat B_sha) && + echo "$C" | git -C graft-test pack-objects --keep-true-parents --revs --stdout >test-ktp.pack && + git init unpack-test-ktp && + git -C unpack-test-ktp index-pack --stdin <test-ktp.pack && + git -C unpack-test-ktp cat-file -p "$C" >/dev/null && + git -C unpack-test-ktp cat-file -p "$B" >/dev/null +' + +test_expect_success 'pack-objects --keep-true-parents is safe with shallow commits' ' + git init shallow-src && + ( + cd shallow-src && + git commit --allow-empty -m "commit_A" && + git commit --allow-empty -m "commit_B" && + git commit --allow-empty -m "commit_C" + ) && + git clone --no-local --depth=1 shallow-src shallow-clone && + SHALLOW_TIP=$(git -C shallow-clone rev-parse HEAD) && + echo "$SHALLOW_TIP" | git -C shallow-clone pack-objects --keep-true-parents --revs --stdout >shallow-ktp.pack && + git init shallow-unpack && + git -C shallow-unpack index-pack --stdin <shallow-ktp.pack && + git -C shallow-unpack cat-file -p "$SHALLOW_TIP" >/dev/null +' + test_done
--
2.43.0