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

[PATCH] repack: do not rebuild packs on --dry-run

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Oct 8, 2026, 06:25 UTC
Message-ID
<20261008062521.25505-1-r.siddharth.shrimali@gmail.com>

"git repack --drop-filtered --dry-run" is documented to list the objects that would be dropped "without rebuilding any pack or deleting anything", but it does both.

This is a bug in cmd_repack(): after printing the candidates, the --dry-run block falls through into the regular repack code. repack_promisor_objects() writes a new promisor pack, and with -d, existing_packs_remove_redundant() deletes the old packs. The command still exits successfully, so the user is not told that the repository was modified.

The existing guard only skips the implied "delete_redundant = 1", so it does not stop an explicit -d, nor the new pack from being written.

Fix it by returning right after the candidates are listed, and add a test that checks the pack directory is unchanged with and without -d.

Reported-by: Coy Geek <coygeek@gmail.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
Bug report:
https://lore.kernel.org/git/CACgTecOm+=vbf50tZNXhcYvRi1ZTsQwbjVoJAbQqs2CmXdJCxg@mail.gmail.com/
 builtin/repack.c                |  8 ++++++++
 t/t7706-repack-drop-filtered.sh | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+)
diff --git a/builtin/repack.c b/builtin/repack.c
index c4360382c1..c048053912 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -391,6 +391,14 @@ int cmd_repack(int argc,
 			oidset_iter_init(&drop_oids, &iter);
 			while ((oid = oidset_iter_next(&iter)))
 				printf("%s\n", oid_to_hex(oid));
+
+			/*
+			 * add an exit here, so that dry run does not
+			 * go on to rebuild any pack or delete anything, even
+			 * if the user explicitly asked for -d
+			 */
+			ret = 0;
+			goto cleanup;
 		}
 	}
 
diff --git a/t/t7706-repack-drop-filtered.sh b/t/t7706-repack-drop-filtered.sh
index cb36115834..a1c475e4ec 100755
--- a/t/t7706-repack-drop-filtered.sh
+++ b/t/t7706-repack-drop-filtered.sh
@@ -135,6 +135,25 @@ test_expect_success '--dry-run does not remove the filtered objects' '
 	git -C repo cat-file -e "$BIG"
 '
 
+test_expect_success '--dry-run leaves the pack directory untouched' '
+	BIG=$(cat big_oid) &&
+	packdir=repo/.git/objects/pack &&
+
+	for opt in "" -d
+	do
+		ls $packdir >before &&
+
+		git -C repo -c repack.writeBitmaps=false \
+			repack --drop-filtered --filter=blob:limit=1k \
+			--dry-run -a $opt >out &&
+
+		ls $packdir >after &&
+		test_cmp before after &&
+		test_grep "$BIG" out &&
+		git -C repo cat-file -e "$BIG" || return 1
+	done
+'
+
 test_expect_success '--drop-filtered removes the promisor blob locally' '
 	BIG=$(cat big_oid) &&
 	SMALL=$(cat small_oid) &&
-- 
2.56.0
Next: D. Ben Knoble
Message 1 of 7 in “repack: do not rebuild packs on --dry-run”
  1. repack: do not rebuild packs on --dry-runSiddharth Shrimali, Oct 8, 2026
  2. D. Ben KnobleOct 8, 2026
  3. Siddharth ShrimaliOct 10, 2026
  4. Junio C HamanoOct 8, 2026
  5. Siddharth ShrimaliOct 10, 2026
  6. repack: do not rebuild packs on --dry-runSiddharth Shrimali, Oct 10, 2026
  7. Ben KnobleOct 10, 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.