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

Bug report: git branch behaves as if --no-replace-objects is passed

From
Elijah Newren <newren@gmail.com>
Date
Mar 30, 2021, 06:05 UTC
Message-ID
<CABPp-BEAbN05+hCtK=xhGg5uZFqbUvH9hMcCNMcBWp5JWLqzPw@mail.gmail.com>
Hi,

Forwarding a report from https://github.com/newren/git-filter-repo/issues/229, with a few more details...

log, diff, etc. seem to all support replace objects nicely:
    git init -b main whatever
    cd whatever/
    >empty
    git add empty
    git commit -m initial
    git replace -f deadbeefdeadbeefdeadbeefdeadbeefdeadbeef $(git
rev-parse main)
    echo stuff >>empty
Now, If I try to use this replace object:
    $ git diff --stat deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
     empty | 1 +
     1 file changed, 1 insertion(+)
    $ git log --oneline deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
    deadbee (replaced) initial
it all works well.  BUT, if I try to use it with branch it doesn't work:
    $ git branch --contains deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
    $
and possibly worse, if I create a new branch based on it and use it:
    $ git branch foobar deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
    $ git checkout foobar
    $ echo stuff >empty
    $ git add empty
    $ git commit -m more

then it's clear that branch created foobar pointing to the replaced object rather than the replacement object -- despite the fact that the replaced object doesn't even exist within this repo:

    $ git cat-file -p HEAD
    tree 18108bae26dc91af2055bc66cc9fea278012dbd3
    parent deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
    author Elijah Newren <newren@gmail.com> 1617083739 -0700
    committer Elijah Newren <newren@gmail.com> 1617083739 -0700
    more

I poked around in the code a little but it is not at all clear to me why some parts of the code (log, diff) translate replace refs correctly, while others (branch) don't. It is clear from the output that log is aware that the refs are replaced, which makes me wonder if every caller needs to be aware of replace refs for them to work correctly everywhere, because I couldn't find a missing environment setup for "branch".

Next: Jeff King
Message 1 of 10 in “Bug report: git branch behaves as if --no-replace-objects is passed”
  1. Elijah NewrenMar 30, 2021
  2. Jeff KingMar 30, 2021
  3. Junio C HamanoMar 30, 2021
  4. Elijah NewrenMar 30, 2021
  5. Elijah NewrenMar 30, 2021
  6. Junio C HamanoMar 30, 2021
  7. Junio C HamanoMar 30, 2021
  8. Elijah NewrenMar 30, 2021
  9. Junio C HamanoMar 30, 2021
  10. Elijah NewrenMar 31, 2021

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.