Skip to content

Commit dbffe54

Browse files
committed
Merge branch 'rs/reflog-expire-single-worktree-fix'
"git reflog expire --single-worktree" has been broken for the past 20 months or so, which has been corrected. * rs/reflog-expire-single-worktree-fix: reflog: fix expire --single-worktree
2 parents c032943 + 26d4c51 commit dbffe54

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

builtin/reflog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
243243
{
244244
struct cmd_reflog_expire_cb cmd = { 0 };
245245
timestamp_t now = time(NULL);
246-
int i, status, do_all, all_worktrees = 1;
246+
int i, status, do_all, single_worktree = 0;
247247
unsigned int flags = 0;
248248
int verbose = 0;
249249
reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent;
@@ -268,7 +268,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
268268
OPT_BOOL(0, "stale-fix", &cmd.stalefix,
269269
N_("prune any reflog entries that point to broken commits")),
270270
OPT_BOOL(0, "all", &do_all, N_("process the reflogs of all references")),
271-
OPT_BOOL(1, "single-worktree", &all_worktrees,
271+
OPT_BOOL(0, "single-worktree", &single_worktree,
272272
N_("limits processing to reflogs from the current worktree only")),
273273
OPT_END()
274274
};
@@ -318,7 +318,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
318318

319319
worktrees = get_worktrees();
320320
for (p = worktrees; *p; p++) {
321-
if (!all_worktrees && !(*p)->is_current)
321+
if (single_worktree && !(*p)->is_current)
322322
continue;
323323
collected.worktree = *p;
324324
refs_for_each_reflog(get_worktree_ref_store(*p),

t/t1410-reflog.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,29 @@ test_expect_success 'expire with multiple worktrees' '
446446
)
447447
'
448448

449+
test_expect_success 'expire one of multiple worktrees' '
450+
git init main-wt2 &&
451+
(
452+
cd main-wt2 &&
453+
test_tick &&
454+
test_commit foo &&
455+
git worktree add link-wt &&
456+
test_tick &&
457+
test_commit -C link-wt foobar &&
458+
test_tick &&
459+
test-tool ref-store worktree:link-wt for-each-reflog-ent HEAD \
460+
>expect-link-wt &&
461+
git reflog expire --verbose --all --expire=$test_tick \
462+
--single-worktree &&
463+
test-tool ref-store worktree:main for-each-reflog-ent HEAD \
464+
>actual-main &&
465+
test-tool ref-store worktree:link-wt for-each-reflog-ent HEAD \
466+
>actual-link-wt &&
467+
test_must_be_empty actual-main &&
468+
test_cmp expect-link-wt actual-link-wt
469+
)
470+
'
471+
449472
test_expect_success REFFILES 'empty reflog' '
450473
test_when_finished "rm -rf empty" &&
451474
git init empty &&

0 commit comments

Comments
 (0)