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

Bug: reference-transaction hook for branch deletions broken between Git v2.30 and Git v2.31

From
WKWaleed Khan <me@waleedkhan.name>
Date
Mar 18, 2021, 03:42 UTC
Message-ID
<CAKjfCeDdSRk5QwyYduvbQvz0zC9FCZ3+5bseeOmZBOULxZ0D7w@mail.gmail.com>
Hello,

The `reference-transaction` hook seems to have broken between Git v2.30 and v2.31, or at least violated my expectations as a user.

I didn't see any mention of the `reference-transaction` hook in the release notes, so I assume that this is a bug. Given that there's documentation at `man githooks` for the `reference-transaction` hook, I assume that the feature is no longer in a preliminary stage, and so a bug report is warranted. I couldn't find any mention of a `reference-transaction` hook bug already having been reported in the mailing list search online.

## Reproduction ##
To reproduce, run this script:

``` #!/bin/sh set -eu

# Change between Git v2.30.0 and v2.31.0 here. GIT=${GIT:-$(which git)} echo "Running version $("$GIT" version)"

# For determinism. export GIT_COMMITTER_DATE="Wed Mar 17 16:53:32 PDT 2021" export GIT_AUTHOR_DATE="Wed Mar 17 16:53:32 PDT 2021"

rm -rf repo mkdir repo cd repo "$GIT" init "$GIT" commit --allow-empty -m 'Initial commit'

mkdir .git/hooks cat >.git/hooks/reference-transaction <<'EOF' #!/bin/sh echo "reference-transaction ($1):" cat EOF chmod +x .git/hooks/reference-transaction

"$GIT" branch -v 'test-branch' echo "Created test-branch" "$GIT" branch -v -d 'test-branch' ```

## Expected behavior (git v2.30) ##
This is the output:

``` [master (root-commit) 3b61ecc] Initial commit reference-transaction (prepared): 0000000000000000000000000000000000000000 3b61ecc56006fcc283d42b302191e1385f19b551 refs/heads/test-branch reference-transaction (committed): 0000000000000000000000000000000000000000 3b61ecc56006fcc283d42b302191e1385f19b551 refs/heads/test-branch Created test-branch reference-transaction (aborted): 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/test-branch reference-transaction (prepared): 3b61ecc56006fcc283d42b302191e1385f19b551 0000000000000000000000000000000000000000 refs/heads/test-branch reference-transaction (committed): 3b61ecc56006fcc283d42b302191e1385f19b551 0000000000000000000000000000000000000000 refs/heads/test-branch Deleted branch test-branch (was 3b61ecc). ```

It's pretty strange that there was an "aborted" reference-transaction from 0 to 0, especially with no previous "prepared" reference-transaction, but that's not the bug in question, and I can work around it by ignoring such transactions on my end.

Notice that as part of the branch deletion, there is a reference-transaction from a non-zero commit hash to a zero commit hash.

## Actual behavior (git v2.31) ##

``` [master (root-commit) 3b61ecc] Initial commit reference-transaction (prepared): 0000000000000000000000000000000000000000 3b61ecc56006fcc283d42b302191e1385f19b551 refs/heads/test-branch reference-transaction (committed): 0000000000000000000000000000000000000000 3b61ecc56006fcc283d42b302191e1385f19b551 refs/heads/test-branch Created test-branch reference-transaction (prepared): 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/test-branch reference-transaction (committed): 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/test-branch reference-transaction (aborted): 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/test-branch reference-transaction (prepared): 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/test-branch reference-transaction (committed): 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/test-branch Deleted branch test-branch (was 3b61ecc). ```

My issues are 1) the reference-transaction deleting the branch goes from a zero commit hash, instead of from the non-zero commit hash 3b61ec, and 2) there's two such "committed" transactions for some reason. Like the other example, there's also a mysterious unpaired aborted transaction, but I assume that's not new behavior in this release.

## `git bugreport` system info ##
`git` 2.30 bugreport (built from source):

[System Info] git version: git version 2.30.2 cpu: x86_64 built from commit: 94f6e3e283f2adfc518b39cfc39291f1c2832ad0 sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64 compiler info: clang: 12.0.0 (clang-1200.0.32.21) libc info: no libc information available $SHELL (typically, interactive shell): /bin/zsh

`git` 2.31 bugreport (built from source):

[System Info] git version: git version 2.31.0 cpu: x86_64 built from commit: a5828ae6b52137b913b978e16cd2334482eb4c1f sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64 compiler info: clang: 12.0.0 (clang-1200.0.32.21) libc info: no libc information available $SHELL (typically, interactive shell): /bin/zsh

The issue also reproduces in CI builds of Git on Linux.
Next: Jeff King
Message 1 of 3 in “Bug: reference-transaction hook for branch deletions broken between Git v2.30 and Git v2.31”
  1. Waleed KhanMar 18, 2021
  2. Jeff KingMar 18, 2021
  3. Patrick SteinhardtMar 18, 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.