Skip to content

Commit e68f62b

Browse files
committed
Merge branch 'js/reflog-expire-stale-fix'
"git reflog expire --stale-fix" can be used to repair the reflog by removing entries that refer to objects that have been pruned away, but was not careful to tolerate missing objects. * js/reflog-expire-stale-fix: reflog expire --stale-fix: be generous about missing objects
2 parents 726b11d + c809798 commit e68f62b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

builtin/reflog.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
602602
*/
603603
if (cb.cmd.stalefix) {
604604
repo_init_revisions(the_repository, &cb.cmd.revs, prefix);
605+
cb.cmd.revs.do_not_die_on_missing_tree = 1;
606+
cb.cmd.revs.ignore_missing = 1;
607+
cb.cmd.revs.ignore_missing_links = 1;
605608
if (flags & EXPIRE_REFLOGS_VERBOSE)
606609
printf(_("Marking reachable objects..."));
607610
mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL);

t/t1410-reflog.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,32 @@ test_expect_success 'reflog expire' '
158158
check_fsck "dangling commit $K"
159159
'
160160

161+
test_expect_success '--stale-fix handles missing objects generously' '
162+
git -c core.logAllRefUpdates=false fast-import --date-format=now <<-EOS &&
163+
commit refs/heads/stale-fix
164+
mark :1
165+
committer Author <[email protected]> now
166+
data <<EOF
167+
start stale fix
168+
EOF
169+
M 100644 inline file
170+
data <<EOF
171+
contents
172+
EOF
173+
commit refs/heads/stale-fix
174+
committer Author <[email protected]> now
175+
data <<EOF
176+
stale fix branch tip
177+
EOF
178+
from :1
179+
EOS
180+
181+
parent_oid=$(git rev-parse stale-fix^) &&
182+
test_when_finished "recover $parent_oid" &&
183+
corrupt $parent_oid &&
184+
git reflog expire --stale-fix
185+
'
186+
161187
test_expect_success 'prune and fsck' '
162188
163189
git prune &&

0 commit comments

Comments
 (0)