transport-helper: add support to delete branches
authorFelipe Contreras <felipe.contreras@gmail.com>
Sun, 20 Apr 2014 18:59:29 +0000 (13:59 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Apr 2014 18:47:34 +0000 (11:47 -0700)
For remote-helpers that use 'export' to push.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5801-remote-helpers.sh
transport-helper.c
index 828866930d40b5311e9db26ef0372db881709b4e..aec924b2e1d669b2554e0c0e8f6d4b88ab3cfce5 100755 (executable)
@@ -102,6 +102,14 @@ test_expect_success 'push new branch with HEAD:new refspec' '
        compare_refs local HEAD server refs/heads/new-refspec-2
 '
 
+test_expect_success 'push delete branch' '
+       (cd local &&
+        git push origin :new-name
+       ) &&
+       test_must_fail git --git-dir="server/.git" \
+        rev-parse --verify refs/heads/new-name
+'
+
 test_expect_success 'forced push' '
        (cd local &&
        git checkout -b force-test &&
index f74eb57046868d0fd18e906b284d3085f0188e39..36fbf9349e08474548368f7d4360af1617198319 100644 (file)
@@ -882,9 +882,6 @@ static int push_refs_with_export(struct transport *transport,
                char *private;
                unsigned char sha1[20];
 
-               if (ref->deletion)
-                       die("remote-helpers do not support ref deletion");
-
                private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
                if (private && !get_sha1(private, sha1)) {
                        strbuf_addf(&buf, "^%s", private);
@@ -896,21 +893,26 @@ static int push_refs_with_export(struct transport *transport,
                if (ref->peer_ref) {
                        if (strcmp(ref->name, ref->peer_ref->name)) {
                                struct strbuf buf = STRBUF_INIT;
-                               const char *name;
-                               int flag;
 
-                               /* Follow symbolic refs (mainly for HEAD). */
-                               name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag);
-                               if (!name || !(flag & REF_ISSYMREF))
-                                       name = ref->peer_ref->name;
+                               if (!ref->deletion) {
+                                       const char *name;
+                                       int flag;
+
+                                       /* Follow symbolic refs (mainly for HEAD). */
+                                       name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag);
+                                       if (!name || !(flag & REF_ISSYMREF))
+                                               name = ref->peer_ref->name;
 
-                               strbuf_addf(&buf, "%s:%s", name, ref->name);
+                                       strbuf_addf(&buf, "%s:%s", name, ref->name);
+                               } else
+                                       strbuf_addf(&buf, ":%s", ref->name);
 
                                string_list_append(&revlist_args, "--refspec");
                                string_list_append(&revlist_args, buf.buf);
                                strbuf_release(&buf);
                        }
-                       string_list_append(&revlist_args, ref->peer_ref->name);
+                       if (!ref->deletion)
+                               string_list_append(&revlist_args, ref->peer_ref->name);
                }
        }