git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: <rsbecker@nexbridge.com>
Cc: "'Curley Joe'" <m48cv7wg9w@liamekaens.com>,  <git@vger.kernel.org>
Subject: Re: git fetch --prune fails with "fatal: bad object"
Date: Sat, 01 Jun 2024 08:53:43 -0700	[thread overview]
Message-ID: <xmqqo78kbqwo.fsf@gitster.g> (raw)
In-Reply-To: <000501dab3b3$51779400$f466bc00$@nexbridge.com> (rsbecker@nexbridge.com's message of "Fri, 31 May 2024 19:36:04 -0400")

<rsbecker@nexbridge.com> writes:

>> - Why did the repository got into this state in the first place?
>>   It seems that it would be much better solution to prevent refs
>>   from having garbage values in them or to prevent objects that are
>>   necessary from going away than any "prune invalid refs" feature.
>
> I agree. However, there are some configurations where disk write
> caches are enabled and require a sync or some other flush
> operation to force a complete write to disk. In such situations,
> corruptions are always possible despite the best efforts by the
> application.

The question was posed to see where the current "best efforts" are
still inadequate.

>> - "fetch" still feels a wrong place to have the feature, if it is
>>   about fixing a local repository corruption.  You should be able
>>   to recover from such a broken ref even if you are only working
>>   locally without fetching from anybody.
>
> I think fsck would be a better place for this.
>
>>If you can somehow _enumerate_ such broken refs, you could drive update-ref to
>>remove them.

Interesting.  "git fsck" certainly can be used to help you find out
about them.  In a throw-away repository, after manually crafting
some "broken refs" (because update-ref will refuse to create a ref
pointing at a missing object):

    $ git for-each-ref
    9e830ad6c4f43159cef50cb1c2205f513c79bc8b commit refs/heads/master
    $ echo 9e830ad6c4f43159cef50cb1c2205f513c79bc8a >.git/refs/heads/broken-missing
    $ git rev-parse master: >.git/refs/heads/broken-tree
    $ git rev-parse "master:foo /baz" >.git/refs/heads/broken-blob

running "git fsck" does tell you about them, ...

    $ git fsck
    Checking object directories: 100% (256/256), done.
    error: refs/heads/broken-blob: not a commit
    error: refs/heads/broken-missing: invalid sha1 pointer 9e830ad6c4f43159cef50cb1c2205f513c79bc8a
    error: refs/heads/broken-tree: not a commit

... and using the information, you can

    $ for r in refs/heads/broken-{blob,missing,tree}
      do git update-ref -d "$r"
      done

to unbreak the repository.

  reply	other threads:[~2024-06-01 15:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 22:34 git fetch --prune fails with "fatal: bad object" Curley Joe
2024-05-31 23:27 ` Junio C Hamano
2024-05-31 23:36   ` rsbecker
2024-06-01 15:53     ` Junio C Hamano [this message]
2024-06-04 10:44       ` Jeff King
2024-06-04 17:50         ` Junio C Hamano
2024-06-05  8:45           ` Jeff King
2024-06-04 20:09         ` Fred Long
2024-06-05  8:47           ` Jeff King
2024-06-05 23:43             ` Fred Long
2024-06-06  1:14               ` Jeff King
2024-06-06 20:12                 ` Fred Long
2024-06-08 11:20                   ` Jeff King
2024-06-08 21:02                     ` Fred Long
2024-06-11  7:31                       ` Jeff King
2024-06-13  3:29                         ` Fred Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqo78kbqwo.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=m48cv7wg9w@liamekaens.com \
    --cc=rsbecker@nexbridge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).