From 20e416409fc2bc260faf65a0fc74927ed0d3ca12 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 23 Feb 2021 15:13:32 -0800 Subject: [PATCH] push: do not turn --delete '' into a matching push When we added a syntax sugar "git push remote --delete " to "git push" as a synonym to the canonical "git push remote :" syntax at f517f1f2 (builtin-push: add --delete as syntactic sugar for :foo, 2009-12-30), we weren't careful enough to make sure that is not empty. Blindly rewriting "--delete " to ":" means that an empty string results in refspec ":", which is the syntax to ask for "matching" push that does not delete anything. Worse yet, if there were matching refs that can be fast-forwarded, they would have been published prematurely, even if the user feels that they are not ready yet to be pushed out, which would be a real disaster. Noticed-by: Tilman Vogel Signed-off-by: Junio C Hamano --- builtin/push.c | 2 +- t/t5516-fetch-push.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/push.c b/builtin/push.c index 6da3a8e5d30..da34524e6f3 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -115,7 +115,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo) else refspec_appendf(&rs, "refs/tags/%s", ref); } else if (deleterefs) { - if (strchr(ref, ':')) + if (strchr(ref, ':') || !*ref) die(_("--delete only accepts plain target ref names")); refspec_appendf(&rs, ":%s", ref); } else if (!strchr(ref, ':')) { diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index d11382f769f..bf0d295d804 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -818,6 +818,11 @@ test_expect_success 'push --delete refuses src:dest refspecs' ' test_must_fail git push testrepo --delete master:foo ' +test_expect_success 'push --delete refuses empty string' ' + mk_test testrepo heads/master && + test_must_fail git push testrepo --delete "" +' + test_expect_success 'warn on push to HEAD of non-bare repository' ' mk_test testrepo heads/master && (