From: Yuvraj Singh Chauhan Date: Wed, 02 Sep 2026 11:30:46 GMT Subject: [PATCH 2/2] pack-objects: add tests for keep-true-parents Message-ID: <20260902113109.686014-2-ysinghcin@gmail.com> In-Reply-To: <20260902113109.686014-1-ysinghcin@gmail.com> 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 --- 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 .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 /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 /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 /dev/null +' + test_done -- 2.43.0