git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] pack-objects: add tests for keep-true-parents

From
Yuvraj Singh Chauhan <ysinghcin@gmail.com>
Date
Sep 2, 2026, 11:30 UTC
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 <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
Previous: Yuvraj Singh Chauhan
Message 2 of 2 in “environment: move grafts_keep_true_parents into repo_config_values”
  1. 1/2 environment: move grafts_keep_true_parents into repo_config_valuesYuvraj Singh Chauhan, Sep 2, 2026
  2. 2/2 pack-objects: add tests for keep-true-parentsYuvraj Singh Chauhan, Sep 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.