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

Reference transaction hook is unable to find the old_oid for pre-existing refs

From
Eelhmn <elhmn42@gmail.com>
Date
Sep 3, 2025, 14:11 UTC
Message-ID
<CACpeKQ=sPOc2AqsMT--2tu=BMEK9MaCAq5=PTG5w49gbRcQgVQ@mail.gmail.com>

While inspecting the reference transaction hook code, I realised that the hook was receiving a CREATE ref update line even for references that already existed on disk, where I was expecting to see an UPDATE ref update line. That behaviour was observed for the file and the reftable backends.

Using the `reference-transaction` file bellow:
```
$ cat .git/hooks/reference-transaction
if test "$1" = prepared
then
         while read -r line
         do
                 printf "%s\n" "$line"
         done >>actual
fi
```
I created the commits A and B

``` $ git commit --allow-empty -m "A"; git tag A $ git commit --allow-empty -m "B"; git tag B ```

Checked which refs were created: ``` $ git show-ref 9b18557013105bb7a7bf681f18757084ada9d948 refs/heads/master 01077b2840db5baea0084921d8f3158a240e8d85 refs/tags/A 9b18557013105bb7a7bf681f18757084ada9d948 refs/tags/B ```

Then ran `git update-ref refs/heads/master A` which logged: ``` 0000000000000000000000000000000000000000 01077b2840db5baea0084921d8f3158a240e8d85 refs/heads/master ```

But I expected: ``` 9b18557013105bb7a7bf681f18757084ada9d948 01077b2840db5baea0084921d8f3158a240e8d85 refs/heads/master ```

The git/git t1416-ref-transaction-hooks.sh update tests seem to be expecting a $ZERO_OID for reference update, so I am not sure if that's a bug or a feature.

A test case: https://github.com/git/git/blob/2462961280690837670d997bde64bd4ebf8ae66d/t/t1416-ref-transaction-hooks.sh#L55
CREATE: <zero_oid> <new_oid> <ref_name>
UPDATE: <old_oid> <new_oid> <ref_name>
I ran those tests using the git version `2.51.0` on `Ubuntu 20.04.6 LTS`.
Next: Jeff King
Message 1 of 2 in “Reference transaction hook is unable to find the old_oid for pre-existing refs”
  1. elhmnSep 3, 2025
  2. Jeff KingSep 3, 2025

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.