From: Pratyush Yadav <me@yadavpratyush.com>
To: git@vger.kernel.org
Subject: Strange behaviour when pushing a commit object to remote's refs/HEAD
Date: Mon, 15 Jan 2024 20:08:13 +0100 [thread overview]
Message-ID: <mafs0fryypg82.fsf@yadavpratyush.com> (raw)
Hi,
I ran into a strange Magit bug, where when I ran magit-show-refs on a
particular repo it threw an error. The details of the Magit bug are not
very interesting, but when attempting to reproduce it, I also saw git
misbehaving for such repos.
The strange behaviour happens when you push a commit object to remote's
refs/HEAD instead of pushing a symbolic ref. Such a repository can be
found at https://github.com/prati0100/magit-reproducer. I roughly used
the below steps to create such a repo:
$ git init
$ echo 1 > foo && git add foo && git commit
$ echo 2 > bar && git add bar && git commit
$ git push
$ git checkout 79264c3
$ echo 2.1 > bar && git add bar && git commit
$ git push origin 707a3d5:refs/heads/HEAD
Now with such a repo, if you do `git log --all --oneline` it would look
something like:
707a3d5 (origin/HEAD) 2.1
86e1c97 (HEAD -> main, origin/main) 2
79264c3 1
And running `git for-each-ref --format='%(symref:short),%(refname:short),%(refname),%(subject)' refs/remotes/origin` gives:
,origin,refs/remotes/origin/HEAD,2.1
,origin/main,refs/remotes/origin/main,2
All well and good so far. Now delete the repo and attempt to clone it.
This time `git log --all --oneline` gives:
86e1c97 (HEAD -> main, origin/main, origin/HEAD) 2
79264c3 1
And running `git for-each-ref --format='%(symref:short),%(refname:short),%(refname),%(subject)' refs/remotes/origin` gives:
origin/main,origin,refs/remotes/origin/HEAD,2
,origin/main,refs/remotes/origin/main,2
So suddenly the remote's HEAD becomes origin/main (symbolic ref) and the
commit (707a3d5, "2.1") is nowhere to be found. It neither shows up in
`git rev-list --all` nor in `git log --all`. The files and trees
associated with it also do not show up in `git rev-list --all --object`.
Yet if you do `git show 707a3d5` it shows up. So it does exist and did
get cloned, but git cannot properly see it.
Interestingly enough, even the GitHub UI is confused and it won't show
you the repo correctly. It will show the commit (86e1c97, "2") for both
"branches" main and HEAD. cgit's UI [0] seems to work fine with this,
though cloning from cgit still suffers from this bug.
There _is_ a way to clone the repo correctly. If you do:
$ git init magit-reproducer
$ git remote add origin https://github.com/prati0100/magit-reproducer.git
$ git remote update
Now if you do git log --all or git for-each-ref, you see the correct
result.
I don't really know how to fix this but it certainly is a bug in git
since it can't clone the repo correctly. And at least one major Git host
can't display such a repo properly (I haven't tried others).
I used Git v2.40.1 to do most of this but I did compile the latest
master d4dbce1db5 ("The seventh batch") and attempted to clone using it
and I see the same problem.
[0] https://git.kernel.org/pub/scm/linux/kernel/git/pratyush/magit-reproducer.git/
--
Regards,
Pratyush Yadav
next reply other threads:[~2024-01-15 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 19:08 Pratyush Yadav [this message]
2024-01-16 9:54 ` Strange behaviour when pushing a commit object to remote's refs/HEAD Karthik Nayak
2024-01-16 11:33 ` Pratyush Yadav
2024-01-16 13:24 ` Karthik Nayak
2024-01-16 15:00 ` Jeff King
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=mafs0fryypg82.fsf@yadavpratyush.com \
--to=me@yadavpratyush.com \
--cc=git@vger.kernel.org \
/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