From: Yuvraj Singh Chauhan <ysinghcin@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 2/2] pack-objects: add tests for keep-true-parents
Date: Wed, 2 Sep 2026 17:00:46 +0530 [thread overview]
Message-ID: <20260902113109.686014-2-ysinghcin@gmail.com> (raw)
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 <ysinghcin@gmail.com>
---
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
prev parent reply other threads:[~2026-09-02 11:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 11:30 [PATCH 1/2] environment: move grafts_keep_true_parents into repo_config_values Yuvraj Singh Chauhan
2026-09-02 11:30 ` Yuvraj Singh Chauhan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260902113109.686014-2-ysinghcin@gmail.com \
--to=ysinghcin@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.