Skip to content

Commit b886db4

Browse files
KarthikNayakgitster
authored andcommitted
refs: don't invoke reference-transaction hook for reflogs
The reference-transaction hook is invoked whenever there is a reference update being performed. For each state of the transaction, we iterate over the updates present and pass this information to the hook. The `ref_update` structure is used to hold these updates within a `transaction`. We use the same structure for holding reflog updates too. Which means that the reference transaction hook is also obtaining information about a reflog update. This is a bug, since: - The hook is designed to work with reference updates and reflogs updates are different. - The hook doesn't have the required information to distinguish reference updates from reflog updates. This is particularly evident when the default branch (pointed by HEAD) is updated, we see that the hook also receives information about HEAD being changed. In reality, we only add a reflog update for HEAD, while HEAD's values remains the same. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 777489f commit b886db4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

refs.c

+3
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,9 @@ static int run_transaction_hook(struct ref_transaction *transaction,
21852185
for (i = 0; i < transaction->nr; i++) {
21862186
struct ref_update *update = transaction->updates[i];
21872187

2188+
if (update->flags & REF_LOG_ONLY)
2189+
continue;
2190+
21882191
strbuf_reset(&buf);
21892192

21902193
if (!(update->flags & REF_HAVE_OLD))

t/t1416-ref-transaction-hooks.sh

-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ test_expect_success 'hook gets all queued updates in prepared state' '
5353
fi
5454
EOF
5555
cat >expect <<-EOF &&
56-
$ZERO_OID $POST_OID HEAD
5756
$ZERO_OID $POST_OID refs/heads/main
5857
EOF
5958
git update-ref HEAD POST <<-EOF &&
@@ -76,7 +75,6 @@ test_expect_success 'hook gets all queued updates in committed state' '
7675
fi
7776
EOF
7877
cat >expect <<-EOF &&
79-
$ZERO_OID $POST_OID HEAD
8078
$ZERO_OID $POST_OID refs/heads/main
8179
EOF
8280
git update-ref HEAD POST &&

0 commit comments

Comments
 (0)