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
This commit is contained in:
Junio C Hamano 2021-02-17 17:21:43 -08:00
commit e68f62be8d
2 changed files with 29 additions and 0 deletions

View File

@ -602,6 +602,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
*/
if (cb.cmd.stalefix) {
repo_init_revisions(the_repository, &cb.cmd.revs, prefix);
cb.cmd.revs.do_not_die_on_missing_tree = 1;
cb.cmd.revs.ignore_missing = 1;
cb.cmd.revs.ignore_missing_links = 1;
if (flags & EXPIRE_REFLOGS_VERBOSE)
printf(_("Marking reachable objects..."));
mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL);

View File

@ -158,6 +158,32 @@ test_expect_success 'reflog expire' '
check_fsck "dangling commit $K"
'
test_expect_success '--stale-fix handles missing objects generously' '
git -c core.logAllRefUpdates=false fast-import --date-format=now <<-EOS &&
commit refs/heads/stale-fix
mark :1
committer Author <a@uth.or> now
data <<EOF
start stale fix
EOF
M 100644 inline file
data <<EOF
contents
EOF
commit refs/heads/stale-fix
committer Author <a@uth.or> now
data <<EOF
stale fix branch tip
EOF
from :1
EOS
parent_oid=$(git rev-parse stale-fix^) &&
test_when_finished "recover $parent_oid" &&
corrupt $parent_oid &&
git reflog expire --stale-fix
'
test_expect_success 'prune and fsck' '
git prune &&