Skip to content

Commit 20e4164

Browse files
committed
push: do not turn --delete '' into a matching push
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 f517f1f (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit 20e4164

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

builtin/push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
115115
else
116116
refspec_appendf(&rs, "refs/tags/%s", ref);
117117
} else if (deleterefs) {
118-
if (strchr(ref, ':'))
118+
if (strchr(ref, ':') || !*ref)
119119
die(_("--delete only accepts plain target ref names"));
120120
refspec_appendf(&rs, ":%s", ref);
121121
} else if (!strchr(ref, ':')) {

t/t5516-fetch-push.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,11 @@ test_expect_success 'push --delete refuses src:dest refspecs' '
818818
test_must_fail git push testrepo --delete master:foo
819819
'
820820

821+
test_expect_success 'push --delete refuses empty string' '
822+
mk_test testrepo heads/master &&
823+
test_must_fail git push testrepo --delete ""
824+
'
825+
821826
test_expect_success 'warn on push to HEAD of non-bare repository' '
822827
mk_test testrepo heads/master &&
823828
(

0 commit comments

Comments
 (0)