Reference transaction hook is unable to find the old_oid for pre-existing refs
- From
- elhmn <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`.