Skip to content

Commit 8e4f5c2

Browse files
pks-tgitster
authored andcommitted
refs: refuse to write pseudorefs
Pseudorefs are not stored in the ref database as by definition, they carry additional metadata that essentially makes them not a ref. As such, writing pseudorefs via the ref backend does not make any sense whatsoever as the ref backend wouldn't know how exactly to store the data. Restrict writing pseudorefs via the ref backend. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1701f2 commit 8e4f5c2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

refs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,13 @@ int ref_transaction_update(struct ref_transaction *transaction,
12631263
return -1;
12641264
}
12651265

1266+
if (!(flags & REF_SKIP_REFNAME_VERIFICATION) &&
1267+
is_pseudo_ref(refname)) {
1268+
strbuf_addf(err, _("refusing to update pseudoref '%s'"),
1269+
refname);
1270+
return -1;
1271+
}
1272+
12661273
if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS)
12671274
BUG("illegal flags 0x%x passed to ref_transaction_update()", flags);
12681275

t/t5510-fetch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ test_expect_success 'fetch with a non-applying branch.<name>.merge' '
518518
test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
519519
one_head=$(cd one && git rev-parse HEAD) &&
520520
this_head=$(git rev-parse HEAD) &&
521-
git update-ref -d FETCH_HEAD &&
521+
rm .git/FETCH_HEAD &&
522522
git fetch one &&
523523
test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
524524
test $this_head = "$(git rev-parse --verify HEAD)"
@@ -530,7 +530,7 @@ test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge
530530
one_ref=$(cd one && git symbolic-ref HEAD) &&
531531
git config branch.main.remote blub &&
532532
git config branch.main.merge "$one_ref" &&
533-
git update-ref -d FETCH_HEAD &&
533+
rm .git/FETCH_HEAD &&
534534
git fetch one &&
535535
test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
536536
test $this_head = "$(git rev-parse --verify HEAD)"
@@ -540,7 +540,7 @@ test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge
540540
# the merge spec does not match the branch the remote HEAD points to
541541
test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
542542
git config branch.main.merge "${one_ref}_not" &&
543-
git update-ref -d FETCH_HEAD &&
543+
rm .git/FETCH_HEAD &&
544544
git fetch one &&
545545
test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
546546
test $this_head = "$(git rev-parse --verify HEAD)"

0 commit comments

Comments
 (0)