git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waleed Khan <me@waleedkhan.name>
To: git@vger.kernel.org
Subject: Bug: reference-transaction hook for branch deletions broken between Git v2.30 and Git v2.31
Date: Wed, 17 Mar 2021 20:42:10 -0700	[thread overview]
Message-ID: <CAKjfCeDdSRk5QwyYduvbQvz0zC9FCZ3+5bseeOmZBOULxZ0D7w@mail.gmail.com> (raw)

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.

             reply	other threads:[~2021-03-18  3:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18  3:42 Waleed Khan [this message]
2021-03-18  4:08 ` Bug: reference-transaction hook for branch deletions broken between Git v2.30 and Git v2.31 Jeff King
2021-03-18  7:33 ` Patrick Steinhardt

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=CAKjfCeDdSRk5QwyYduvbQvz0zC9FCZ3+5bseeOmZBOULxZ0D7w@mail.gmail.com \
    --to=me@waleedkhan.name \
    --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;
as well as URLs for NNTP newsgroup(s).