Merge branch 'lb/reflog-expire-dry-run-fix' into next

The --dry-run option of git reflog expire has been corrected to
report "would prune" instead of "prune" when refs are named on the
command line, bringing it in line with the behavior of the --all
option.

* lb/reflog-expire-dry-run-fix:
  builtin/reflog: say "would prune" for named refs with --dry-run
This commit is contained in:
Junio C Hamano committed 2026-10-29 07:36:31 -07:00
commit 31d1e57fa9
2 files changed
+38 -1

No files matched your search

+4 -1
View File
@@ -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]);
+34
View File
@@ -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 \