Skip to content

Commit 4a25b91

Browse files
committed
Merge branch 'zh/push-to-delete-onelevel-ref'
"git push" has been taught to allow deletion of refs with one-level names to help repairing a repository who acquired such a ref by mistake. In general, we don't encourage use of such a ref, and creation or update to such a ref is rejected as before. * zh/push-to-delete-onelevel-ref: push: allow delete single-level ref receive-pack: fix funny ref error messsage
2 parents 67076b8 + 7c3c550 commit 4a25b91

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

builtin/receive-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,10 @@ static const char *update(struct command *cmd, struct shallow_info *si)
14601460
find_shared_symref(worktrees, "HEAD", name);
14611461

14621462
/* only refs/... are allowed */
1463-
if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
1464-
rp_error("refusing to create funny ref '%s' remotely", name);
1463+
if (!starts_with(name, "refs/") ||
1464+
check_refname_format(name + 5, is_null_oid(new_oid) ?
1465+
REFNAME_ALLOW_ONELEVEL : 0)) {
1466+
rp_error("refusing to update funny ref '%s' remotely", name);
14651467
ret = "funny refname";
14661468
goto out;
14671469
}

connect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static int check_ref(const char *name, unsigned int flags)
3131
return 0;
3232

3333
/* REF_NORMAL means that we don't want the magic fake tag refs */
34-
if ((flags & REF_NORMAL) && check_refname_format(name, 0))
34+
if ((flags & REF_NORMAL) && check_refname_format(name,
35+
REFNAME_ALLOW_ONELEVEL))
3536
return 0;
3637

3738
/* REF_HEADS means that we want regular branch heads */

t/t5516-fetch-push.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ test_expect_success 'push with ambiguity' '
401401
402402
'
403403

404+
test_expect_success 'push with onelevel ref' '
405+
mk_test testrepo heads/main &&
406+
test_must_fail git push testrepo HEAD:refs/onelevel
407+
'
408+
404409
test_expect_success 'push with colon-less refspec (1)' '
405410
406411
mk_test testrepo heads/frotz tags/frotz &&
@@ -898,6 +903,13 @@ test_expect_success 'push --delete refuses empty string' '
898903
test_must_fail git push testrepo --delete ""
899904
'
900905

906+
test_expect_success 'push --delete onelevel refspecs' '
907+
mk_test testrepo heads/main &&
908+
git -C testrepo update-ref refs/onelevel refs/heads/main &&
909+
git push testrepo --delete refs/onelevel &&
910+
test_must_fail git -C testrepo rev-parse --verify refs/onelevel
911+
'
912+
901913
test_expect_success 'warn on push to HEAD of non-bare repository' '
902914
mk_test testrepo heads/main &&
903915
(

0 commit comments

Comments
 (0)