]> git.ipfire.org Git - thirdparty/git.git/commitdiff
push: do not turn --delete '' into a matching push
authorJunio C Hamano <gitster@pobox.com>
Tue, 23 Feb 2021 23:13:32 +0000 (15:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Feb 2021 23:19:34 +0000 (15:19 -0800)
When we added a syntax sugar "git push remote --delete <ref>" to
"git push" as a synonym to the canonical "git push remote :<ref>"
syntax at f517f1f2 (builtin-push: add --delete as syntactic sugar
for :foo, 2009-12-30), we weren't careful enough to make sure that
<ref> is not empty.

Blindly rewriting "--delete <ref>" to ":<ref>" means that an empty
string <ref> 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 <tilman.vogel@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/push.c
t/t5516-fetch-push.sh

index 6da3a8e5d30af38530d29c245d15a747dc9f4eed..da34524e6f31190ad2a680851912a9889b632653 100644 (file)
@@ -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, ':')) {
index d11382f769f6669aa1f95e83a45fd266d4b9e304..bf0d295d804c14998e4070c751dfad06b01a7cf5 100755 (executable)
@@ -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 &&
        (