git/list[1] front-page[2] threads[3] people[4] search[5] about
 

"git fetch" fails for a --reference clone after an outer forced push

From
MVMirochnik, Oleg V <oleg.v.mirochnik@intel.com>
Date
Dec 25, 2024, 17:23 UTC
Message-ID
<SJ0PR11MB581445B096273126D18F3724C60C2@SJ0PR11MB5814.namprd11.prod.outlook.com>
Hi all,

To reduce traffic, we use local mirrors via "git clone --reference mirror ..." commands. And we regularly get problems with update of few weeks old clones and must run something like below to get rid of outdated branches:

git for-each-ref --format="%(refname)" | while read ref; do
    git show-ref --quiet --verify $ref 2>/dev/null || git update-ref -d $ref
done
This can be quite long operation as number of refs is significant.
Details are below.

Thanks, Oleg.

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

$ cat ./doit #!/bin/sh set -xe rm -rf tst mkdir tst cd tst mkdir master git -C master init --bare git clone master local touch local/foo git -C local add . git -C local commit -m init-commit git -C local push echo foo > local/foo git -C local commit -a -m dummy-commit git -C local push origin HEAD:refs/heads/dummy git clone --mirror file://`pwd`/master mirror git clone --reference `pwd`/mirror file://`pwd`/master local1 git -C local1 log --oneline origin/dummy git -C local commit --amend -m new-dummy-commit git -C local push -f origin HEAD:dummy git -C mirror fetch git -C mirror gc --prune=now git -C local1 fetch git -C local1 log --oneline origin/dummy

What did you expect to happen? (Expected behavior)
No errors; last few lines like:
+ git -C local1 fetch
From file:///tmp/tst/master
 + 552a293...248c7fa dummy      -> origin/dummy  (forced update)
+ git -C local1 log --oneline origin/dummy
248c7fa (origin/dummy) new-dummy-commit
0636429 (HEAD -> master, origin/master, origin/HEAD) init-commit
What happened instead? (Actual behavior)
+ git -C local1 fetch
fatal: bad object refs/remotes/origin/dummy
error: file:///tmp/tst/master did not send all necessary objects
What's different between what you expected and what actually happened?
Obvious - should work and does not work
Anything else you want to add:

It works if "git -C mirror gc --prune=now" step is skipped or if local path is used for the clone steps instead of the "file://" The same issue is with https://github.com/... The same issue if use "git -C local1 remote update --prune" instead of the "git -C local1 fetch"

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

podman ub24 container is used to get a newer git version. Exactly the same behavior is for the git v2.39.1

[System Info] git version: git version 2.43.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.14.0-70.13.1.el9_0.x86_64 #1 SMP PREEMPT Thu Apr 14 12:42:38 EDT 2022 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): <unset>

[Enabled Hooks] not run from a git repository - no hooks to show

Next: Jeff King
Message 1 of 5 in “"git fetch" fails for a --reference clone after an outer forced push”
  1. Mirochnik, Oleg VDec 25, 2024
  2. Jeff KingDec 26, 2024
  3. Mirochnik, Oleg VDec 26, 2024
  4. Jeff KingDec 27, 2024
  5. Mirochnik, Oleg VDec 27, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.