🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1363

[PATCH] builtin/reflog: say "would prune" for named refs with --dry-run

#1363
From: Laveesh Bansal
Date: Sat, 24 Oct 2026 01:38
98 lines
12296 bytes
With --dry-run --verbose, "git reflog expire --all" reports the entries
it would remove as "would prune", but when refs are named on the command
line it reports them as "prune", which looks as if they were removed:

    $ git reflog expire --dry-run --verbose --expire=now HEAD
    prune commit (initial): first

Nothing is removed in either case, only the label is wrong. This was
reported at [1].

fcd2c3d9d8 (reflog + refs-backend: move "verbose" out of the backend,
2021-12-22) added dry_run to struct expire_reflog_policy_cb and set it
in the --all loop, but not in the loop for named refs. Set it there
too.

Add tests for named refs and --all. No test checked the keep/prune
wording before.

[1] https://lore.kernel.org/git/b46cbce8-d2bb-46d2-bdd3-545422813d6b@tngtech.com/

Reported-by: Sven Weiland <sven.weiland@tngtech.com>
Assisted-by: Claude Sonnet 5.5
Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
---

Notes:
    The dry_run bit just duplicates what is already in flags, so every
    caller has to copy it, and one got missed. Dropping it would mean
    changing the callback signature, so I left that alone.

 builtin/reflog.c  |  5 ++++-
 t/t1410-reflog.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 1211c58fa4..49e5453dd9 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -279,7 +279,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 
 	for (i = 0; i < argc; i++) {
 		char *ref;
-		struct expire_reflog_policy_cb cb = { .opts = opts };
+		struct expire_reflog_policy_cb cb = {
+			.opts = opts,
+			.dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
+		};
 
 		if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
 			status |= error(_("reflog could not be found: '%s'"), argv[i]);
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 93b5b49e1d..998a7e8667 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -240,6 +240,40 @@ test_expect_success 'reflog expire --dry-run should not touch reflog' '
 	check_fsck "missing blob $F"
 '
 
+# A dry run only ever says "keep" or "would prune".
+check_dry_run_output () {
+	test_grep "^would prune " "$1" &&
+	sed -e "/^keep /d" -e "/^would prune /d" \
+		-e "/^Marking reachable objects/d" "$1" >unexpected &&
+	test_must_be_empty unexpected
+}
+
+test_expect_success 'reflog expire --dry-run --verbose with a named ref' '
+	git reflog refs/heads/main >before &&
+	git reflog expire --dry-run --verbose \
+		--expire=$(($test_tick - 10000)) \
+		--expire-unreachable=$(($test_tick - 10000)) \
+		--stale-fix \
+		refs/heads/main >output &&
+	check_dry_run_output output &&
+
+	git reflog refs/heads/main >after &&
+	test_cmp before after
+'
+
+test_expect_success 'reflog expire --dry-run --verbose --all' '
+	git reflog refs/heads/main >before &&
+	git reflog expire --dry-run --verbose \
+		--expire=$(($test_tick - 10000)) \
+		--expire-unreachable=$(($test_tick - 10000)) \
+		--stale-fix \
+		--all >output &&
+	check_dry_run_output output &&
+
+	git reflog refs/heads/main >after &&
+	test_cmp before after
+'
+
 test_expect_success 'reflog expire' '
 
 	git reflog expire --verbose \
-- 
2.54.0
Technical Details
Message-ID: <20261024013850.66448-1-laveeshb@laveeshbansal.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73121-linux-kernel-git=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73121-linux-kernel-git=dewy.ru
From: laveeshb@laveeshbansal.com (Laveesh Bansal)
Newsgroups: linux.kernel.git
Subject: [PATCH] builtin/reflog: say "would prune" for named refs with --dry-run
Date: Fri, 23 Oct 2026 18:38:50 -0700
Organization: Usenet Network
Message-ID: <20261024013850.66448-1-laveeshb@laveeshbansal.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="659107"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CQc3472TqDoVI0NB8YcLUsK1TY0= sha256:yfcrXVIYDhWWvqeOa/7gJTYEkHCWRfDMiRi6L5i7aUQ=
	sha1:zMgq6KCQLcA2gXfJy0FNs0LqGyE= sha256:D/ETgVtRFPxMdOd/djtL2xr6QPpugmLCXmjlRhMJ7L8=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 523B41115DB; Sat, 24 Oct 2026 04:41:07 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=laveeshbansal.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id hLlydeyS2zOX;
	Sat, 24 Oct 2026 04:41:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-73121-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=laveeshbansal.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B8AC810E955; Sat, 24 Oct 2026 04:40:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3BC9539C9E; Sat, 24 Oct 2026 01:40:48 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792806047;
	b=EVKU5aNLBHUiiaP4+oiq5LvO7yz7aPPhcAX94enaj/4SI2/u4HbHSU9gFtuZYtRMM07i
	 ciDZskPc0M8fTruwaf17XUYrfnty3cso1hddCPV9fn77O5VTd2lSk9F8+PP3yZfJO4BMv
	 judNVXWqmLhuxzoRlGDQRF7Q9qGgXjqTHYbliY8lg8SI/eiEglJvucGyraLaOQnm4f9pw
	 dUGMURpLk29HU9lVUk5rf+KDHqJHiNhf+0y8WzZEOJ2T2zV51gl94OpSgy8kVAJXW9qa3
	 MRyRUJFCIliByK4P6EyNCzc7MJN7AIZECSudxZsjXL06lvjD1WmdZhcL+1g2L6QwZJg==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792806047;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding:X-ZohoMailClient;
	bh=4/6Lq/D0t5MjQ/eB0bvO9NfoH/R8E51fN7h+02SpZ+c=;
	b=pGpmcUENAej9ChkoyzVaf7hdcuLODQiKL5Sj2tIh0PQFY1DbkkjuTJLbCFyGg8vShC7t
	 5BXpYg0Ax+u20+2vCz0HeUTNvdRQSovxxd2fcaU5/gs/TjFOchph10sTku31JgCTNoVu/
	 U/H2SEB/rnLN9hzowL1MfHtlc0+mAY8KpvjsWbyAZjL9XpPK9MYId4k8fJcYDGFSBdOxq
	 vjY5k4zoXZ/llAyD6ZEYgr1XSEPxeHtyAF9Yy+vN2E6DdfJ+g2FvJZiYX4r68bHztphBi
	 OzGGnKh0XrS876I4+fOcyCY2grYPA7HUvsLBaxKifuOcN+GpYR5vwoIsMPl13rWh+zg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=laveeshbansal.com header.i=laveeshb@laveeshbansal.com header.a=rsa-sha256 header.s=zoho header.b="G5lb/ti+";
	dmarc=none header.from=laveeshbansal.com;
	spf=pass smtp.mailfrom=laveeshbansal.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id F09D9606A322;
	Sat, 24 Oct 2026 01:40:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=laveeshbansal.com header.i=laveeshb@laveeshbansal.com header.a=rsa-sha256 header.s=zoho header.b=G5lb/ti+
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.15
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792806046;
	b=rqeW56UI96JZm54ETNXqoT4AVzkMcFtZuL9tHprT0zE51LNIQLKKzxC+YUBx2cNKjfNB
	 lm+Oy0G37n0MQ0uWe5pdlIM/sEhnYhzuox+JmMDy6mLx/MtjCLeOThvJ481Koq9V2jO94
	 VS74Lx4PTCVsBjjBfWRuoFOUMXosISvPzMOUOWp1vNpL43eH8muCPA5gzH3Fk1omRMWMh
	 OicoFTn9CkMPZkPaua3SoWQ/HSXVrJsL2xXJyYSZb63WoCVD6ReQ5IkmZ+WP4NsIlsw5X
	 s62jdnZForr14husD88wjD6e0ZLdUusoJIWJYE6j06HEDP54SbYAhJv/WGrErf7RFtA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792806046;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding:
	 X-ZohoMailClient;
	bh=4/6Lq/D0t5MjQ/eB0bvO9NfoH/R8E51fN7h+02SpZ+c=;
	b=ZfQwcyIih7xV+VFDjeTn+U7ALbm9zSnD5JZDqg0rhlB1vJC6aLmiTH/OyRp1qRrjFFtf
	 NeSZ8drPxgpmRoFXPc84cs+66FXdpfR5flo9bykApEnMM6hvfYKeZf3ssxsQDyddletkC
	 k/ScuzL7J+NMxXZdBDwbzQR0lMu8+h18Re9fjrw1K6LDdVbJPHJXlOb1d2gxxZvoPPmRS
	 8xe3Ny+xKYSdZDnFUWkqAjc0+oonqas7XAeoIZI5Tz3gAr4004VIFrJLorRr687U9Fw6S
	 3fvczh3bWJH39YXUjnCogFLtengKZONh9SAJ368p3aW2bE4sb3/Y15+hRlPE1xmBa6A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=laveeshbansal.com;
	spf=pass smtp.mailfrom=laveeshbansal.com;
	dkim=pass header.d=laveeshbansal.com header.i=laveeshb@laveeshbansal.com header.a=rsa-sha256 header.s=zoho header.b="G5lb/ti+";
	arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.15
X-Received: from sender6-op-o15.zoho.com (sender6-op-o15.zoho.com [165.173.180.15])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B9C5606A31A
	for <git@vger.kernel.org>; Sat, 24 Oct 2026 01:40:45 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8B9C5606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=laveeshbansal.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=laveeshbansal.com
X-ARC-Seal: i=1; a=rsa-sha256; t=1792806028; cv=none; 
	d=zohomail.com; s=zohoarc; 
	b=OkZgyPTQJGcK38IBUvrXuc1HEsKqeddm6lVFKSoFMM2ln1D9fpXFSNarNcK3wCcdhrJ4GscBXednPYuyklflRxJTPao4DUC0yBz4jAus27Vz3XDuFVSWPSUELpalxFeCwgkbKuJrgFw65hXD5g4VgR56uOsAD/FxSj7h7EHRE1Q=
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; 
	t=1792806028; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; 
	bh=4/6Lq/D0t5MjQ/eB0bvO9NfoH/R8E51fN7h+02SpZ+c=; 
	b=FMy6ynaVlVOLw8P7DLX58IQ40xU5FcCZkG8y34j9l3Alsn1fI9oqRnA92C2U8BA0ZeQ+ZuJthFLpvOyvJ3iW52DpKvSYbgqa8g0SUZvt7cQcp7oX1/QrYGQ1l4CDSIt+sgjj3QqIt/n781RInaJRIs3uhX6lN5Wi2TGxH3R8flc=
X-ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass  header.i=laveeshbansal.com;
	spf=pass  smtp.mailfrom=laveeshb@laveeshbansal.com;
	dmarc=pass header.from=<laveeshb@laveeshbansal.com>
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1792806028;
	s=zoho; d=laveeshbansal.com; i=laveeshb@laveeshbansal.com;
	h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To;
	bh=4/6Lq/D0t5MjQ/eB0bvO9NfoH/R8E51fN7h+02SpZ+c=;
	b=G5lb/ti+Fa49W0HsF2U2kSHR55xCSuAtkrpQm3Q4/vH5cX4CVIDcnSg/gzrgU6sG
	9hY6HXGR0b48nVh5+fWOSe4X4ZbbBQMBljMdVequzwRWAaLY/3/KLWix/H7cCM2d7EX
	UBhV3gWOYqd4YdLGXAwakccNLZJdgXNILtLXeP3c=
X-Received: by smtp.zohomail.com with SMTPS id 1792806025050589.3255213039168;
	Fri, 23 Oct 2026 18:40:25 -0700 (PDT)
X-Cc: Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>,
	Karthik Nayak <karthik.188@gmail.com>,
	Sven Weiland <sven.weiland@tngtech.com>
X-Mailer: git-send-email 2.54.0
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-ZohoMailClient: External